1
# Copyright (C) 2005 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Export a Tree to a non-versioned directory.
21
from bzrlib.trace import mutter
24
def zip_exporter(tree, dest, root):
25
""" Export this tree to a new zip file.
27
`dest` will be created holding the contents of this tree; if it
28
already exists, it will be overwritten".
32
now = time.localtime()[:6]
33
mutter('export version %r', tree)
35
compression = zipfile.ZIP_DEFLATED
36
zipf = zipfile.ZipFile(dest, "w", compression)
41
for dp, ie in inv.iter_entries():
42
# .bzrignore has no meaning outside of a working tree
44
if dp == ".bzrignore":
48
mutter(" export {%s} kind %s to %s", file_id, ie.kind, dest)
51
zinfo = zipfile.ZipInfo(
52
filename=str(os.path.join(root, dp)),
54
zinfo.compress_type = compression
55
zipf.writestr(zinfo, tree.get_file_text(file_id))
56
elif ie.kind == "directory":
57
zinfo = zipfile.ZipInfo(
58
filename=str(os.path.join(root, dp)+os.sep),
60
zinfo.compress_type = compression
61
zipf.writestr(zinfo,'')
62
elif ie.kind == "symlink":
63
zinfo = zipfile.ZipInfo(
64
filename=str(os.path.join(root, dp+".lnk")),
66
zinfo.compress_type = compression
67
zipf.writestr(zinfo, ie.symlink_target)
71
except UnicodeEncodeError:
74
from bzrlib.errors import BzrError
75
raise BzrError("Can't export non-ascii filenames to zip")