/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/zip_exporter.py

  • Committer: Ian Clatworthy
  • Date: 2008-07-23 13:29:55 UTC
  • mto: (4171.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 4173.
  • Revision ID: ian.clatworthy@canonical.com-20080723132955-kzxal29bslx51u36
add --filters to export command

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
from bzrlib import (
25
25
    osutils,
26
26
    )
 
27
from bzrlib.filters import (
 
28
    ContentFilterContext,
 
29
    filtered_output_bytes,
 
30
    )
27
31
from bzrlib.trace import mutter
28
32
 
29
33
 
35
39
_DIR_ATTR = stat.S_IFDIR | ZIP_DIRECTORY_BIT
36
40
 
37
41
 
38
 
def zip_exporter(tree, dest, root):
 
42
def zip_exporter(tree, dest, root, filtered=False):
39
43
    """ Export this tree to a new zip file.
40
44
 
41
45
    `dest` will be created holding the contents of this tree; if it
72
76
                            date_time=now)
73
77
                zinfo.compress_type = compression
74
78
                zinfo.external_attr = _FILE_ATTR
75
 
                zipf.writestr(zinfo, tree.get_file_text(file_id))
 
79
                content = tree.get_file_text(file_id)
 
80
                if filtered:
 
81
                    chunks = tree.get_file_lines(file_id)
 
82
                    filters = tree._content_filter_stack(dp)
 
83
                    context = ContentFilterContext(dp)
 
84
                    contents = filtered_output_bytes(chunks, filters, context)
 
85
                    content = ''.join(contents)
 
86
                else:
 
87
                    content = tree.get_file_text(file_id)
 
88
                zipf.writestr(zinfo, content)
76
89
            elif ie.kind == "directory":
77
90
                # Directories must contain a trailing slash, to indicate
78
91
                # to the zip routine that they are really directories and
98
111
        os.remove(dest)
99
112
        from bzrlib.errors import BzrError
100
113
        raise BzrError("Can't export non-ascii filenames to zip")
101