[r46]: / trunk / cforge / cforge / Package / CFORGE / Scripts / action.markdown.py  Maximize  Restore  History

Download this file

50 lines (41 with data), 1.7 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
# Example Batch:
# set WD=%~d0%~p0
# "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

import sys, os
import os.path
import clr
clr.AddReference("System.Xml")
from System.Xml.Xsl import XslCompiledTransform


scriptpath = os.path.abspath(os.path.dirname(sys.argv[0]))
folder=sys.argv[1].replace("`````", "'")
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;

# Export all libraries and projects
reporter = ER()
for root, dirs, files in os.walk(folder):
    for file in files:
        if file.endswith(".library") or file.endswith(".project"):
			print("Export project '%s'" % file)
			filename=str(os.path.join(root, file))
			tempname=str(os.path.join(root, file + ".xml"))
			mdname=str(os.path.join(root, file + ".md"))
			proj = projects.open(filename)
			proj.export_xml(reporter, proj.get_children(False), tempname, recursive = True)
			proj.close()
			
			# XSLT transform
			print("Transform file with %s" % xslfile)
			xsl = XslCompiledTransform()
			xsl.Load(xslfile)
			xsl.Transform(tempname, mdname)
else:
	print("error: file not found '%s'" % file)

system.exit()