1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
1 |
# Copyright (C) 2005, 2006 Canonical Ltd
|
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 |
from bzrlib.trace import mutter |
|
22 |
import tarfile |
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
23 |
from bzrlib import errors, export |
1185.31.12
by John Arbash Meinel
Refactored the export code to make it easier to add new export formats. |
24 |
|
25 |
||
26 |
def tar_exporter(tree, dest, root, compression=None): |
|
27 |
"""Export this tree to a new tar file.
|
|
28 |
||
29 |
`dest` will be created holding the contents of this tree; if it
|
|
30 |
already exists, it will be clobbered, like with "tar -c".
|
|
31 |
"""
|
|
32 |
from time import time |
|
33 |
now = time() |
|
34 |
compression = str(compression or '') |
|
35 |
if root is None: |
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
36 |
root = export.get_root_name(dest) |
37 |
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. |
38 |
mutter('export version %r', tree) |
39 |
inv = tree.inventory |
|
1852.6.6
by Robert Collins
Finish updating iter_entries change to make all tests pass. |
40 |
entries = inv.iter_entries() |
41 |
entries.next() # skip root |
|
42 |
for dp, ie in entries: |
|
1185.61.3
by Jamie Wilkinson
convert tabs to 4-spaces |
43 |
# .bzrignore has no meaning outside of a working tree
|
44 |
# so do not export it
|
|
1185.61.2
by Jamie Wilkinson
exclude .bzrignore from exports |
45 |
if dp == ".bzrignore": |
1185.61.3
by Jamie Wilkinson
convert tabs to 4-spaces |
46 |
continue
|
47 |
||
1185.31.12
by John Arbash Meinel
Refactored the export code to make it easier to add new export formats. |
48 |
mutter(" export {%s} kind %s to %s", ie.file_id, ie.kind, dest) |
49 |
item, fileobj = ie.get_tar_item(root, dp, now, tree) |
|
50 |
ball.addfile(item, fileobj) |
|
51 |
ball.close() |
|
52 |
||
53 |
||
54 |
def tgz_exporter(tree, dest, root): |
|
55 |
tar_exporter(tree, dest, root, compression='gz') |
|
56 |
||
57 |
||
58 |
def tbz_exporter(tree, dest, root): |
|
59 |
tar_exporter(tree, dest, root, compression='bz2') |
|
60 |