~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/export/dir_exporter.py

  • Committer: Vincent Ladeuil
  • Date: 2011-06-07 07:23:36 UTC
  • mfrom: (5952.1.25 tarball-generator)
  • mto: This revision was merged to the branch mainline in revision 5961.
  • Revision ID: v.ladeuil+lp@free.fr-20110607072336-us9gklyqstjyq4mt
Exporting may now be done with a generator

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    )
28
28
 
29
29
 
30
 
def dir_exporter(tree, dest, root, subdir=None, filtered=False, force_mtime=None):
31
 
    """Export this tree to a new directory.
 
30
def dir_exporter_generator(tree, dest, root, subdir=None, filtered=False,
 
31
                           force_mtime=None, fileobj=None):
 
32
    """Return a generator that exports this tree to a new directory.
32
33
 
33
34
    `dest` should either not exist or should be empty. If it does not exist it
34
35
    will be created holding the contents of this tree.
 
36
    
 
37
    :param fileobj: Is not used in this exporter
35
38
 
36
39
    :note: If the export fails, the destination directory will be
37
40
           left in an incompletely exported state: export is not transactional.
42
45
        if e.errno == errno.EEXIST:
43
46
            # check if directory empty
44
47
            if os.listdir(dest) != []:
45
 
                raise errors.BzrError("Can't export tree to non-empty directory.")
 
48
                raise errors.BzrError(
 
49
                    "Can't export tree to non-empty directory.")
46
50
        else:
47
51
            raise
48
52
    # Iterate everything, building up the files we will want to export, and
69
73
        else:
70
74
            raise errors.BzrError("don't know how to export {%s} of kind %r" %
71
75
               (ie.file_id, ie.kind))
 
76
 
 
77
        yield
72
78
    # The data returned here can be in any order, but we've already created all
73
79
    # the directories
74
80
    flags = os.O_CREAT | os.O_TRUNC | os.O_WRONLY | getattr(os, 'O_BINARY', 0)
92
98
        else:
93
99
            mtime = tree.get_file_mtime(tree.path2id(relpath), relpath)
94
100
        os.utime(fullpath, (mtime, mtime))
 
101
 
 
102
        yield
 
103
        
 
104
def dir_exporter(tree, dest, root, subdir=None, filtered=False, 
 
105
                 force_mtime=None, fileobj=None):
 
106
 
 
107
    for _ in dir_exporter_generator(tree, dest, root, subdir, filtered,
 
108
                                    force_mtime, fileobj):
 
109
        pass