360
360
def tbz_exporter(tree, dest, root):
361
361
tar_exporter(tree, dest, root, compression='bz2')
362
362
exporters['tbz2'] = tbz_exporter
365
def zip_exporter(tree, dest, root):
366
""" Export this tree to a new zip file.
368
`dest` will be created holding the contents of this tree; if it
369
already exists, it will be overwritten".
374
now = time.localtime()[:6]
375
mutter('export version %r', tree)
377
compression = zipfile.ZIP_DEFLATED
378
zipf = zipfile.ZipFile(dest, "w", compression)
383
for dp, ie in inv.iter_entries():
386
mutter(" export {%s} kind %s to %s", file_id, ie.kind, dest)
388
if ie.kind == "file":
389
zinfo = zipfile.ZipInfo(
390
filename=str(os.path.join(root, dp)),
392
zinfo.compress_type = compression
393
zipf.writestr(zinfo, tree.get_file_text(file_id))
394
elif ie.kind == "directory":
395
zinfo = zipfile.ZipInfo(
396
filename=str(os.path.join(root, dp)+os.sep),
398
zinfo.compress_type = compression
399
zipf.writestr(zinfo,'')
400
elif ie.kind == "symlink":
401
zinfo = zipfile.ZipInfo(
402
filename=str(os.path.join(root, dp+".lnk")),
404
zinfo.compress_type = compression
405
zipf.writestr(zinfo, ie.symlink_target)
409
except UnicodeEncodeError:
412
from bzrlib.errors import BzrError
413
raise BzrError("Can't export non-ascii filenames to zip")
414
#/def zip_exporter(tree, dest, root):
416
exporters["zip"] = zip_exporter