~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/export/zip_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:
26
26
    osutils,
27
27
    )
28
28
from bzrlib.export import _export_iter_entries
 
29
from bzrlib.filters import (
 
30
    ContentFilterContext,
 
31
    filtered_output_bytes,
 
32
    )
29
33
from bzrlib.trace import mutter
30
34
 
31
35
 
37
41
_DIR_ATTR = stat.S_IFDIR | ZIP_DIRECTORY_BIT
38
42
 
39
43
 
40
 
def zip_exporter(tree, dest, root, subdir):
 
44
def zip_exporter(tree, dest, root, subdir, filtered=False):
41
45
    """ Export this tree to a new zip file.
42
46
 
43
47
    `dest` will be created holding the contents of this tree; if it
64
68
                            date_time=now)
65
69
                zinfo.compress_type = compression
66
70
                zinfo.external_attr = _FILE_ATTR
67
 
                zipf.writestr(zinfo, tree.get_file_text(file_id))
 
71
                if filtered:
 
72
                    chunks = tree.get_file_lines(file_id)
 
73
                    filters = tree._content_filter_stack(dp)
 
74
                    context = ContentFilterContext(dp, tree, ie)
 
75
                    contents = filtered_output_bytes(chunks, filters, context)
 
76
                    content = ''.join(contents)
 
77
                else:
 
78
                    content = tree.get_file_text(file_id)
 
79
                zipf.writestr(zinfo, content)
68
80
            elif ie.kind == "directory":
69
81
                # Directories must contain a trailing slash, to indicate
70
82
                # to the zip routine that they are really directories and
90
102
        os.remove(dest)
91
103
        from bzrlib.errors import BzrError
92
104
        raise BzrError("Can't export non-ascii filenames to zip")
93