1
# Copyright (C) 2005, 2006, 2008 Canonical Ltd
1
# Copyright (C) 2005, 2006, 2008, 2009, 2010 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
13
13
# You should have received a copy of the GNU General Public License
14
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
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
"""Export a Tree to a non-versioned directory.
25
from bzrlib import errors, export, osutils
25
from bzrlib import export, osutils
26
26
from bzrlib.export import _export_iter_entries
27
from bzrlib.filters import (
29
filtered_output_bytes,
27
31
from bzrlib.trace import mutter
30
def tar_exporter(tree, dest, root, subdir, compression=None):
34
def tar_exporter(tree, dest, root, subdir, compression=None, filtered=False,
35
per_file_timestamps=False):
31
36
"""Export this tree to a new tar file.
33
38
`dest` will be created holding the contents of this tree; if it
47
52
for dp, ie in _export_iter_entries(tree, subdir):
48
53
filename = osutils.pathjoin(root, dp).encode('utf8')
49
54
item = tarfile.TarInfo(filename)
55
if per_file_timestamps:
56
item.mtime = tree.get_file_mtime(ie.file_id, dp)
51
59
if ie.kind == "file":
52
60
item.type = tarfile.REGTYPE
53
61
if tree.is_executable(ie.file_id):
57
item.size = ie.text_size
58
fileobj = tree.get_file(ie.file_id)
66
chunks = tree.get_file_lines(ie.file_id)
67
filters = tree._content_filter_stack(dp)
68
context = ContentFilterContext(dp, tree, ie)
69
contents = filtered_output_bytes(chunks, filters, context)
70
content = ''.join(contents)
71
item.size = len(content)
72
fileobj = StringIO.StringIO(content)
74
item.size = ie.text_size
75
fileobj = tree.get_file(ie.file_id)
59
76
elif ie.kind == "directory":
60
77
item.type = tarfile.DIRTYPE
78
def tgz_exporter(tree, dest, root, subdir):
79
tar_exporter(tree, dest, root, subdir, compression='gz')
82
def tbz_exporter(tree, dest, root, subdir):
83
tar_exporter(tree, dest, root, subdir, compression='bz2')
95
def tgz_exporter(tree, dest, root, subdir, filtered=False,
96
per_file_timestamps=False):
97
tar_exporter(tree, dest, root, subdir, compression='gz',
98
filtered=filtered, per_file_timestamps=per_file_timestamps)
101
def tbz_exporter(tree, dest, root, subdir, filtered=False,
102
per_file_timestamps=False):
103
tar_exporter(tree, dest, root, subdir, compression='bz2',
104
filtered=filtered, per_file_timestamps=per_file_timestamps)