/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/export/zip_exporter.py

  • Committer: Martin von Gagern
  • Date: 2010-04-20 08:47:38 UTC
  • mfrom: (5167 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5195.
  • Revision ID: martin.vgagern@gmx.net-20100420084738-ygymnqmdllzrhpfn
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2008, 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Export a Tree to a non-versioned directory.
18
18
"""
26
26
    osutils,
27
27
    )
28
28
from bzrlib.export import _export_iter_entries
 
29
from bzrlib.filters import (
 
30
    ContentFilterContext,
 
31
    filtered_output_bytes,
 
32
    )
29
33
from bzrlib.trace import mutter
30
34
 
31
35
 
32
36
# Windows expects this bit to be set in the 'external_attr' section
33
37
# Or it won't consider the entry a directory
34
38
ZIP_DIRECTORY_BIT = (1 << 4)
 
39
FILE_PERMISSIONS = (0644 << 16)
35
40
 
36
 
_FILE_ATTR = stat.S_IFREG
 
41
_FILE_ATTR = stat.S_IFREG | FILE_PERMISSIONS
37
42
_DIR_ATTR = stat.S_IFDIR | ZIP_DIRECTORY_BIT
38
43
 
39
44
 
40
 
def zip_exporter(tree, dest, root, subdir):
 
45
def zip_exporter(tree, dest, root, subdir, filtered=False,
 
46
                 per_file_timestamps=False):
41
47
    """ Export this tree to a new zip file.
42
48
 
43
49
    `dest` will be created holding the contents of this tree; if it
57
63
 
58
64
            # zipfile.ZipFile switches all paths to forward
59
65
            # slashes anyway, so just stick with that.
 
66
            if per_file_timestamps:
 
67
                mtime = tree.get_file_mtime(ie.file_id, dp)
 
68
            else:
 
69
                mtime = now
60
70
            filename = osutils.pathjoin(root, dp).encode('utf8')
61
71
            if ie.kind == "file":
62
72
                zinfo = zipfile.ZipInfo(
63
73
                            filename=filename,
64
 
                            date_time=now)
 
74
                            date_time=mtime)
65
75
                zinfo.compress_type = compression
66
76
                zinfo.external_attr = _FILE_ATTR
67
 
                zipf.writestr(zinfo, tree.get_file_text(file_id))
 
77
                if filtered:
 
78
                    chunks = tree.get_file_lines(file_id)
 
79
                    filters = tree._content_filter_stack(dp)
 
80
                    context = ContentFilterContext(dp, tree, ie)
 
81
                    contents = filtered_output_bytes(chunks, filters, context)
 
82
                    content = ''.join(contents)
 
83
                else:
 
84
                    content = tree.get_file_text(file_id)
 
85
                zipf.writestr(zinfo, content)
68
86
            elif ie.kind == "directory":
69
87
                # Directories must contain a trailing slash, to indicate
70
88
                # to the zip routine that they are really directories and
71
89
                # not just empty files.
72
90
                zinfo = zipfile.ZipInfo(
73
91
                            filename=filename + '/',
74
 
                            date_time=now)
 
92
                            date_time=mtime)
75
93
                zinfo.compress_type = compression
76
94
                zinfo.external_attr = _DIR_ATTR
77
95
                zipf.writestr(zinfo,'')
78
96
            elif ie.kind == "symlink":
79
97
                zinfo = zipfile.ZipInfo(
80
98
                            filename=(filename + '.lnk'),
81
 
                            date_time=now)
 
99
                            date_time=mtime)
82
100
                zinfo.compress_type = compression
83
101
                zinfo.external_attr = _FILE_ATTR
84
102
                zipf.writestr(zinfo, ie.symlink_target)
90
108
        os.remove(dest)
91
109
        from bzrlib.errors import BzrError
92
110
        raise BzrError("Can't export non-ascii filenames to zip")
93