forked from Tuxemon/Tuxemon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_android.py
executable file
·152 lines (118 loc) · 4.24 KB
/
build_android.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
#!/usr/bin/python
import sys
import shutil
import subprocess
import urllib2
import os
try:
import configparser
except ImportError:
import ConfigParser as configparser
sys.argv = [sys.argv[0]]
RAPT_ARCHIVE = "renpy-6.18.3-rapt.zip"
RAPT_LINK = "http://www.tuxemon.org/files/" + RAPT_ARCHIVE
SIX_ARCHIVE = "six-1.9.0.tar.gz"
SIX_LINK = "https://pypi.python.org/packages/source/s/six/%s#md5=476881ef4012262dfc8adc645ee786c4" % SIX_ARCHIVE
def download_rapt():
# First, download rapt
print " Downloading rapt..."
headers = { 'User-Agent' : 'Mozilla/5.0' }
req = urllib2.Request(RAPT_LINK, None, headers)
data = urllib2.urlopen(req).read()
# write the data
f = open("build/" + RAPT_ARCHIVE, 'wb')
f.write(data)
f.close()
def unzip_rapt():
import zipfile
print " Unzipping", RAPT_ARCHIVE, "..."
with zipfile.ZipFile("build/" + RAPT_ARCHIVE, "r") as z:
z.extractall("build")
def modify_rapt():
f = open("build/rapt/buildlib/rapt/build.py", "r")
contents = f.readlines()
f.close()
lines = []
fixed = False
for line in contents:
if "RENPY = plat.renpy" in line:
lines.append(' RENPY = False\n')
fixed = True
else:
lines.append(line)
if fixed:
print " Fixing rapt builder..."
f = open("build/rapt/buildlib/rapt/build.py.fixed", 'w')
for line in lines:
f.write(line)
f.close()
os.rename("build/rapt/buildlib/rapt/build.py.fixed", "build/rapt/buildlib/rapt/build.py")
def install_dependencies():
if not os.path.exists("tuxemon/neteria"):
print "WARNING: Neteria module not found. Networking will be disabled."
print "Copy neteria module to project directory before continuing."
if not os.path.exists("tuxemon/pytmx"):
print " Installing pytmx dependency..."
subprocess.call(["git", "clone", "https://github.com/bitcraft/PyTMX.git"])
os.rename("PyTMX/pytmx", "tuxemon/pytmx")
if not os.path.exists("tuxemon/six.py"):
# Download the SIX module.
print " Installing six dependency..."
headers = { 'User-Agent' : 'Mozilla/5.0' }
req = urllib2.Request(SIX_LINK, None, headers)
data = urllib2.urlopen(req).read()
# write the data
f = open(SIX_ARCHIVE, 'wb')
f.write(data)
f.close()
import tarfile
tar = tarfile.open(SIX_ARCHIVE)
tar.extractall()
tar.close()
os.rename("six-1.9.0/six.py", "tuxemon/six.py")
def set_default_config(file_name):
config = configparser.ConfigParser()
config.read(file_name)
config.set("display", "controller_overlay", "1")
# Writing our configuration file to 'example.cfg'
with open(file_name, 'wb') as configfile:
config.write(configfile)
if __name__ == "__main__":
if not os.path.exists("build"):
os.mkdir("build")
print "Checking dependencies..."
install_dependencies()
print "Checking for rapt..."
if not os.path.exists("build/rapt"):
download_rapt()
unzip_rapt()
os.unlink("build/" + RAPT_ARCHIVE)
print "Verifying rapt builder..."
modify_rapt()
if not os.path.exists("build/rapt/tuxemon"):
print " Creating symlink to project directory..."
os.symlink("../../tuxemon", "build/rapt/tuxemon")
# Check md5 hash instead of copying every time.
print "Copying icon and splash images..."
shutil.copyfile("tuxemon/resources/gfx/icon.png", "build/rapt/templates/pygame-icon.png")
#shutil.copyfile("tuxemon/resources/gfx/presplash.jpg", "build/rapt/templates/pygame-presplash.jpg")
# Set default config for Android devices.
set_default_config("tuxemon/tuxemon.cfg")
print "Executing build..."
os.chdir("build/rapt")
print "Checking for existing Android SDK..."
sdk = False
for item in os.listdir('.'):
if 'android-sdk-' in item:
sdk = True
if not sdk:
print " SDK not found."
sys.argv.append('installsdk')
execfile('android.py')
sys.argv.pop()
print "Starting build..."
sys.argv.append('build')
sys.argv.append('tuxemon')
sys.argv.append('debug')
#sys.argv.append('install')
execfile('android.py')