equal
deleted
inserted
replaced
209 PLCOpen_v1_xml = PLCOpen_v1_file.read() |
209 PLCOpen_v1_xml = PLCOpen_v1_file.read() |
210 PLCOpen_v1_file.close() |
210 PLCOpen_v1_file.close() |
211 PLCOpen_v1_xml = PLCOpen_v1_xml.replace( |
211 PLCOpen_v1_xml = PLCOpen_v1_xml.replace( |
212 "http://www.plcopen.org/xml/tc6.xsd", |
212 "http://www.plcopen.org/xml/tc6.xsd", |
213 "http://www.plcopen.org/xml/tc6_0201") |
213 "http://www.plcopen.org/xml/tc6_0201") |
214 PLCOpen_v1_xsd = etree.XMLSchema(etree.fromstring(PLCOpen_v1_xml)) |
214 PLCOpen_v1_xsd = etree.XMLSchema(etree.fromstring(PLCOpen_v1_xml.encode())) |
215 |
215 |
216 # XPath for file compatibility process |
216 # XPath for file compatibility process |
217 ProjectResourcesXPath = PLCOpen_XPath("ppx:instances/ppx:configurations/ppx:configuration/ppx:resource") |
217 ProjectResourcesXPath = PLCOpen_XPath("ppx:instances/ppx:configurations/ppx:configuration/ppx:resource") |
218 ResourceInstancesXpath = PLCOpen_XPath("ppx:pouInstance | ppx:task/ppx:pouInstance") |
218 ResourceInstancesXpath = PLCOpen_XPath("ppx:pouInstance | ppx:task/ppx:pouInstance") |
219 TransitionsConditionXPath = PLCOpen_XPath("ppx:types/ppx:pous/ppx:pou/ppx:body/*/ppx:transition/ppx:condition") |
219 TransitionsConditionXPath = PLCOpen_XPath("ppx:types/ppx:pous/ppx:pou/ppx:body/*/ppx:transition/ppx:condition") |
299 except Exception as e: |
299 except Exception as e: |
300 return None, str(e) |
300 return None, str(e) |
301 |
301 |
302 |
302 |
303 def LoadProject(filepath): |
303 def LoadProject(filepath): |
304 project_file = open(filepath) |
304 project_file = open(filepath, encoding='utf-8') |
305 project_xml = project_file.read() |
305 project_xml = project_file.read() |
306 project_file.close() |
306 project_file.close() |
307 return LoadProjectXML(project_xml) |
307 return LoadProjectXML(project_xml) |
308 |
308 |
309 |
309 |
330 def SaveProject(project, filepath): |
330 def SaveProject(project, filepath): |
331 content = etree.tostring( |
331 content = etree.tostring( |
332 project, |
332 project, |
333 pretty_print=True, |
333 pretty_print=True, |
334 xml_declaration=True, |
334 xml_declaration=True, |
335 encoding='utf-8') |
335 encoding='utf-8').decode() |
336 |
336 |
337 assert len(content) != 0 |
337 assert len(content) != 0 |
338 |
338 |
339 project_file = open(filepath, 'w') |
339 project_file = open(filepath, 'w', encoding='utf-8') |
340 project_file.write(content) |
340 project_file.write(content) |
341 project_file.close() |
341 project_file.close() |
342 |
342 |
343 |
343 |
344 # ---------------------------------------------------------------------- |
344 # ---------------------------------------------------------------------- |