-
Notifications
You must be signed in to change notification settings - Fork 3
/
txtsplit.py
46 lines (36 loc) · 1.3 KB
/
txtsplit.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
#!/usr/bin/env python3
# usage: txtsplit.py <input_file_name> <output_dir>
# splits a txt2gam file into individual location files
# encoded in utf-8, for git to better handle
# Original file from girllife-ecv. https://git.tfgamessite.com/KevinSmarts/girllife-ecv
import os
import sys
import re
import io
import xml.etree.ElementTree as ET
assert len(sys.argv) == 3, "usage:\ntxtsplit.py <input_file_name> <output_dir>"
iname = str(sys.argv[1])
odir = 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()
ifile = io.open(iname, 'rt', encoding='utf-16')
counter = 1
oname = None
firstline = ifile.readline().replace(u'\ufeff','')
match = re.search('^#\s(\$?[_.\w]+)$', firstline)
if match:
oname = os.path.join(odir, match.group(1).replace("$","_") + '.qsrc' )
counter += 1
assert oname, "file is in the wrong format, must start with a location name"
ofile = io.open(oname, 'w', encoding='utf-8')
ofile.write(firstline)
for line in ifile:
match = re.search('^#\s(\$?[_.\w]+)$', line)
if match:
ofile.close()
oname = os.path.join(odir, match.group(1).replace("$","_") + '.qsrc' )
counter += 1
ofile = io.open(oname, 'w', encoding='utf-8')
ofile.write(line)