~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/export/dir_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:
19
19
 
20
20
 
21
21
import os
 
22
import StringIO
22
23
 
23
24
from bzrlib import errors, osutils
24
25
from bzrlib.export import _export_iter_entries
 
26
from bzrlib.filters import (
 
27
    ContentFilterContext,
 
28
    filtered_output_bytes,
 
29
    )
25
30
from bzrlib.trace import mutter
26
31
 
27
32
 
28
 
def dir_exporter(tree, dest, root, subdir):
 
33
def dir_exporter(tree, dest, root, subdir, filtered=False):
29
34
    """Export this tree to a new directory.
30
35
 
31
36
    `dest` should not exist, and will be created holding the
42
47
    for dp, ie in _export_iter_entries(tree, subdir):
43
48
        fullpath = osutils.pathjoin(dest, dp)
44
49
        if ie.kind == "file":
45
 
            fileobj = tree.get_file(ie.file_id)
 
50
            if filtered:
 
51
                chunks = tree.get_file_lines(ie.file_id)
 
52
                filters = tree._content_filter_stack(dp)
 
53
                context = ContentFilterContext(dp, tree, ie)
 
54
                contents = filtered_output_bytes(chunks, filters, context)
 
55
                content = ''.join(contents)
 
56
                fileobj = StringIO.StringIO(content)
 
57
            else:
 
58
                fileobj = tree.get_file(ie.file_id)
46
59
            osutils.pumpfile(fileobj, file(fullpath, 'wb'))
47
60
            if tree.is_executable(ie.file_id):
48
61
                os.chmod(fullpath, 0755)