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' , format = tarfile .USTAR_FORMAT )
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
@@ -301,8 +310,8 @@ def make_package(args):
301
310
subprocess .call ([ANDROID , 'update' , 'project' , '-p' , '.' , '-t' ,
302
311
'android-{}' .format (args .sdk_version )])
303
312
except (OSError , IOError ):
304
- print 'An error occured while calling' , ANDROID , 'update'
305
- print 'Your PATH must include android tools.'
313
+ print ( 'An error occured while calling' , ANDROID , 'update' )
314
+ print ( 'Your PATH must include android tools.' )
306
315
sys .exit (- 1 )
307
316
308
317
# Delete the old assets.
@@ -341,7 +350,7 @@ def make_package(args):
341
350
if args .add_jar :
342
351
for jarname in args .add_jar :
343
352
if not os .path .exists (jarname ):
344
- print 'Requested jar does not exist: {}' .format (jarname )
353
+ print ( 'Requested jar does not exist: {}' .format (jarname ) )
345
354
sys .exit (- 1 )
346
355
shutil .copy (jarname , 'libs' )
347
356
@@ -350,8 +359,8 @@ def make_package(args):
350
359
for arg in args .command :
351
360
subprocess .check_call ([ANT , arg ])
352
361
except (OSError , IOError ):
353
- print 'An error occured while calling' , ANT
354
- print 'Did you install ant on your system ?'
362
+ print ( 'An error occured while calling' , ANT )
363
+ print ( 'Did you install ant on your system ?' )
355
364
sys .exit (- 1 )
356
365
357
366
if __name__ == '__main__' :
0 commit comments