From 7d586c1d4b2b10046b070156ba60566ee89a509f Mon Sep 17 00:00:00 2001 From: Karl Walther Date: Sun, 15 Dec 2024 22:43:26 +0100 Subject: [PATCH] correct paths --- .CI/tests/translate_test_cases.py | 2 +- IEC61131-10XML/Add/plc.xml | 4 ++-- IEC61131-10XML/MultiplyByParameter/plc.xml | 2 +- cdl_plc.py | 15 +++++++++++++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.CI/tests/translate_test_cases.py b/.CI/tests/translate_test_cases.py index 62a27f3..a311b31 100644 --- a/.CI/tests/translate_test_cases.py +++ b/.CI/tests/translate_test_cases.py @@ -2,7 +2,7 @@ sys.path.append('../../') import cdl_plc -cxf_json_path = '../../cxf/ModelicaTestCases/' +cxf_json_path = 'cxf/ModelicaTestCases/' test_cases = [ cxf_json_path + 'SingleBlocks/Reals/' + 'Add', diff --git a/IEC61131-10XML/Add/plc.xml b/IEC61131-10XML/Add/plc.xml index 3e91252..c37cf43 100644 --- a/IEC61131-10XML/Add/plc.xml +++ b/IEC61131-10XML/Add/plc.xml @@ -57,7 +57,7 @@ u2 - + @@ -82,7 +82,7 @@ - + diff --git a/IEC61131-10XML/MultiplyByParameter/plc.xml b/IEC61131-10XML/MultiplyByParameter/plc.xml index 4c30285..d25fefa 100644 --- a/IEC61131-10XML/MultiplyByParameter/plc.xml +++ b/IEC61131-10XML/MultiplyByParameter/plc.xml @@ -66,7 +66,7 @@ r1 - + diff --git a/cdl_plc.py b/cdl_plc.py index cd81f9c..148ab31 100644 --- a/cdl_plc.py +++ b/cdl_plc.py @@ -6,6 +6,14 @@ import ast +import os + +abspath = os.path.abspath(__file__) +dname = os.path.dirname(abspath) +print(dname) +os.chdir(dname) + + class Cdl2Plc: dict_assign_cdl_to_iec_standard_lib = { @@ -1091,19 +1099,22 @@ def create_dict_cdl_blocks(self): cdl_block = fileBlock.read() self.dict_cdl_blocks["scalar_inputs"].add(cdl_block) - def create_iec_xml(self): + def create_iec_xml(self, debug=False): """ Render based on dicts """ template_loader = jinja2.FileSystemLoader(searchpath="./") template_env = jinja2.Environment(loader=template_loader) - # fileTemplateVariable = "templateVariable.xml" file_template_global = [ "xml_templates/structure/global.xml", "templateVariable.xml", ][0] + + if debug: + print('cwd: ', os.getcwd()) + template = template_env.get_template(file_template_global) self.output_text = template.render( dictInputVars=self.program_inputs,