forked from f95Lok/SoA-LokScriptTranslation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
txtmerge.py
44 lines (33 loc) · 1.1 KB
/
txtmerge.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
#!/usr/bin/env python3
# usage: txtmerge.py <input_dir> <output_file_name>
# does the exact opposite of txtsplit.py
# Original file from Girl Life ecv - Betmonty
import os
import sys
import re
import io
import xml.etree.ElementTree as ET
assert len(sys.argv) == 3, "usage:\ntxtmerge.py <input_dir> <output_file_name>"
idir = str(sys.argv[1])
oname = str(sys.argv[2])
# read the project xml file first
# let's do this later in order to implement directory structure
tree = ET.parse('SOA.qproj')
root = tree.getroot()
ofile = io.open(oname, 'w', encoding='utf-16', newline='\r\n')
for location in root.iter('Location'):
iname = location.attrib['name']
iname = iname.replace("$","_")
try:
ifile = io.open(os.path.join(idir,iname + '.qsrc'), 'rt', encoding='utf-8')
text = ifile.read()
# make sure there's a line at the end of file
# (why wouldn't there be one? WINDOWS!
if text[-1] != u'\n':
text += u'\n\n'
ofile.write(text)
ifile.close()
except IOError:
print("WARNING: missing location %s" % iname)
pass
ofile.close()