3
3
from os .path import dirname , join , isfile , realpath , relpath , split
4
4
from zipfile import ZipFile
5
5
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 ))
7
10
sys .path .insert (0 , 'buildlib' )
8
11
9
12
from fnmatch import fnmatch
@@ -67,10 +70,14 @@ def render(template, dest, **kwargs):
67
70
68
71
template = environment .get_template (template )
69
72
text = template .render (** kwargs )
73
+ if python_major_version == 2 :
74
+ text = text .encode ('utf-8' )
75
+ else :
76
+ text = bytes (text , 'utf-8' )
70
77
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 ()
74
81
75
82
76
83
def compile_dir (dfn ):
@@ -183,7 +190,7 @@ def select(fn):
183
190
tf = tarfile .open (tfn , 'w:gz' )
184
191
dirs = []
185
192
for fn , afn in files :
186
- print '%s: %s' % (tfn , fn )
193
+ print ( '%s: %s' % (tfn , fn ) )
187
194
dn = dirname (afn )
188
195
if dn not in dirs :
189
196
# create every dirs first if not exist yet
@@ -219,7 +226,9 @@ def make_package(args):
219
226
220
227
args .numeric_version = str (version_code )
221
228
222
- args .name = args .name .decode ('utf-8' )
229
+ if python_major_version == 2 :
230
+ args .name = args .name .decode ('utf-8' )
231
+
223
232
if args .icon_name :
224
233
args .icon_name = args .icon_name .decode ('utf-8' )
225
234
@@ -304,8 +313,8 @@ def make_package(args):
304
313
subprocess .call ([ANDROID , 'update' , 'project' , '-p' , '.' , '-t' ,
305
314
'android-{}' .format (android_api )])
306
315
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.' )
309
318
sys .exit (- 1 )
310
319
311
320
# Delete the old assets.
@@ -344,7 +353,7 @@ def make_package(args):
344
353
if args .add_jar :
345
354
for jarname in args .add_jar :
346
355
if not os .path .exists (jarname ):
347
- print 'Requested jar does not exist: {}' .format (jarname )
356
+ print ( 'Requested jar does not exist: {}' .format (jarname ) )
348
357
sys .exit (- 1 )
349
358
shutil .copy (jarname , 'libs' )
350
359
@@ -353,8 +362,8 @@ def make_package(args):
353
362
for arg in args .command :
354
363
subprocess .check_call ([ANT , arg ])
355
364
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 ?' )
358
367
sys .exit (- 1 )
359
368
360
369
if __name__ == '__main__' :
0 commit comments