Fix creating zip files with directories.
This commit is contained in:
parent
8f922c5077
commit
5158c6e6b9
|
@ -16,6 +16,7 @@
|
||||||
"""Archive commands for the zipfile Python module."""
|
"""Archive commands for the zipfile Python module."""
|
||||||
from patoolib import util
|
from patoolib import util
|
||||||
import zipfile
|
import zipfile
|
||||||
|
import os
|
||||||
|
|
||||||
READ_SIZE_BYTES = 1024*1024
|
READ_SIZE_BYTES = 1024*1024
|
||||||
|
|
||||||
|
@ -59,7 +60,18 @@ def create_zip (archive, compression, cmd, *args, **kwargs):
|
||||||
zfile = zipfile.ZipFile(archive, 'w')
|
zfile = zipfile.ZipFile(archive, 'w')
|
||||||
try:
|
try:
|
||||||
for filename in args:
|
for filename in args:
|
||||||
|
if os.path.isdir(filename):
|
||||||
|
write_directory(zfile, filename)
|
||||||
|
else:
|
||||||
zfile.write(filename)
|
zfile.write(filename)
|
||||||
finally:
|
finally:
|
||||||
zfile.close()
|
zfile.close()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def write_directory (zfile, directory):
|
||||||
|
"""Write recursively all directories and filenames to zipfile instance."""
|
||||||
|
for dirpath, dirnames, filenames in os.walk(directory):
|
||||||
|
zfile.write(dirpath)
|
||||||
|
for filename in filenames:
|
||||||
|
zfile.write(os.path.join(dirpath, filename))
|
||||||
|
|
Loading…
Reference in New Issue