8000 Made build.py compatible with python3 · mmariani/python-for-android@5faaed7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5faaed7

Browse files
committed
Made build.py compatible with python3
1 parent ccc4ef4 commit 5faaed7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+10801
-11
lines changed

src/build.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
from os.path import dirname, join, isfile, realpath, relpath, split
44
from zipfile import ZipFile
55
import sys
6-
sys.path.insert(0, 'buildlib/jinja2.egg')
6+
7+
python_major_version = sys.version_info[0]
8+
9+
sys.path.insert(0, 'buildlib/jinja2-py{}.egg'.format(python_major_version))
710
sys.path.insert(0, 'buildlib')
811

912
from fnmatch import fnmatch
@@ -67,10 +70,14 @@ def render(template, dest, **kwargs):
6770

6871
template = environment.get_template(template)
6972
text = template.render(**kwargs)
73+
if python_major_version == 2:
74+
text = text.encode('utf-8')
75+
else:
76+
text = bytes(text, 'utf-8')
7077

71-
f = file(dest, 'wb')
72-
f.write(text.encode('utf-8'))
73-
f.close()
78+
with open(dest, 'wb') as fileh:
79+
fileh.write(text)
80+
fileh.close()
7481

7582

7683
def compile_dir(dfn):
@@ -183,7 +190,7 @@ def select(fn):
183190
tf = tarfile.open(tfn, 'w:gz')
184191
dirs = []
185192
for fn, afn in files:
186-
print '%s: %s' % (tfn, fn)
193+
print('%s: %s' % (tfn, fn))
187194
dn = dirname(afn)
188195
if dn not in dirs:
189196
# create every dirs first if not exist yet
@@ -219,7 +226,9 @@ def make_package(args):
219226

220227
args.numeric_version = str(version_code)
221228

222-
args.name = args.name.decode('utf-8')
229+
if python_major_version == 2:
230+
args.name = args.name.decode('utf-8')
231+
223232
if args.icon_name:
224233
args.icon_name = args.icon_name.decode('utf-8')
225234

@@ -304,8 +313,8 @@ def make_package(args):
304313
subprocess.call([ANDROID, 'update', 'project', '-p', '.', '-t',
305314
'android-{}'.format(android_api)])
306315
except (OSError, IOError):
307-
print 'An error occured while calling', ANDROID, 'update'
308-
print 'Your PATH must include android tools.'
316+
print('An error occured while calling', ANDROID, 'update')
317+
print('Your PATH must include android tools.')
309318
sys.exit(-1)
310319

311320
# Delete the old assets.
@@ -344,7 +353,7 @@ def make_package(args):
344353
if args.add_jar:
345354
for jarname in args.add_jar:
346355
if not os.path.exists(jarname):
347-
print 'Requested jar does not exist: {}'.format(jarname)
356+
print('Requested jar does not exist: {}'.format(jarname))
348357
sys.exit(-1)
349358
shutil.copy(jarname, 'libs')
350359

@@ -353,8 +362,8 @@ def make_package(args):
353362
for arg in args.command:
354363
subprocess.check_call([ANT, arg])
355364
except (OSError, IOError):
356-
print 'An error occured while calling', ANT
357-
print 'Did you install ant on your system ?'
365+
print('An error occured while calling', ANT)
366+
print('Did you install ant on your system ?')
358367
sys.exit(-1)
359368

360369
if __name__ == '__main__':

0 commit comments

Comments
 (0)
0