Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 60d1b62

Browse files
authored
Create hoi4statemanpowermultiplier
1 parent 6345618 commit 60d1b62

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

‎python2/hoi4statemanpowermultiplier

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/python
2+
import argparse
3+
import os
4+
import glob
5+
import sys
6+
7+
#############################
8+
###
9+
### HoI 4 State Manpower Multiplier by Yard1, originally for Equestria at War mod
10+
### Written in Python 2.7
11+
###
12+
### Copyright (c) 2017 Antoni Baum (Yard1)
13+
### Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
14+
### The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
15+
### THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
###
17+
### usage: hoi4StateManpowerChanger.py [-h] input multiplier
18+
###
19+
### Given a state history file or folder, multiply the manpower by a given
20+
### multiplier.
21+
###
22+
### positional arguments:
23+
### input State history file name/folder containing files
24+
### multiplier Manpower multiplier
25+
###
26+
### optional arguments:
27+
### -h, --help show this help message and exit
28+
###
29+
#############################
30+
31+
def readable_dir(prospective_dir):
32+
if not os.path.isdir(prospective_dir):
33+
raise Exception("readable_dir:{0} is not a valid path".format(prospective_dir))
34+
if os.access(prospective_dir, os.R_OK):
35+
return prospective_dir
36+
else:
37+
raise Exception("readable_dir:{0} is not a readable dir".format(prospective_dir))
38+
39+
#############################
40+
41+
def increase_manpower(name, multi):
42+
print("Reading file " + name + "...")
43+
with open(name, "r") as f:
44+
lines = f.read().splitlines()
45+
new_lines = list()
46+
for line in lines:
47+
if "manpower" in line:
48+
nline = line.split("=")
49+
nline[1] = str(int(int(nline[1])*float(multi)))
50+
line = nline[0] + "=" + nline[1]
51+
new_lines.append(line)
52+
with open(name, "w") as f:
53+
f.writelines(str(line) + "\n" for line in new_lines)
54+
55+
#############################
56+
parser = argparse.ArgumentParser(description='Given a state history file or folder, multiply the manpower by a given multiplier.')
57+
parser.add_argument('input', metavar='input',
58+
help='State history file name/folder containing files')
59+
parser.add_argument('multiplier', metavar='multiplier',
60+
help='Manpower multiplier')
61+
62+
args = parser.parse_args()
63+
counter = 0
64+
names_global = list()
65+
is_dir = False
66+
try:
67+
dir = readable_dir(args.input)
68+
is_dir = True
69+
except:
70+
print("Not a directory, treating as file.")
71+
72+
if is_dir:
73+
for f in glob.glob(dir+"/*"):
74+
try:
75+
increase_manpower(f, args.multiplier)
76+
counter = counter+1
77+
except:
78+
pass
79+
else:
80+
increase_manpower(args.input, args.multiplier)
81+
counter = counter+1
82+
print("Finished, %s state files parsed" % counter)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /