/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3408.7.1 by Martin Pool
Support tarball export to stdout
1
# Copyright (C) 2005, 2006, 2008 Canonical Ltd
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
2
#
1185.31.12 by John Arbash Meinel
Refactored the export code to make it easier to add new export formats.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
7
#
1185.31.12 by John Arbash Meinel
Refactored the export code to make it easier to add new export formats.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
12
#
1185.31.12 by John Arbash Meinel
Refactored the export code to make it easier to add new export formats.
13
# You should have received a copy of the GNU General Public License
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
16
17
"""Export a Tree to a non-versioned directory.
18
"""
19
20
import os
21
import tarfile
3408.7.1 by Martin Pool
Support tarball export to stdout
22
import time
23
import sys
24
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
25
from bzrlib import errors, export
3408.7.1 by Martin Pool
Support tarball export to stdout
26
from bzrlib.trace import mutter
1185.31.12 by John Arbash Meinel
Refactored the export code to make it easier to add new export formats.
27
28
29
def tar_exporter(tree, dest, root, compression=None):
30
    """Export this tree to a new tar file.
31
32
    `dest` will be created holding the contents of this tree; if it
33
    already exists, it will be clobbered, like with "tar -c".
34
    """
3408.7.1 by Martin Pool
Support tarball export to stdout
35
    now = time.time()
1185.31.12 by John Arbash Meinel
Refactored the export code to make it easier to add new export formats.
36
    compression = str(compression or '')
3408.7.1 by Martin Pool
Support tarball export to stdout
37
    if dest == '-':
38
        # XXX: If no root is given, the output tarball will contain files
39
        # named '-/foo'; perhaps this is the most reasonable thing.
40
        ball = tarfile.open(None, 'w|' + compression, sys.stdout)
41
    else:
42
        if root is None:
43
            root = export.get_root_name(dest)
44
        ball = tarfile.open(dest, 'w:' + compression)
1185.31.12 by John Arbash Meinel
Refactored the export code to make it easier to add new export formats.
45
    mutter('export version %r', tree)
46
    inv = tree.inventory
1852.6.6 by Robert Collins
Finish updating iter_entries change to make all tests pass.
47
    entries = inv.iter_entries()
48
    entries.next() # skip root
49
    for dp, ie in entries:
1185.61.3 by Jamie Wilkinson
convert tabs to 4-spaces
50
        # .bzrignore has no meaning outside of a working tree
51
        # so do not export it
1185.61.2 by Jamie Wilkinson
exclude .bzrignore from exports
52
        if dp == ".bzrignore":
1185.61.3 by Jamie Wilkinson
convert tabs to 4-spaces
53
            continue
1185.31.12 by John Arbash Meinel
Refactored the export code to make it easier to add new export formats.
54
        item, fileobj = ie.get_tar_item(root, dp, now, tree)
55
        ball.addfile(item, fileobj)
56
    ball.close()
57
58
59
def tgz_exporter(tree, dest, root):
60
    tar_exporter(tree, dest, root, compression='gz')
61
62
63
def tbz_exporter(tree, dest, root):
64
    tar_exporter(tree, dest, root, compression='bz2')
65