From df8665685b38caab04d143f9135ba42fb8dcb7e5 Mon Sep 17 00:00:00 2001 From: Ben Hutcheson Date: Sun, 7 Jul 2024 21:05:50 +0200 Subject: [PATCH] feat: Improve the structure of the model to more closely match am L5X file. --- acd/l5x/elements.py | 30 ++++++++++++++++++------------ setup.py | 2 +- test/test_api.py | 3 ++- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/acd/l5x/elements.py b/acd/l5x/elements.py index 7a61881..229cbda 100644 --- a/acd/l5x/elements.py +++ b/acd/l5x/elements.py @@ -38,12 +38,15 @@ def to_xml(self): if isinstance(attribute_value, L5xElement): child_list.append(attribute_value.to_xml()) elif isinstance(attribute_value, list): - pass - #for element in attribute_value: - # if isinstance(element, L5xElement): - # child_list.append(element.to_xml()) - # else: - # child_list.append(f"<{element}/>") + if attribute == "tags": + new_child_list: List[str] = [] + for element in attribute_value: + if isinstance(element, L5xElement): + new_child_list.append(element.to_xml()) + else: + new_child_list.append(f"<{element}/>") + child_list.append(f'<{attribute.title().replace("_", "")}>{" ".join(new_child_list)}') + else: attribute_list.append(f'{attribute.title().replace("_", "")}="{attribute_value}"') @@ -60,9 +63,12 @@ class DataType(L5xElement): @dataclass class Tag(L5xElement): name: str - data_table_instance: int + tag_type: str data_type: str - comments: List[Tuple[str, str]] + radix: str + external_access: str + _data_table_instance: int + _comments: List[Tuple[str, str]] @dataclass @@ -204,12 +210,12 @@ def build(self) -> Tag: try: r = RxGeneric.from_bytes(results[0][3]) except Exception as e: - return Tag(results[0][0], results[0][0], 0, "", []) + return Tag(results[0][0], results[0][0], "Base", "", "Decimal", "None", 0, []) if r.cip_type != 0x6B: - return Tag(results[0][0], results[0][0], 0, "", []) + return Tag(results[0][0], results[0][0], "Base", "", "Decimal", "None", 0, []) if r.main_record.data_type == 0xFFFFFFFF: - return Tag(results[0][0], results[0][0], r.main_record.data_table_instance, "", []) + return Tag(results[0][0], results[0][0], "Base", "", "Decimal", "None", r.main_record.data_table_instance, []) self._cur.execute( "SELECT comp_name, object_id, parent_id, record FROM comps WHERE object_id=" + str( @@ -236,7 +242,7 @@ def build(self) -> Tag: data_type = data_type + "[" + str(r.main_record.dimension_2) + "]" if r.main_record.dimension_3 != 0: data_type = data_type + "[" + str(r.main_record.dimension_3) + "]" - return Tag(name, name, r.main_record.data_table_instance, data_type, comment_results) + return Tag(name, name, "Base", data_type, "Decimal", "Read/Write", r.main_record.data_table_instance, comment_results) @dataclass diff --git a/setup.py b/setup.py index fd72c9b..174fcaa 100644 --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ def run(self): setup( name="acd-tools", - version="0.2a3", + version="0.2a4", description="Rockwell ACD File Tools", classifiers=[ "Development Status :: 3 - Alpha", diff --git a/test/test_api.py b/test/test_api.py index bf11f2a..5b161ea 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -31,4 +31,5 @@ def manual_test_to_xml(): ss = project.to_xml() element = ET.XML(ss) ET.indent(element) - print(ET.tostring(element, encoding='unicode')) \ No newline at end of file + with open(os.path.join("build", "CuteLogix.L5X"), "w") as out_file: + out_file.write(ET.tostring(element, encoding='unicode')) \ No newline at end of file