-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxml2prf.py
47 lines (39 loc) · 1.24 KB
/
xml2prf.py
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
#!/usr/bin/env python
# Author: [email protected]
import os
import sys
import time
import xml.etree.ElementTree as ET
def main(argv):
if len(argv) < 2:
print('Usage: {0} <xmlfile>'.format(argv[0]))
sys.exit(1)
if os.path.exists(argv[1]):
output = []
root = ET.parse(argv[1]).getroot()
profile_name = argv[1].replace('.xml', '')
for child in root:
if 'value' in child.attrib.keys():
output.append('{0}={1}={2}'.format(
child.attrib['name'],
child.tag,
child.attrib['value']
)
)
else:
output.append('{0}={1}={2}'.format(
child.attrib['name'],
child.tag,
child.text or ''
)
)
with open(profile_name + '.prf', 'w') as fp:
fp.write(
(
'# Date: {0}\n\n' +
'profile_name={1}\n\n'
).format(time.strftime('%Y-%m-%d'), profile_name)
)
fp.write('\n'.join(sorted(output)))
if __name__ == '__main__':
main(sys.argv)