Skip to content

Commit c2b38bf

Browse files
committed
refactor: replace print statements with logging
- xml_reader.py: Replace print to stderr with logger.warning - glencoe_writer.py: Replace debug prints with logger.debug - feature_cardinality_refactoring.py: Replace debug print with logger.debug
1 parent 6ca604f commit c2b38bf

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

flamapy/metamodels/fm_metamodel/transformations/glencoe_writer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import json
2+
import logging
23
import string
34
from typing import Any
45

56
from flamapy.core.models.ast import Node, ASTOperation
67
from flamapy.core.transformations import ModelToText
78
from flamapy.metamodels.fm_metamodel.models import FeatureModel, Feature, Constraint
89

10+
logger = logging.getLogger(__name__)
11+
912

1013
class GlencoeWriter(ModelToText):
1114
CTC_TYPES = {
@@ -38,8 +41,8 @@ def transform(self) -> str:
3841

3942
def _to_json(feature_model: FeatureModel) -> dict[str, Any]:
4043
result: dict[str, Any] = {}
41-
print(f'-{feature_model.root.name}-')
42-
print(f'-{safename(feature_model.root.name)}-')
44+
logger.debug("Root name: %s", feature_model.root.name)
45+
logger.debug("Safe root name: %s", safename(feature_model.root.name))
4346
result["id"] = f"FM_{safename(feature_model.root.name)}"
4447
result["name"] = f"FM_{safename(feature_model.root.name)}"
4548
result["features"] = _get_features_info(feature_model.get_features())

flamapy/metamodels/fm_metamodel/transformations/refactorings/feature_cardinality_refactoring.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import copy
2+
import logging
23
from dataclasses import dataclass
34
from typing import Any, cast
45

@@ -16,6 +17,8 @@
1617
RefactoringException
1718
)
1819

20+
logger = logging.getLogger(__name__)
21+
1922

2023
@dataclass
2124
class CloneContext:
@@ -167,7 +170,8 @@ def contextualize_constraint(feature_model: FeatureModel,
167170
features_names_map: dict[str, str]) -> Constraint:
168171
"""Create a contextualized constraint for the given constraints according to the provided
169172
feature clone."""
170-
print(f'Contextualizing constraint {constraint.name} for features {features_names_map}')
173+
logger.debug("Contextualizing constraint %s for features %s",
174+
constraint.name, features_names_map)
171175
# Create a copy of the constraint
172176
new_constraint = copy.deepcopy(constraint)
173177
# Rename the constraint's name

flamapy/metamodels/fm_metamodel/transformations/xml_reader.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import sys
1+
import logging
22
from typing import Optional
33
from xml.etree import ElementTree
44

@@ -12,6 +12,8 @@
1212
Relation,
1313
)
1414

15+
logger = logging.getLogger(__name__)
16+
1517

1618
class XMLReader(TextToModel):
1719

@@ -39,7 +41,7 @@ def transform(self) -> FeatureModel:
3941
ctc = self.parse_ctc(child)
4042
feature_model.ctcs.append(ctc)
4143
else:
42-
print("This XML contains non supported elements", file=sys.stderr)
44+
logger.warning("This XML contains non supported elements")
4345

4446
return feature_model
4547

@@ -83,7 +85,7 @@ def parse_feature(self, element: ElementTree.Element, parent: Optional[Feature])
8385
feature = Feature(name, [], parent=parent)
8486

8587
if name in self.name_feature:
86-
print("This XML contains duplicated feature names", file=sys.stderr)
88+
logger.warning("This XML contains duplicated feature names")
8789
raise DuplicatedFeature
8890

8991
self.name_feature[name] = feature
@@ -113,7 +115,7 @@ def parse_relation(self, element: ElementTree.Element, parent: Feature) -> Relat
113115
relation.card_min = int(str(child.attrib.get('min')))
114116
relation.card_max = int(str(child.attrib.get('max')))
115117
else:
116-
print("This XML contains non supported elements", file=sys.stderr)
118+
logger.warning("This XML contains non supported elements")
117119

118120
elif element.tag.casefold() == 'setrelation':
119121
for child in element:
@@ -124,7 +126,7 @@ def parse_relation(self, element: ElementTree.Element, parent: Feature) -> Relat
124126
relation.card_min = int(str(child.attrib.get('min')))
125127
relation.card_max = int(str(child.attrib.get('max')))
126128
else:
127-
print("This XML contains non supported elements", file=sys.stderr)
129+
logger.warning("This XML contains non supported elements")
128130
else:
129131
raise RuntimeError("Something is wrong on the xml")
130132
return relation

0 commit comments

Comments
 (0)