/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/export/tar_exporter.py

  • Committer: Andrew Bennetts
  • Date: 2010-04-13 04:33:55 UTC
  • mfrom: (5147 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5149.
  • Revision ID: andrew.bennetts@canonical.com-20100413043355-lg3id0uwtju0k3zs
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2008 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2008, 2009, 2010 Canonical Ltd
2
2
#
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
12
12
#
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
16
16
 
17
17
"""Export a Tree to a non-versioned directory.
18
18
"""
19
19
 
20
 
import os
 
20
import StringIO
21
21
import sys
22
22
import tarfile
23
23
import time
24
24
 
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 (
 
28
    ContentFilterContext,
 
29
    filtered_output_bytes,
 
30
    )
27
31
from bzrlib.trace import mutter
28
32
 
29
33
 
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.
32
37
 
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)
50
 
        item.mtime = now
 
55
        if per_file_timestamps:
 
56
            item.mtime = tree.get_file_mtime(ie.file_id, dp)
 
57
        else:
 
58
            item.mtime = now
51
59
        if ie.kind == "file":
52
60
            item.type = tarfile.REGTYPE
53
61
            if tree.is_executable(ie.file_id):
54
62
                item.mode = 0755
55
63
            else:
56
64
                item.mode = 0644
57
 
            item.size = ie.text_size
58
 
            fileobj = tree.get_file(ie.file_id)
 
65
            if filtered:
 
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)
 
73
            else:
 
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
61
78
            item.name += '/'
75
92
    ball.close()
76
93
 
77
94
 
78
 
def tgz_exporter(tree, dest, root, subdir):
79
 
    tar_exporter(tree, dest, root, subdir, compression='gz')
80
 
 
81
 
 
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)
 
99
 
 
100
 
 
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)