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
|
#!/usr/bin/env python
import os
import re
import sys
import datetime
import xml.etree.ElementTree as ET
import defusedxml.ElementTree as goodET
from xcosblocks import createDefaultParent, process_xcos_model, remove_hyphen_number
sys.tracebacklimit = 0
if len(sys.argv) != 4:
print("Usage: %s filename.xml workspace.dat context" % sys.argv[0])
sys.exit(1)
filename = sys.argv[1]
(basename, ext) = os.path.splitext(filename)
workspace_file = sys.argv[2]
context = sys.argv[3]
if ext != '.xml':
print("Usage: %s filename.xml workspace.dat" % sys.argv[0])
sys.exit(1)
base = r'(_[a-zA-Z]*_on_Cloud)?( *\([0-9]*\))?\.xml$'
title = re.sub(r'^.*/', r'', filename)
title = re.sub(base, r'', title)
tree = goodET.parse(filename)
diagram = tree.getroot()
rootattribid = '0:1:0'
parentattribid = '0:2:0'
outdiagram = ET.Element('XcosDiagram')
outdiagram.set('background', '-1')
outdiagram.set('finalIntegrationTime', '30.0') # TODO: From POST
outdiagram.set('title', title)
dt = datetime.datetime(2021, 7, 15, 15, 31)
comment = ET.Comment(dt.strftime('Xcos - 2.0 - scilab-6.1.1 - %Y%m%d %H%M'))
outdiagram.append(comment)
outmodel = process_xcos_model(diagram, title, rootattribid, parentattribid,
workspace_file, context)
outdiagram.append(outmodel)
defaultParent = createDefaultParent(parentattribid, rootattribid)
outdiagram.append(defaultParent)
outtree = ET.ElementTree(outdiagram)
ET.indent(outtree)
outfile = remove_hyphen_number(basename) + '.xcos'
outtree.write(outfile, encoding='UTF-8', xml_declaration=True)
sys.exit(0)
|