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
17
17
"""Export a Tree to a non-versioned directory.
24
25
from bzrlib import (
28
from bzrlib.export import _export_iter_entries
29
from bzrlib.filters import (
31
filtered_output_bytes,
27
33
from bzrlib.trace import mutter
30
36
# Windows expects this bit to be set in the 'external_attr' section
31
37
# Or it won't consider the entry a directory
32
38
ZIP_DIRECTORY_BIT = (1 << 4)
39
FILE_PERMISSIONS = (0644 << 16)
34
_FILE_ATTR = stat.S_IFREG
41
_FILE_ATTR = stat.S_IFREG | FILE_PERMISSIONS
35
42
_DIR_ATTR = stat.S_IFDIR | ZIP_DIRECTORY_BIT
38
def zip_exporter(tree, dest, root):
45
def zip_exporter(tree, dest, root, subdir, filtered=False):
39
46
""" Export this tree to a new zip file.
41
48
`dest` will be created holding the contents of this tree; if it
42
49
already exists, it will be overwritten".
51
mutter('export version %r', tree)
46
53
now = time.localtime()[:6]
47
mutter('export version %r', tree)
49
55
compression = zipfile.ZIP_DEFLATED
50
56
zipf = zipfile.ZipFile(dest, "w", compression)
55
entries = inv.iter_entries()
56
entries.next() # skip root
57
for dp, ie in entries:
58
# .bzrignore has no meaning outside of a working tree
60
if dp == ".bzrignore":
59
for dp, ie in _export_iter_entries(tree, subdir):
63
60
file_id = ie.file_id
64
61
mutter(" export {%s} kind %s to %s", file_id, ie.kind, dest)
73
70
zinfo.compress_type = compression
74
71
zinfo.external_attr = _FILE_ATTR
75
zipf.writestr(zinfo, tree.get_file_text(file_id))
73
chunks = tree.get_file_lines(file_id)
74
filters = tree._content_filter_stack(dp)
75
context = ContentFilterContext(dp, tree, ie)
76
contents = filtered_output_bytes(chunks, filters, context)
77
content = ''.join(contents)
79
content = tree.get_file_text(file_id)
80
zipf.writestr(zinfo, content)
76
81
elif ie.kind == "directory":
77
82
# Directories must contain a trailing slash, to indicate
78
83
# to the zip routine that they are really directories and