@@ -347,21 +347,53 @@ def generate_target_others(platform_name, arch, version):
347
347
348
348
################################
349
349
# Make packages
350
+
351
+ #https://gist.github.com/kgn/610907
352
+ def ZipDir (inputDir , outputZip ):
353
+ '''Zip up a directory and preserve symlinks and empty directories'''
354
+ zipOut = zipfile .ZipFile (outputZip , 'w' , compression = zipfile .ZIP_DEFLATED )
355
+
356
+ rootLen = len (os .path .dirname (inputDir ))
357
+ def _ArchiveDirectory (parentDirectory ):
358
+ contents = os .listdir (parentDirectory )
359
+ #store empty directories
360
+ if not contents :
361
+ #http://www.velocityreviews.com/forums/t318840-add-empty-directory-using-zipfile.html
362
+ archiveRoot = parentDirectory [rootLen :].replace ('\\ ' , '/' ).lstrip ('/' )
363
+ zipInfo = zipfile .ZipInfo (archiveRoot + '/' )
364
+ zipOut .writestr (zipInfo , '' )
365
+ for item in contents :
366
+ fullPath = os .path .join (parentDirectory , item )
367
+ if os .path .isdir (fullPath ) and not os .path .islink (fullPath ):
368
+ _ArchiveDirectory (fullPath )
369
+ else :
370
+ archiveRoot = fullPath [rootLen :].replace ('\\ ' , '/' ).lstrip ('/' )
371
+ if os .path .islink (fullPath ):
372
+ # http://www.mail-archive.com/python-list@python.org/msg34223.html
373
+ zipInfo = zipfile .ZipInfo (archiveRoot )
374
+ zipInfo .create_system = 3
375
+ # long type of hex val of '0xA1ED0000L',
376
+ # say, symlink attr magic...
377
+ zipInfo .external_attr = 2716663808L
378
+ zipOut .writestr (zipInfo , os .readlink (fullPath ))
379
+ else :
380
+ zipOut .write (fullPath , archiveRoot , zipfile .ZIP_DEFLATED )
381
+ _ArchiveDirectory (inputDir )
382
+
383
+ zipOut .close ()
384
+
350
385
def compress (from_dir , to_dir , fname , compress ):
351
386
from_dir = os .path .normpath (from_dir )
352
387
to_dir = os .path .normpath (to_dir )
353
388
_from = os .path .join (from_dir , fname )
354
389
_to = os .path .join (to_dir , fname )
355
390
if compress == 'zip' :
356
- z = zipfile .ZipFile (_to + '.zip' , 'w' , compression = zipfile .ZIP_DEFLATED )
357
- if os .path .isdir (_from ):
358
- for root , dirs , files in os .walk (_from ):
359
- for f in files :
360
- _path = os .path .join (root , f )
361
- z .write (_path , _path .replace (from_dir + os .sep , '' ))
391
+ if os .path .isdir (_from ):
392
+ ZipDir (_from , _to + '.zip' )
362
393
else :
394
+ z = zipfile .ZipFile (_to + '.zip' , 'w' , compression = zipfile .ZIP_DEFLATED )
363
395
z .write (_from , fname )
364
- z .close ()
396
+ z .close ()
365
397
elif compress == 'tar.gz' : # only for folders
366
398
if not os .path .isdir (_from ):
367
399
print 'Will not create tar.gz for a single file: ' + _from
@@ -424,13 +456,13 @@ def make_packages(targets):
424
456
src = os .path .join (binaries_location , f )
425
457
dest = os .path .join (folder , f )
426
458
if os .path .isdir (src ): # like nw.app
427
- shutil .copytree (src , dest )
459
+ shutil .copytree (src , dest , symlinks = True )
428
460
else :
429
461
shutil .copy (src , dest )
430
462
compress (dist_dir , dist_dir , t ['output' ], t ['compress' ])
431
463
# remove temp folders
432
464
if (t .has_key ('keep4test' )) :
433
- shutil .copytree (folder , nwfolder )
465
+ shutil .copytree (folder , nwfolder , symlinks = True )
434
466
435
467
shutil .rmtree (folder )
436
468
else :
0 commit comments