a/codesys-ide/scripts/export-documentation.py | b/codesys-ide/scripts/export-documentation.py | ||
---|---|---|---|
1 | import sys, os, re, shutil |
1 | import sys, os, re, shutil |
2 | import helper |
2 | import helper |
3 | 3 | from System.Xml.Xsl import XslCompiledTransform |
|
4 | def get_artifacts(path, libdir): |
4 | |
5 | artifacts = list() |
5 | scriptpath = os.path.abspath(os.path.dirname(sys.argv[0])) |
6 | # ziph is zipfile handle |
6 | xslfile=os.path.join(scriptpath, "plcopenxml.xslt") |
7 | for root, dirs, files in os.walk(path): |
7 | |
8 | if "doc_unzip" in root: |
8 | class ER(ExportReporter): |
9 | for file in files: |
9 | def error(self, object, message): |
10 | filename=os.path.join(root, file) |
10 | system.write_message(Severity.Error, "Error exporting %s: %s" % (object, message)) |
11 | dirname=re.split("doc_unzip[^\\\\]*", root)[1].lstrip("\\") |
11 | def warning(self, object, message): |
12 | # print(dirname) |
12 | system.write_message(Severity.Warning, "Warning exporting %s: %s" % (object, message)) |
13 | destdir=os.path.join(libdir + ".doc", dirname) |
||
14 | # print("parsing file: %s (%s)" % (filename, destdir)) |
||
15 | if not os.path.exists(destdir): |
13 | def nonexportable(self, object): |
16 | os.mkdir(destdir) |
14 | system.write_message(Severity.Information, "Object not exportable: %s" % object) |
17 | shutil.copy2(filename, destdir) |
15 | @property |
18 | artifacts.append(os.path.join(destdir, file)) |
16 | def aborting(self): |
19 | return artifacts |
17 | return False; |
20 | |||
21 | 18 | ||
22 | class SearchBuildDo(helper.SearchBuild): |
19 | class SearchBuildDo(helper.SearchBuild): |
23 | # Build rules for: |
20 | # Build rules for: |
24 | # - *.library -> *.compiled-library |
21 | # - *.library -> *.compiled-library |
25 | def doit(self, filename): |
22 | def doit(self, filename): |
26 | artifacts = list() |
23 | reporter = ER() |
27 | 24 | artifacts = list() |
|
28 | if filename.endswith(".library"): |
25 | |
29 | destination = filename.replace(".library", ".compiled-library") |
26 | tempname = filename + ".xml" |
30 | artifacts.append(destination) |
27 | mdname = filename + ".md" |
31 | 28 | ||
32 | print("%s -> %s\n" % (filename, destination)) |
29 | print("%s -> %s\n" % (filename, mdname)) |
33 | 30 | ||
34 | proj = projects.open(filename) |
31 | proj = projects.open(filename) |
35 | proj.save_as_compiled_library(destination) |
32 | proj.export_xml(reporter, proj.get_children(False), tempname, recursive = True) |
36 | artifacts = get_artifacts(os.path.join("c:", "users", "Public", "Application Data", "CODESYS", "Temporary Files"), filename) |
33 | |
34 | # XSLT transform |
||
35 | print("Transform file with %s" % xslfile) |
||
36 | xsl = XslCompiledTransform() |
||
37 | xsl.Load(xslfile) |
||
38 | xsl.Transform(tempname, mdname) |
||
39 | # hacky fixup for XML preamble |
||
40 | f = open(mdname, "r") |
||
41 | if f: |
||
42 | c = f.read() |
||
43 | f.close() |
||
44 | f = open(mdname, "w") |
||
45 | if f: |
||
46 | f.write(c[41:]); |
||
47 | f.close() |
||
48 | artifacts.append(mdname) |
||
37 | proj.close() |
49 | |
50 | proj.close() |
||
38 | 51 | ||
39 | return artifacts |
52 | return artifacts |
40 | 53 | ||
41 | scriptpath = os.path.abspath(os.path.dirname(sys.argv[0])) |
54 | scriptpath = os.path.abspath(os.path.dirname(sys.argv[0])) |
42 | 55 | ||
43 | sb = SearchBuildDo() |
56 | sb = SearchBuildDo() |
44 | sb.search(".library", ".") |
57 | sb.search(".library", ".") |
58 | sb.search(".project", ".") |
||
45 | sb.save(".", ".drone-artifacts") |
59 | sb.save(".", ".drone-artifacts") |