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
25
def tar_exporter(tree, dest, root, compression=None):
26
"""Export this tree to a new tar file.
28
`dest` will be created holding the contents of this tree; if it
29
already exists, it will be clobbered, like with "tar -c".
33
compression = str(compression or '')
35
root = get_root_name(dest)
37
ball = tarfile.open(dest, 'w:' + compression)
38
except tarfile.CompressionError, e:
39
raise BzrError(str(e))
40
mutter('export version %r', tree)
42
for dp, ie in inv.iter_entries():
43
mutter(" export {%s} kind %s to %s", ie.file_id, ie.kind, dest)
44
item, fileobj = ie.get_tar_item(root, dp, now, tree)
45
ball.addfile(item, fileobj)
49
def tgz_exporter(tree, dest, root):
50
tar_exporter(tree, dest, root, compression='gz')
53
def tbz_exporter(tree, dest, root):
54
tar_exporter(tree, dest, root, compression='bz2')