Page Menu
Home
Wildfire Games
Search
Configure Global Search
Log In
Paste
P261
Fix D4443
Active
Public
Actions
Authored by
Freagarach
on Jan 21 2022, 1:29 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Subscribers
None
#!/usr/bin/env python3
import
fileinput
import
glob
import
os
import
xml.etree.ElementTree
as
ET
class
SedLike
:
def
sed
(
path
,
changes
):
for
line
in
fileinput
.
input
(
path
,
inplace
=
True
):
for
change
in
changes
:
line
=
line
.
replace
(
change
[
0
],
change
[
1
])
print
(
line
,
end
=
""
)
class
TemplateFixer
:
def
__init__
(
self
,
vfs_root
):
self
.
template_folder
=
os
.
path
.
join
(
vfs_root
,
'simulation'
,
'templates'
)
def
fix_template
(
self
,
template_path
):
tree
=
ET
.
parse
(
template_path
)
root
=
tree
.
getroot
()
cmp_identity
=
root
.
find
(
'Identity'
)
if
cmp_identity
==
None
:
return
False
formations
=
cmp_identity
.
find
(
'Formations'
)
if
formations
==
None
:
return
False
cmp_unitai
=
root
.
find
(
'UnitAI'
)
if
cmp_unitai
==
None
:
cmp_unitai
=
ET
.
Element
(
'UnitAI'
)
root
.
append
(
cmp_unitai
)
cmp_unitai
.
append
(
formations
)
cmp_identity
.
remove
(
formations
)
if
cmp_identity
.
__len__
()
==
0
:
root
.
remove
(
cmp_identity
)
root
[:]
=
sorted
(
root
,
key
=
lambda
x
:
x
.
tag
)
ET
.
indent
(
tree
)
tree
.
write
(
template_path
,
xml_declaration
=
True
,
encoding
=
'utf-8'
)
return
True
def
fix_style
(
self
,
template_path
):
self
.
changes
=
[
[
' />'
,
'/>'
],
[
"version='1.0'"
,
'version="1.0"'
],
[
"'utf-8'"
,
'"utf-8"'
]
]
SedLike
.
sed
(
template_path
,
self
.
changes
)
with
open
(
template_path
,
'a'
)
as
file
:
file
.
write
(
'
\n
'
)
def
run
(
self
):
for
template
in
glob
.
iglob
(
self
.
template_folder
+
'/**/*.xml'
,
recursive
=
True
):
if
self
.
fix_template
(
template
):
self
.
fix_style
(
template
)
if
__name__
==
'__main__'
:
script_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
template_fixer
=
TemplateFixer
(
script_dir
)
template_fixer
.
run
()
Event Timeline
Freagarach
created this paste.
Jan 21 2022, 1:29 PM
Freagarach
mentioned this in
D4443: Move formations from cmpIdentity to cmpUnitAI.
.
Freagarach
mentioned this in
rP26235: Move the allowed formations from cmpIdentity to cmpUnitAI.
.
Jan 23 2022, 8:25 AM
Freagarach
changed the visibility from "All Users" to "Public (No Login Required)".
Jan 23 2022, 8:26 AM
Log In to Comment