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():
44
mutter(" export {%s} kind %s to %s", file_id, ie.kind, dest)
47
zinfo = zipfile.ZipInfo(
48
filename=str(os.path.join(root, dp)),
50
zinfo.compress_type = compression
51
zipf.writestr(zinfo, tree.get_file_text(file_id))
52
elif ie.kind == "directory":
53
zinfo = zipfile.ZipInfo(
54
filename=str(os.path.join(root, dp)+os.sep),
56
zinfo.compress_type = compression
57
zipf.writestr(zinfo,'')
58
elif ie.kind == "symlink":
59
zinfo = zipfile.ZipInfo(
60
filename=str(os.path.join(root, dp+".lnk")),
62
zinfo.compress_type = compression
63
zipf.writestr(zinfo, ie.symlink_target)
67
except UnicodeEncodeError:
70
from bzrlib.errors import BzrError
71
raise BzrError("Can't export non-ascii filenames to zip")