37
38
# Or it won't consider the entry a directory
38
39
ZIP_DIRECTORY_BIT = (1 << 4)
39
40
FILE_PERMISSIONS = (0644 << 16)
41
DIR_PERMISSIONS = (0755 << 16)
41
43
_FILE_ATTR = stat.S_IFREG | FILE_PERMISSIONS
42
_DIR_ATTR = stat.S_IFDIR | ZIP_DIRECTORY_BIT
45
def zip_exporter(tree, dest, root, subdir, filtered=False,
46
per_file_timestamps=False):
44
_DIR_ATTR = stat.S_IFDIR | ZIP_DIRECTORY_BIT | DIR_PERMISSIONS
47
def zip_exporter(tree, dest, root, subdir=None, filtered=False, force_mtime=None):
47
48
""" Export this tree to a new zip file.
49
50
`dest` will be created holding the contents of this tree; if it
50
51
already exists, it will be overwritten".
52
mutter('export version %r', tree)
54
now = time.localtime()[:6]
56
54
compression = zipfile.ZIP_DEFLATED
57
57
zipf = zipfile.ZipFile(dest, "w", compression)
60
59
for dp, ie in _export_iter_entries(tree, subdir):
61
60
file_id = ie.file_id
64
63
# zipfile.ZipFile switches all paths to forward
65
64
# slashes anyway, so just stick with that.
66
if per_file_timestamps:
65
if force_mtime is not None:
67
68
mtime = tree.get_file_mtime(ie.file_id, dp)
69
date_time = time.localtime(mtime)[:6]
70
70
filename = osutils.pathjoin(root, dp).encode('utf8')
71
71
if ie.kind == "file":
72
72
zinfo = zipfile.ZipInfo(
75
75
zinfo.compress_type = compression
76
76
zinfo.external_attr = _FILE_ATTR
89
89
# not just empty files.
90
90
zinfo = zipfile.ZipInfo(
91
91
filename=filename + '/',
93
93
zinfo.compress_type = compression
94
94
zinfo.external_attr = _DIR_ATTR
95
95
zipf.writestr(zinfo,'')
96
96
elif ie.kind == "symlink":
97
97
zinfo = zipfile.ZipInfo(
98
98
filename=(filename + '.lnk'),
100
100
zinfo.compress_type = compression
101
101
zinfo.external_attr = _FILE_ATTR
102
102
zipf.writestr(zinfo, ie.symlink_target)