--- a/codesys-ide/scripts/export-documentation.py +++ b/codesys-ide/scripts/export-documentation.py @@ -1,40 +1,53 @@ import sys, os, re, shutil import helper +from System.Xml.Xsl import XslCompiledTransform -def get_artifacts(path, libdir): - artifacts = list() - # ziph is zipfile handle - for root, dirs, files in os.walk(path): - if "doc_unzip" in root: - for file in files: - filename=os.path.join(root, file) - dirname=re.split("doc_unzip[^\\\\]*", root)[1].lstrip("\\") -# print(dirname) - destdir=os.path.join(libdir + ".doc", dirname) -# print("parsing file: %s (%s)" % (filename, destdir)) - if not os.path.exists(destdir): - os.mkdir(destdir) - shutil.copy2(filename, destdir) - artifacts.append(os.path.join(destdir, file)) - return artifacts +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; class SearchBuildDo(helper.SearchBuild): # Build rules for: # - *.library -> *.compiled-library def doit(self, filename): + reporter = ER() artifacts = list() - if filename.endswith(".library"): - destination = filename.replace(".library", ".compiled-library") - artifacts.append(destination) + tempname = filename + ".xml" + mdname = filename + ".md" - print("%s -> %s\n" % (filename, destination)) + print("%s -> %s\n" % (filename, mdname)) - proj = projects.open(filename) - proj.save_as_compiled_library(destination) - artifacts = get_artifacts(os.path.join("c:", "users", "Public", "Application Data", "CODESYS", "Temporary Files"), filename) - proj.close() + proj = projects.open(filename) + proj.export_xml(reporter, proj.get_children(False), tempname, recursive = 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:]); + f.close() + artifacts.append(mdname) + + proj.close() return artifacts @@ -42,4 +55,5 @@ sb = SearchBuildDo() sb.search(".library", ".") +sb.search(".project", ".") sb.save(".", ".drone-artifacts")