]> git.phdru.name Git - dotfiles.git/blobdiff - bin/zip.py
Refactor(bin/decode-URLs.py): Python3-only
[dotfiles.git] / bin / zip.py
index 35bf0e69f00da71c92c80ef55c09767c904e0120..bf55a08f7f01c004111a5e84a37525f10851141c 100755 (executable)
@@ -6,7 +6,7 @@
 
 import sys, os
 from getopt import getopt, GetoptError
-from zipfile import ZipFile, ZIP_DEFLATED
+from zipfile import ZipFile, ZipInfo, ZIP_DEFLATED
 from m_lib.defenc import default_encoding
 
 def usage():
@@ -21,13 +21,21 @@ if len(arguments) < 2:
     usage()
 
 def addToZip(zf, path):
-    if os.path.isfile(path):
+    if os.path.isfile(path) or os.path.islink(path):
         print(path)
         if isinstance(path, bytes):
             recoded_path = path.decode(default_encoding).encode('cp866')
         else:
             recoded_path = path
-        zf.write(path, recoded_path, ZIP_DEFLATED)
+        if os.path.islink(path):
+            # http://www.mail-archive.com/python-list@python.org/msg34223.html
+            zipInfo = ZipInfo(recoded_path)
+            zipInfo.create_system = 3
+            # say, symlink attr magic...
+            zipInfo.external_attr = 0xA1ED0000
+            zf.writestr(zipInfo, os.readlink(path))
+        else:
+            zf.write(path, recoded_path, ZIP_DEFLATED)
     elif os.path.isdir(path):
         for nm in os.listdir(path):
             addToZip(zf, os.path.join(path, nm))