Skip to content

Commit

Permalink
Cambios al string de salida de FeatureIDE para ponerlo mas bonito
Browse files Browse the repository at this point in the history
  • Loading branch information
Enriquelp committed Feb 1, 2024
1 parent 28cd896 commit 6ab6225
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,11 @@ def __init__(self, path: str, source_model: FeatureModel) -> None:
self.source_model = source_model

def transform(self) -> str:
# return _to_featureidexml(self.source_model).write(self.path)
et = _to_featureidexml(self.source_model).getroot()
xml_str = ET.tostring(et, encoding='unicode', method='xml')
return pretty_print_xml_elementtree(xml_str)


if self.path is not None:
et = _to_featureidexml(self.source_model).getroot()
xml_str = ET.tostring(et, encoding='unicode', method='xml')
# with open(self.path, 'w', encoding='utf8') as file:
# file.write(xml_str)

return xml_str


def _to_featureidexml(feature_model: FeatureModel):
featureModel = ET.Element("featureModel")
Expand Down Expand Up @@ -135,4 +129,34 @@ def _get_ctc_info(ast_node: Node) -> dict[str, Any]:
right = _get_ctc_info(ast_node.right)
operands.append(right)
ctc_info['operands'] = operands
return ctc_info
return ctc_info

def pretty_print_xml_elementtree(xml_string):
# Parse the XML string
root = ET.fromstring(xml_string)

# Indent the XML
indent(root)

# Convert the XML element back to a string
pretty_xml = ET.tostring(root, encoding="unicode")

# Print the pretty XML
return pretty_xml

def indent(elem, level=0):
# Add indentation
indent_size = " "
i = "\n" + level * indent_size
if len(elem):
if not elem.text or not elem.text.strip():
elem.text = i + indent_size
if not elem.tail or not elem.tail.strip():
elem.tail = i
for elem in elem:
indent(elem, level + 1)
if not elem.tail or not elem.tail.strip():
elem.tail = i
else:
if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i
2 changes: 0 additions & 2 deletions rhea-backend/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,9 @@ def download_feature_model():
print('FM expired.')
return jsonify({'error': f'FM expired for hash "{fm_hash}"'}), 404
fm_str = write_fm_file(fm, fm_format)
# print(fm_str)
if fm_str is None:
return jsonify({'error': 'Object not found'}), 404
response = make_response(fm_str)
print(response.data)
return response


Expand Down

0 comments on commit 6ab6225

Please sign in to comment.