~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-25 02:39:08 UTC
  • mto: (3585.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3586.
  • Revision ID: ian.clatworthy@canonical.com-20080725023908-4pare2wg4m75iong
deprecate export-related InventoryEntry methods and refactor export code accordingly

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
 
 
23
from bzrlib import errors, osutils
21
24
from bzrlib.trace import mutter
22
25
 
 
26
 
23
27
def dir_exporter(tree, dest, root):
24
28
    """Export this tree to a new directory.
25
29
 
32
36
    :note: If the export fails, the destination directory will be
33
37
           left in a half-assed state.
34
38
    """
35
 
    import os
36
39
    os.mkdir(dest)
37
40
    mutter('export version %r', tree)
38
41
    inv = tree.inventory
44
47
        if dp == ".bzrignore":
45
48
            continue
46
49
        
47
 
        ie.put_on_disk(dest, dp, tree)
48
 
 
 
50
        fullpath = osutils.pathjoin(dest, dp)
 
51
        if ie.kind == "file":
 
52
            fileobj = tree.get_file(ie.file_id)
 
53
            osutils.pumpfile(fileobj, file(fullpath, 'wb'))
 
54
            if tree.is_executable(ie.file_id):
 
55
                os.chmod(fullpath, 0755)
 
56
        elif ie.kind == "directory":
 
57
            os.mkdir(fullpath)
 
58
        elif ie.kind == "symlink":
 
59
            try:
 
60
                os.symlink(ie.symlink_target, fullpath)
 
61
            except OSError,e:
 
62
                raise errors.BzrError(
 
63
                    "Failed to create symlink %r -> %r, error: %s"
 
64
                    % (fullpath, self.symlink_target, e))
 
65
        else:
 
66
            raise errors.BzrError("don't know how to export {%s} of kind %r" %
 
67
               (ie.file_id, ie.kind))