~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/export/zip_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:
44
44
_DIR_ATTR = stat.S_IFDIR | ZIP_DIRECTORY_BIT | DIR_PERMISSIONS
45
45
 
46
46
 
47
 
def zip_exporter(tree, dest, root, subdir=None, filtered=False, force_mtime=None):
 
47
def zip_exporter_generator(tree, dest, root, subdir=None, filtered=False, 
 
48
                 force_mtime=None, fileobj=None):
48
49
    """ Export this tree to a new zip file.
49
50
 
50
51
    `dest` will be created holding the contents of this tree; if it
52
53
    """
53
54
 
54
55
    compression = zipfile.ZIP_DEFLATED
55
 
    if dest == "-":
 
56
    if fileobj is not None:
 
57
        dest = fileobj
 
58
    elif dest == "-":
56
59
        dest = sys.stdout
57
60
    zipf = zipfile.ZipFile(dest, "w", compression)
58
61
    try:
100
103
                zinfo.compress_type = compression
101
104
                zinfo.external_attr = _FILE_ATTR
102
105
                zipf.writestr(zinfo, tree.get_symlink_target(file_id))
 
106
            
 
107
            yield
103
108
 
104
109
        zipf.close()
105
110
 
108
113
        os.remove(dest)
109
114
        from bzrlib.errors import BzrError
110
115
        raise BzrError("Can't export non-ascii filenames to zip")
 
116
    
 
117
def zip_exporter(tree, dest, root, subdir=None, filtered=False, 
 
118
                 force_mtime=None, fileobj=None):
 
119
    
 
120
    for _ in zip_exporter_generator(tree, dest, root, subdir, filtered,
 
121
                                    force_mtime, fileobj):
 
122
        pass