a/trunk/cforge/cforge/Package/CFORGE/Scripts/action.markdown.py | b/trunk/cforge/cforge/Package/CFORGE/Scripts/action.markdown.py | ||
---|---|---|---|
... |
... |
||
2 | # set WD=%~d0%~p0 |
2 | # set WD=%~d0%~p0 |
3 | # "C:\Program Files (x86)\3S CODESYS-V3.5.12.0\CODESYS\Common\CODESYS.exe" --profile="CODESYS V3.5 SP12" --runscript="%WD%\action.plcopenxml.export.py" --scriptargs="test.project" --noUI |
3 | # "C:\Program Files (x86)\3S CODESYS-V3.5.12.0\CODESYS\Common\CODESYS.exe" --profile="CODESYS V3.5 SP12" --runscript="%WD%\action.plcopenxml.export.py" --scriptargs="test.project" --noUI |
4 | 4 | ||
5 | import sys, os |
5 | import sys, os |
6 | import os.path |
6 | import os.path |
7 | import clr |
||
8 | clr.AddReference("System.Xml") |
||
9 | from System.Xml.Xsl import XslCompiledTransform |
||
10 | |||
7 | 11 | ||
8 | scriptpath = os.path.abspath(os.path.dirname(sys.argv[0])) |
12 | scriptpath = os.path.abspath(os.path.dirname(sys.argv[0])) |
9 | folder=sys.argv[1] |
13 | folder=sys.argv[1] |
10 | xsl=os.path.join(scriptpath, "plcopenxml.xsl") |
14 | xslfile=os.path.join(scriptpath, "plcopenxml.xslt") |
11 | 15 | ||
12 | class ER(ExportReporter): |
16 | class ER(ExportReporter): |
13 | def error(self, object, message): |
17 | def error(self, object, message): |
14 | system.write_message(Severity.Error, "Error exporting %s: %s" % (object, message)) |
18 | system.write_message(Severity.Error, "Error exporting %s: %s" % (object, message)) |
15 | def warning(self, object, message): |
19 | def warning(self, object, message): |
... |
... |
||
24 | reporter = ER() |
28 | reporter = ER() |
25 | for root, dirs, files in os.walk(folder): |
29 | for root, dirs, files in os.walk(folder): |
26 | for file in files: |
30 | for file in files: |
27 | if file.endswith(".library") or file.endswith(".project"): |
31 | if file.endswith(".library") or file.endswith(".project"): |
28 | print("Export project '%s'" % file) |
32 | print("Export project '%s'" % file) |
29 | print(reporter) |
33 | filename=str(os.path.join(root, file)) |
30 | filename=str(os.path.join(root, file)) |
34 | tempname=str(os.path.join(root, file + ".xml")) |
31 | tempname=str(os.path.join(root, file + ".xml")) |
35 | mdname=str(os.path.join(root, file + ".md")) |
32 | proj = projects.open(filename) |
36 | proj = projects.open(filename) |
33 | proj.export_xml(reporter, proj.get_children(False), tempname, recursive = True) |
37 | proj.export_xml(reporter, proj.get_children(False), tempname, recursive = True) |
34 | proj.close() |
38 | proj.close() |
35 | 39 | ||
36 | # XSLT transform |
40 | # XSLT transform |
37 | print("Transform file with %s" % xsl) |
41 | print("Transform file with %s" % xslfile) |
42 | xsl = XslCompiledTransform() |
||
43 | xsl.Load(xslfile) |
||
44 | xsl.Transform(tempname, mdname) |
||
38 | else: |
45 | else: |
39 | print("error: file not found '%s'" % file) |
46 | print("error: file not found '%s'" % file) |
40 | 47 | ||
41 | system.exit() |
48 | system.exit() |
42 | 49 |