-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_mini.py
executable file
·63 lines (48 loc) · 2.03 KB
/
build_mini.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
#!/usr/bin/env python3
import os
import sys
import datetime
import subprocess
from pathlib import Path
from localpaths import rootpath
version = 'v1.7.3-BETA'
cut_titles = ['e_rajastan', 'e_deccan', 'e_mali', 'k_sahara', 'k_fezzan', 'k_kanem', 'k_hausaland', 'k_canarias']
scons_bin_path = Path('/usr/bin/scons')
mapcut_bin_path_default = Path('/usr/local/bin/mapcut')
mini_path = rootpath / 'MiniSWMH/MiniSWMH'
mapcut_path = rootpath / 'ck2utils/mapcut'
def build_mapcut():
print(">> attempting to build mapcut from source...")
os.chdir(str(mapcut_path))
try:
output = subprocess.check_output(str(scons_bin_path), universal_newlines=True, stderr=subprocess.STDOUT)
if sys.stdout:
sys.stdout.write(output)
except subprocess.CalledProcessError as e:
sys.stderr.write('> scons failed!\n> command: {}\n> exit code: {}\n\n{}'.format(e.cmd, e.returncode, e.output))
sys.exit(1)
def main():
if sys.platform.startswith('linux') and mapcut_bin_path_default.exists():
mapcut_bin_path = mapcut_bin_path_default
else:
mapcut_bin = 'mapcut' if sys.platform.startswith('linux') else 'mapcut.exe'
mapcut_bin_path = mapcut_path / mapcut_bin
if not mapcut_bin_path.exists():
build_mapcut()
if not mapcut_bin_path.exists():
sys.stderr.write('mapcut binary not found: {}\n'.format(mapcut_bin_path))
return 2
print(">> executing mapcut...")
try:
output = subprocess.check_output([str(mapcut_bin_path)] + cut_titles,
universal_newlines=True, stderr=subprocess.STDOUT)
if sys.stdout:
sys.stdout.write(output)
except subprocess.CalledProcessError as e:
sys.stderr.write('> mapcut failed!\n> command: {}\n> exit code: {}\n\n{}'.format(e.cmd, e.returncode, e.output))
return 3
with (mini_path / 'version.txt').open('w') as f:
print('{} - {}'.format(version, datetime.date.today()), file=f)
return 0
if __name__ == '__main__':
sys.exit(main())