@@ -319,13 +319,12 @@ def cleanup_and_exit(returncode):
319
319
global dmgvolumepaths
320
320
global dmg_was_mounted
321
321
global tmp_path
322
-
323
- if not dmg_was_mounted :
324
- detachpaths (dmgvolumepaths )
325
- if tmp_path is not None :
326
- shutil .rmtree (tmp_path )
327
- if tmp_scripts_path is not None :
328
- shutil .rmtree (tmp_scripts_path )
322
+
323
+ if args .clean :
324
+ if not dmg_was_mounted :
325
+ detachpaths (dmgvolumepaths )
326
+ if tmp_path is not None :
327
+ shutil .rmtree (tmp_path )
329
328
exit (returncode )
330
329
331
330
@@ -355,6 +354,10 @@ if __name__ == "__main__":
355
354
If this is a directory, then the
356
355
package will be created with the default filename {name}-{version}.pkg''' )
357
356
357
+ parser .add_argument ('--clean' , dest = 'clean' , action = 'store_true' , help = "clean up temp files (default)" )
358
+ parser .add_argument ('--no-clean' , dest = 'clean' , action = 'store_false' , help = " do NOT clean up temp files" )
359
+ parser .set_defaults (clean = True )
360
+
358
361
parser .add_argument ("-v" , "--verbosity" , action = "count" , default = 0 , help = "controls amount of logging output (max -vvv)" )
359
362
parser .add_argument ('--version' , help = 'prints the version' , action = 'version' , version = quickpkg_version )
360
363
@@ -388,6 +391,9 @@ if __name__ == "__main__":
388
391
tmp_path = None
389
392
dmg_was_mounted = False
390
393
tmp_scripts_path = None
394
+ tmp_path = tempfile .mkdtemp ()
395
+ payload_path = os .path .join (tmp_path , "payload" )
396
+ os .makedirs (payload_path )
391
397
392
398
# if item is a dmg, mount it and find useful contents
393
399
if item_extension == 'dmg' :
@@ -403,19 +409,17 @@ if __name__ == "__main__":
403
409
print "Found too many Applications! Can't decide!"
404
410
print foundapps
405
411
cleanup_and_exit (1 )
406
-
407
- app_path = foundapps [0 ]
408
-
412
+
409
413
# if item is zip, unzip to tmp location and find useful contents
410
414
if item_extension == 'zip' :
411
- tmp_path = tempfile . mkdtemp ( )
412
- unzip_cmd = ["/usr/bin/unzip" , "-d" , tmp_path , item_path ]
415
+ unarchive_path = os . path . join ( tmp_path , "unarchive" )
416
+ unzip_cmd = ["/usr/bin/unzip" , "-d" , unarchive_path , item_path ]
413
417
result = cmdexec (unzip_cmd )
414
418
if result ["return_code" ] != 0 :
415
419
print "An error occured while unzipping:"
416
420
print "%d, %s" % (result ["return_code" ], result ["stderr" ])
417
421
cleanup_and_exit (1 )
418
- foundapps = finditemswithextension (tmp_path , 'app' )
422
+ foundapps = finditemswithextension (unarchive_path , 'app' )
419
423
if len (foundapps ) == 0 :
420
424
print "Could not find an application!"
421
425
cleanup_and_exit (1 )
@@ -424,15 +428,35 @@ if __name__ == "__main__":
424
428
print foundapps
425
429
cleanup_and_exit (1 )
426
430
427
- app_path = foundapps [0 ]
431
+ logger ( "Found application: %s" % foundapps [0 ], 1 )
428
432
429
- logger ("Found application: %s" % app_path , 1 )
433
+ # copy found app to payload folder
434
+ app_name = os .path .basename (foundapps [0 ])
435
+ app_path = os .path .join (payload_path , app_name )
436
+ shutil .copytree (foundapps [0 ], app_path )
430
437
431
438
# extract version and other metadata
432
439
(app_name , app_identifier , app_version ) = appNameAndVersion (app_path )
433
440
434
441
logger ("Name: %s, ID: %s, Version: %s" % (app_name , app_identifier , app_version ), 1 )
435
442
443
+ # create the component plist
444
+ component_plist = os .path .join (tmp_path , app_identifier ) + ".plist"
445
+ analyzecmd = ["/usr/bin/pkgbuild" ,
446
+ "--analyze" ,
447
+ "--root" , payload_path ,
448
+ "--identifier" , app_identifier ,
449
+ "--version" , app_version ,
450
+ "--install-location" , "/Applications" ,
451
+ component_plist ]
452
+ result = cmdexec (analyzecmd )
453
+
454
+ logger (result ["stdout" ], 1 )
455
+ if result ["return_code" ] != 0 :
456
+ print "Error Code: %d " % result ["return_code" ]
457
+ print result ["stderr" ]
458
+ cleanup_and_exit (1 )
459
+
436
460
pkg_name = "{name}-{version}.pkg"
437
461
if args .output :
438
462
if os .path .isdir (args .output ):
@@ -449,7 +473,8 @@ if __name__ == "__main__":
449
473
450
474
# run pkgutil to build result
451
475
pkgcmd = ["/usr/bin/pkgbuild" ,
452
- "--component" , app_path ,
476
+ "--root" , payload_path ,
477
+ "--component-plist" , component_plist ,
453
478
"--identifier" , app_identifier ,
454
479
"--version" , app_version ,
455
480
"--install-location" , "/Applications" ,
@@ -460,7 +485,9 @@ if __name__ == "__main__":
460
485
cleanup_and_exit (1 )
461
486
462
487
if args .postinstall or args .preinstall :
463
- tmp_scripts_path = tempfile .mkdtemp ()
488
+ tmp_scripts_path = os .path .join (tmp_dir , "scripts" )
489
+ os .makedirs (tmp_scripts_path )
490
+
464
491
if args .scripts :
465
492
logger ("copying %s to tmp scripts folder %s" % (args .scripts , tmp_scripts_path ), 1 )
466
493
shutil .rmtree (tmp_scripts_path )
0 commit comments