~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/export/tar_exporter.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-03-20 05:08:48 UTC
  • mfrom: (4171.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090320050848-c1wdgzf5kkfdt1ys
Content filters (Ian Clatworthy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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)