Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
VIGNET Pierre
cadbiom
Commits
b78e6507
Commit
b78e6507
authored
Jan 29, 2020
by
VIGNET Pierre
Browse files
[lib] XmlVisitor: first refactor; remove shit code
parent
e2ad1a45
Changes
1
Hide whitespace changes
Inline
Side-by-side
library/cadbiom/models/guard_transitions/translators/chart_xml.py
View file @
b78e6507
...
...
@@ -51,6 +51,7 @@ Classes::
"""
from
__future__
import
unicode_literals
from
__future__
import
print_function
import
itertools
as
it
from
xml.sax
import
make_parser
from
xml.sax
import
parseString
...
...
@@ -148,43 +149,33 @@ class XmlVisitor:
tag
=
"CMacroNode"
attrname
=
[
"name"
,
"xloc"
,
"yloc"
,
"wloc"
,
"hloc"
]
attr
=
[
mnode
.
name
,
mnode
.
xloc
,
mnode
.
yloc
,
mnode
.
wloc
,
mnode
.
hloc
]
properties
=
[
tag
,
attrname
,
attr
]
macro
=
etree
.
SubElement
(
self
.
current_element
,
properties
[
0
]
)
macro
=
etree
.
SubElement
(
self
.
current_element
,
tag
)
self
.
current_element
=
macro
if
len
(
properties
)
>
1
:
attrname
=
properties
[
1
]
attr
=
properties
[
2
]
attributes
=
macro
.
attrib
for
i
in
range
(
0
,
len
(
attrname
)):
attributes
[
attrname
[
i
]]
=
str
(
attr
[
i
])
# Update attributes of the element
# Keys: attr names; Values: attr values
macro
.
attrib
.
update
(
dict
(
zip
(
attrname
,
attr
)))
# nodes
for
snode
in
mnode
.
sub_nodes
:
properties
=
snode
.
accept
(
self
)
if
properties
[
0
]
==
"CMacroNode"
:
self
.
current_element
=
macro
if
properties
[
0
]
!=
"CMacroNode"
:
else
:
subel
=
etree
.
SubElement
(
self
.
current_element
,
properties
[
0
])
if
len
(
properties
)
>
1
:
attrname
=
properties
[
1
]
attr
=
properties
[
2
]
attributes
=
subel
.
attrib
for
i
in
range
(
0
,
len
(
attrname
)):
attributes
[
attrname
[
i
]]
=
str
(
attr
[
i
])
attrname
=
properties
[
1
]
attr
=
properties
[
2
]
subel
.
attrib
.
update
(
dict
(
zip
(
attrname
,
attr
)))
# transitions
for
gtr
in
mnode
.
transitions
:
for
trunlist
in
gtr
:
properties
=
trunlist
.
accept
(
self
)
sub_tr
=
etree
.
SubElement
(
self
.
current_element
,
properties
[
0
])
if
len
(
properties
)
>
1
:
attrname
=
properties
[
1
]
attr
=
properties
[
2
]
attributes
=
sub_tr
.
attrib
for
i
in
range
(
0
,
len
(
attrname
)):
attributes
[
attrname
[
i
]]
=
str
(
attr
[
i
])
for
transition
in
it
.
chain
(
*
mnode
.
transitions
):
properties
=
transition
.
accept
(
self
)
sub_tr
=
etree
.
SubElement
(
self
.
current_element
,
properties
[
0
])
attrname
=
properties
[
1
]
attr
=
properties
[
2
]
sub_tr
.
attrib
.
update
(
dict
(
zip
(
attrname
,
attr
)))
self
.
current_element
=
save_macro
return
[
tag
,
attrname
,
attr
]
...
...
@@ -226,13 +217,10 @@ class XmlVisitor:
xmodel
.
append
(
element
)
# nodes
for
snode
in
tnode
.
sub_nodes
:
create_xml_element
(
snode
)
[
create_xml_element
(
snode
)
for
snode
in
tnode
.
sub_nodes
]
# transitions
for
gtr
in
tnode
.
transitions
:
for
trans
in
gtr
:
create_xml_element
(
trans
)
[
create_xml_element
(
trans
)
for
trans
in
it
.
chain
(
*
tnode
.
transitions
)]
# constraints
if
len
(
tnode
.
model
.
constraints
)
>
0
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment