diff --git a/rhea-backend/rhea/metamodels/fm_metamodel/transformations/featureide_writer.py b/rhea-backend/rhea/metamodels/fm_metamodel/transformations/featureide_writer.py index a03a107d..376549f0 100644 --- a/rhea-backend/rhea/metamodels/fm_metamodel/transformations/featureide_writer.py +++ b/rhea-backend/rhea/metamodels/fm_metamodel/transformations/featureide_writer.py @@ -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") @@ -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 \ No newline at end of file + 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 \ No newline at end of file diff --git a/rhea-backend/server.py b/rhea-backend/server.py index f20140fb..18edbdb8 100644 --- a/rhea-backend/server.py +++ b/rhea-backend/server.py @@ -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