-
Notifications
You must be signed in to change notification settings - Fork 1
/
utility.py
executable file
·213 lines (190 loc) · 6.8 KB
/
utility.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env python
import re
import pdb
import os
import sys
#zeroPattern=re.compile('.000')
# outFile.write(zeroPattern.sub("", line))
def changeProvinceSingleLine(attribute, multiply, defaultAmount):
if len(sys.argv) == 3:
amount=defaultAmount
elif len(sys.argv) == 4:
amount=sys.argv[3]
else:
print "Usage: " + sys.argv[0] + " save.hoi3 NAT 10"
sys.exit(2)
output_file='outFile.hoi3'
input_file=sys.argv[1]
nation=sys.argv[2]
text_file = open(input_file, "r")
whole_thing = text_file.read()
text_file.close()
text_file = open(input_file, "r")
outFile = open(output_file, 'w')
match_nation_flag=False
reached_end_of_provinces=False
changes=False
for idx, line in enumerate(text_file):
if not reached_end_of_provinces:
if re.match('\\A[0-9]*=',line):
match_nation_flag=False
elif re.match('\\AREB=',line):
reached_end_of_provinces=True
elif match_nation_flag:
value = re.search('\t' + attribute,line)
if value:
if multiply:
line = attribute + str(float(line[value.end():].rstrip()) * float(amount)) + '\n'
else:
line = attribute + amount + '\n'
changes=True
elif re.search('\tcontroller="' + nation + '"',line):
match_nation_flag=True
outFile.write(line)
text_file.close()
outFile.close()
if not changes:
print 'Warning: no changes made'
os.remove(output_file)
else:
os.remove(input_file)
os.rename(output_file, input_file)
print 'Finished making edits for', sys.argv[0]
def changeProvinceMultiLine(attribute, defaultAmount):
if len(sys.argv) == 3:
amount=defaultAmount
elif len(sys.argv) == 4:
amount=sys.argv[3]
else:
print "Usage: " + sys.argv[0] + " save.hoi3 NAT 10"
sys.exit(2)
output_file='outFile.hoi3'
input_file=sys.argv[1]
nation=sys.argv[2]
text_file = open(input_file, "r")
whole_thing = text_file.read()
text_file.close()
text_file = open(input_file, "r")
outFile = open(output_file, 'w')
match_nation_flag=False
delay_write=False
reached_end_of_provinces=False
changes=False
for idx, line in enumerate(text_file):
if not reached_end_of_provinces:
if re.match('\\A[0-9]*=',line):
match_nation_flag=False
elif re.match('\\AREB=',line):
reached_end_of_provinces=True
elif match_nation_flag:
if re.search('\t' + attribute,line):
delay_write=True
if delay_write:
if re.search('}',line):
delay_write=False
line=attribute + '{' + amount + ' ' + amount + '}\n'
changes=True
elif re.search('\tcontroller="' + nation + '"',line):
match_nation_flag=True
if not delay_write:
outFile.write(line)
text_file.close()
outFile.close()
if not changes:
print 'Warning: no changes made'
os.remove(output_file)
else:
os.remove(input_file)
os.rename(output_file, input_file)
print 'Finished making edits for', sys.argv[0]
def changeProvinceProduction(attribute, defaultAmount):
if len(sys.argv) == 3:
amount=defaultAmount
elif len(sys.argv) == 4:
amount=sys.argv[3]
else:
print "Usage: " + sys.argv[0] + " save.hoi3 NAT 10"
sys.exit(2)
output_file='outFile.hoi3'
input_file=sys.argv[1]
nation=sys.argv[2]
text_file = open(input_file, "r")
whole_thing = text_file.read()
text_file.close()
text_file = open(input_file, "r")
outFile = open(output_file, 'w')
match_nation_flag=False
reached_end_of_provinces=False
changes=False
producing=False
for idx, line in enumerate(text_file):
if not reached_end_of_provinces:
if re.match('\\A[0-9]*=',line):
match_nation_flag=False
producing=False
elif re.match('\\AREB=',line):
reached_end_of_provinces=True
elif match_nation_flag:
if re.search('\t' + 'current_producing=',line):
producing=True
elif producing:
value = re.search('\t' + attribute,line)
if value:
line = attribute + str(float(line[value.end():].rstrip()) * float(amount)) + '\n'
changes=True
elif re.search('\tcontroller="' + nation + '"',line):
match_nation_flag=True
outFile.write(line)
text_file.close()
outFile.close()
if not changes:
print 'Warning: no changes made'
os.remove(output_file)
else:
os.remove(input_file)
os.rename(output_file, input_file)
print 'Finished making edits for', sys.argv[0]
def changeNationSingleLine(attribute, multiply, defaultAmount):
if len(sys.argv) == 3:
amount=defaultAmount
elif len(sys.argv) == 4:
amount=sys.argv[3]
else:
print "Usage: " + sys.argv[0] + " save.hoi3 NAT 10"
sys.exit(2)
output_file='outFile.hoi3'
input_file=sys.argv[1]
nation=sys.argv[2]
text_file = open(input_file, "r")
whole_thing = text_file.read()
text_file.close()
text_file = open(input_file, "r")
outFile = open(output_file, 'w')
match_nation_flag=False
reached_end=False
entered_subelement=False
changes=False
for idx, line in enumerate(text_file):
if not reached_end:
if re.match('\\A' + nation + '=*',line):
match_nation_flag=True
elif match_nation_flag:
if re.match('\\A[A-Z][A-Z][A-Z]=*',line):
reached_end=True
value = re.search('\t' + attribute,line)
if value:
if multiply:
line = attribute + str(float(line[value.end():].rstrip()) * float(amount)) + '\n'
else:
line = attribute + amount + '\n'
changes=True
outFile.write(line)
text_file.close()
outFile.close()
if not changes:
print 'Warning: no changes made'
os.remove(output_file)
else:
os.remove(input_file)
os.rename(output_file, input_file)
print 'Finished making edits for', sys.argv[0]