~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/export/dir_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:
17
17
"""Export a Tree to a non-versioned directory.
18
18
"""
19
19
 
 
20
 
20
21
import os
 
22
import StringIO
 
23
 
 
24
from bzrlib import errors, osutils
 
25
from bzrlib.filters import (
 
26
    ContentFilterContext,
 
27
    filtered_output_bytes,
 
28
    )
21
29
from bzrlib.trace import mutter
22
30
 
23
 
def dir_exporter(tree, dest, root):
 
31
 
 
32
def dir_exporter(tree, dest, root, filtered=False):
24
33
    """Export this tree to a new directory.
25
34
 
26
35
    `dest` should not exist, and will be created holding the
32
41
    :note: If the export fails, the destination directory will be
33
42
           left in a half-assed state.
34
43
    """
35
 
    import os
36
44
    os.mkdir(dest)
37
45
    mutter('export version %r', tree)
38
46
    inv = tree.inventory
44
52
        if dp == ".bzrignore":
45
53
            continue
46
54
        
47
 
        ie.put_on_disk(dest, dp, tree)
48
 
 
 
55
        fullpath = osutils.pathjoin(dest, dp)
 
56
        if ie.kind == "file":
 
57
            if filtered:
 
58
                chunks = tree.get_file_lines(ie.file_id)
 
59
                filters = tree._content_filter_stack(dp)
 
60
                context = ContentFilterContext(dp)
 
61
                contents = filtered_output_bytes(chunks, filters, context)
 
62
                content = ''.join(contents)
 
63
                fileobj = StringIO.StringIO(content)
 
64
            else:
 
65
                fileobj = tree.get_file(ie.file_id)
 
66
            osutils.pumpfile(fileobj, file(fullpath, 'wb'))
 
67
            if tree.is_executable(ie.file_id):
 
68
                os.chmod(fullpath, 0755)
 
69
        elif ie.kind == "directory":
 
70
            os.mkdir(fullpath)
 
71
        elif ie.kind == "symlink":
 
72
            try:
 
73
                os.symlink(ie.symlink_target, fullpath)
 
74
            except OSError,e:
 
75
                raise errors.BzrError(
 
76
                    "Failed to create symlink %r -> %r, error: %s"
 
77
                    % (fullpath, self.symlink_target, e))
 
78
        else:
 
79
            raise errors.BzrError("don't know how to export {%s} of kind %r" %
 
80
               (ie.file_id, ie.kind))