@@ -232,7 +232,8 @@ def main():
232
232
from_emcc = True
233
233
leading = ''
234
234
elif arg .startswith ('--plugin' ):
235
- plugin = open (arg .split ('=' , 1 )[1 ], 'r' ).read ()
235
+ with open (arg .split ('=' , 1 )[1 ]) as f :
236
+ plugin = f .read ()
236
237
eval (plugin ) # should append itself to plugins
237
238
leading = ''
238
239
elif leading == 'preload' or leading == 'embed' :
@@ -391,17 +392,18 @@ def was_seen(name):
391
392
if has_preloaded :
392
393
# Bundle all datafiles into one archive. Avoids doing lots of simultaneous
393
394
# XHRs which has overhead.
394
- data = open (data_target , 'wb' )
395
395
start = 0
396
- for file_ in data_files :
397
- file_ ['data_start' ] = start
398
- curr = open (file_ ['srcpath' ], 'rb' ).read ()
399
- file_ ['data_end' ] = start + len (curr )
400
- if AV_WORKAROUND :
401
- curr += '\x00 '
402
- start += len (curr )
403
- data .write (curr )
404
- data .close ()
396
+ with open (data_target , 'wb' ) as data :
397
+ for file_ in data_files :
398
+ file_ ['data_start' ] = start
399
+ with open (file_ ['srcpath' ], 'rb' ) as f :
400
+ curr = f .read ()
401
+ file_ ['data_end' ] = start + len (curr )
402
+ if AV_WORKAROUND :
403
+ curr += '\x00 '
404
+ start += len (curr )
405
+ data .write (curr )
406
+
405
407
# TODO: sha256sum on data_target
406
408
if start > 256 * 1024 * 1024 :
407
409
print ('warning: file packager is creating an asset bundle of %d MB. '
@@ -913,20 +915,17 @@ def was_seen(name):
913
915
# differs from the current generated one, otherwise leave the file
914
916
# untouched preserving its old timestamp
915
917
if os .path .isfile (jsoutput ):
916
- f = open (jsoutput , 'r+' )
917
- old = f .read ()
918
+ with open (jsoutput ) as f :
919
+ old = f .read ()
918
920
if old != ret :
919
- f .seek (0 )
920
- f .write (ret )
921
- f .truncate ()
921
+ with open (jsoutput , 'w' ) as f :
922
+ f .write (ret )
922
923
else :
923
- f = open (jsoutput , 'w' )
924
- f .write (ret )
925
- f .close ()
924
+ with open (jsoutput , 'w' ) as f :
925
+ f .write (ret )
926
926
if separate_metadata :
927
- f = open (jsoutput + '.metadata' , 'w' )
928
- json .dump (metadata , f , separators = (',' , ':' ))
929
- f .close ()
927
+ with open (jsoutput + '.metadata' , 'w' ) as f :
928
+ json .dump (metadata , f , separators = (',' , ':' ))
930
929
931
930
return 0
932
931
0 commit comments