forked from unknown-horizons/unknown-horizons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stage_build_mac.py
161 lines (134 loc) · 4.6 KB
/
stage_build_mac.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
#!/usr/bin/env python
# ###################################################
# Copyright (C) 2008-2014 The Unknown Horizons Team
# This file is part of Unknown Horizons.
#
# Unknown Horizons is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# ###################################################
import shutil
import sys
import getopt
import os
import glob
verbose = False
help_message = '''
Usage: stage_build_mac.py [options]
Options:
--run Start app with "open ./dist/Unknown Horizons.app"
when done (all is cleaned before this)
--fife-dir=<Location> Location of FIFE-trunk
--python-bin=<Location> For people with a lot of python,
this is totally optional!
--verbose Just as it sounds :) will output more info
'''
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
def setup(fife_dir):
"""
Setup files and directories
"""
if verbose:
print "Setting up environment"
# If these two exists we remove them for a clean build
if os.path.exists('./build'):
if verbose:
print "Cleaning build path"
shutil.rmtree('./build')
if os.path.exists('./dist'):
if verbose:
print "Cleaning dist path"
shutil.rmtree('./dist')
# These should have cleaned out, else we remove them
if os.path.exists('./src'):
if verbose:
print "Cleaning src path"
shutil.rmtree('./src')
if os.path.exists('./fife'):
if verbose:
print "Cleaning fife path"
shutil.rmtree('./fife')
if verbose:
print "Create src directory"
# The source files, for building app correctly
os.makedirs('./src/Contents/Resources/')
# Copy fife and content
if verbose:
print "Copying Icon.icns"
shutil.copy('./content/gui/icons/Icon.icns', './src/Contents/Resources/')
if verbose:
print "Copying fife source from " + fife_dir + "engine/python/fife"
while shutil.copytree(fife_dir + 'engine/python/fife', './fife'):
if verbose:
print "..."
if verbose:
print "Copying content into src"
while shutil.copytree('./content', './src/Contents/Resources/content'):
if verbose:
print "..."
def tearDown(run):
shutil.rmtree('./src/')
shutil.rmtree('./fife')
# Remove some other styff
files = glob.glob('*.egg')
for f in files:
if os.path.isfile(f):
os.remove(f)
else:
shutil.rmtree(f)
# If the -r or --run arg is passed we start the app after build
if run:
os.popen("open ./dist/Unknown\ Horizons.app")
def build(pyver):
os.system(pyver + " setup.py build_i18n")
os.system(pyver + " setup_mac.py py2app")
def main(argv=None):
fife_dir = False
pyver = "/usr/bin/python"
run = False
if argv is None:
argv = sys.argv
try:
try:
opts, args = getopt.getopt(argv[1:], "hfp:rv", ["help",
"fife-dir=", "python-bin=", "run", "--verbose"])
except getopt.error, msg:
raise Usage(msg)
# option processing
for option, value in opts:
if option in ("-p", "--python-bin",):
pyver = value
if option in ("-f", "--fife-dir",):
fife_dir = value
if option in ("-h", "--help"):
raise Usage(help_message)
if option in ("-r", "--run",):
run = True
if option in ("-v", "--verbose",):
verbose = True
# We got to have the fife source!!!!!
if not fife_dir:
raise Usage(help_message)
except Usage, err:
print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
print >> sys.stderr, "\t for help use --help"
return 2
setup(fife_dir)
build(pyver)
tearDown(run)
if __name__ == "__main__":
sys.exit(main())