[20f0d8]: / codesys-ide / scripts / export-documentation.py  Maximize  Restore  History

Download this file

80 lines (62 with data), 2.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import sys, os, re, shutil
import helper
from System.Xml.Xsl import XslCompiledTransform
scriptpath = os.path.abspath(os.path.dirname(sys.argv[0]))
xslfile=os.path.join(scriptpath, "plcopenxml.xslt")
class ER(ExportReporter):
def error(self, object, message):
system.write_message(Severity.Error, "Error exporting %s: %s" % (object, message))
def warning(self, object, message):
system.write_message(Severity.Warning, "Warning exporting %s: %s" % (object, message))
def nonexportable(self, object):
system.write_message(Severity.Information, "Object not exportable: %s" % object)
@property
def aborting(self):
return False;
def parseObj(treeobj, depth=0):
objs = list()
if not treeobj.is_device:
objs.append(treeobj)
for child in treeobj.get_children(False):
objs += parseObj(child, depth+1)
return objs
def parseProj(proj):
objs = list()
for obj in proj.get_children():
objs += parseObj(obj)
return objs
class SearchBuildDo(helper.SearchBuild):
# Build rules for:
# - *.library -> *.compiled-library
def doit(self, filename):
reporter = ER()
artifacts = list()
tempname = filename + ".xml"
mdname = filename + ".md"
print("%s -> %s\n" % (filename, mdname))
proj = projects.open(filename)
objs = parseProj(proj)
# proj.export_xml(reporter, proj.get_children(False), tempname, recursive = True)
proj.export_xml(reporter, objs, tempname, recursive = False, declarations_as_plaintext = True)
# XSLT transform
print("Transform file with %s" % xslfile)
xsl = XslCompiledTransform()
xsl.Load(xslfile)
xsl.Transform(tempname, mdname)
# hacky fixup for XML preamble
f = open(mdname, "r")
if f:
c = f.read()
f.close()
f = open(mdname, "w")
if f:
f.write(c[41:].replace("&lt;", "<").replace("&gt;", ">"));
f.close()
artifacts.append(mdname)
proj.close()
return artifacts
scriptpath = os.path.abspath(os.path.dirname(sys.argv[0]))
sb = SearchBuildDo()
sb.search(".library", ".")
sb.search(".project", ".")
sb.save(".", ".drone-artifacts")