Skip to content

Commit

Permalink
build_mini: compile mapcut from source if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
zijistark committed Dec 8, 2016
1 parent ada0cf2 commit 8af664c
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions build_mini.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

import os
import sys
import datetime
import subprocess
Expand All @@ -8,27 +9,41 @@


version = 'v1.3.0-BETA'

cut_titles = ['e_rajastan', 'e_mali', 'k_sahara', 'k_fezzan', 'k_kanem', 'k_hausaland']
scons_bin_path = '/usr/bin/scons'

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:
sys.stdout.write(subprocess.check_output(scons_bin_path, universal_newlines=True, stderr=subprocess.STDOUT))
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():
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 1
return 2

print(">> executing mapcut...")

try:
sys.stdout.write(subprocess.check_output([str(mapcut_bin_path)] + cut_titles,
universal_newlines=True, stderr=subprocess.STDOUT))
except subprocess.CalledProcessError as e:
sys.stderr.write('mapcut failed!\ncommand: {}\nexit code: {}\n\n{}'.format(e.cmd, e.returncode, e.output))
return 2
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)
Expand Down

0 comments on commit 8af664c

Please sign in to comment.