~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/export/tar_exporter.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
20
import os
 
21
import StringIO
21
22
import sys
22
23
import tarfile
23
24
import time
24
25
 
25
26
from bzrlib import errors, export, osutils
26
27
from bzrlib.export import _export_iter_entries
 
28
from bzrlib.filters import (
 
29
    ContentFilterContext,
 
30
    filtered_output_bytes,
 
31
    )
27
32
from bzrlib.trace import mutter
28
33
 
29
34
 
30
 
def tar_exporter(tree, dest, root, subdir, compression=None):
 
35
def tar_exporter(tree, dest, root, subdir, compression=None, filtered=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
54
59
                item.mode = 0755
55
60
            else:
56
61
                item.mode = 0644
57
 
            item.size = ie.text_size
58
 
            fileobj = tree.get_file(ie.file_id)
 
62
            if filtered:
 
63
                chunks = tree.get_file_lines(ie.file_id)
 
64
                filters = tree._content_filter_stack(dp)
 
65
                context = ContentFilterContext(dp, tree, ie)
 
66
                contents = filtered_output_bytes(chunks, filters, context)
 
67
                content = ''.join(contents)
 
68
                item.size = len(content)
 
69
                fileobj = StringIO.StringIO(content)
 
70
            else:
 
71
                item.size = ie.text_size
 
72
                fileobj = tree.get_file(ie.file_id)
59
73
        elif ie.kind == "directory":
60
74
            item.type = tarfile.DIRTYPE
61
75
            item.name += '/'
75
89
    ball.close()
76
90
 
77
91
 
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')
 
92
def tgz_exporter(tree, dest, root, subdir, filtered=False):
 
93
    tar_exporter(tree, dest, root, subdir, compression='gz', filtered=filtered)
 
94
 
 
95
 
 
96
def tbz_exporter(tree, dest, root, subdir, filtered=False):
 
97
    tar_exporter(tree, dest, root, subdir, compression='bz2', filtered=filtered)