1185.31.12
by John Arbash Meinel
Refactored the export code to make it easier to add new export formats. |
1 |
# Copyright (C) 2005 Canonical Ltd
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
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.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
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.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
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
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
1185.31.12
by John Arbash Meinel
Refactored the export code to make it easier to add new export formats. |
16 |
|
17 |
"""Export a Tree to a non-versioned directory.
|
|
18 |
"""
|
|
19 |
||
3368.2.32
by Ian Clatworthy
add --filters to export command |
20 |
|
1185.31.12
by John Arbash Meinel
Refactored the export code to make it easier to add new export formats. |
21 |
import os |
3368.2.32
by Ian Clatworthy
add --filters to export command |
22 |
import StringIO |
23 |
||
24 |
from bzrlib import errors, osutils |
|
3613.2.2
by Robert Collins
Refactor exporters to remove obvious duplication to a helper function. |
25 |
from bzrlib.export import _export_iter_entries |
3368.2.32
by Ian Clatworthy
add --filters to export command |
26 |
from bzrlib.filters import ( |
27 |
ContentFilterContext, |
|
28 |
filtered_output_bytes, |
|
29 |
)
|
|
1185.31.12
by John Arbash Meinel
Refactored the export code to make it easier to add new export formats. |
30 |
from bzrlib.trace import mutter |
31 |
||
3368.2.32
by Ian Clatworthy
add --filters to export command |
32 |
|
3368.2.41
by Ian Clatworthy
1st cut merge of bzr.dev r3907 |
33 |
def dir_exporter(tree, dest, root, subdir, filtered=False): |
1185.31.12
by John Arbash Meinel
Refactored the export code to make it easier to add new export formats. |
34 |
"""Export this tree to a new directory.
|
35 |
||
36 |
`dest` should not exist, and will be created holding the
|
|
37 |
contents of this tree.
|
|
38 |
||
39 |
TODO: To handle subdirectories we need to create the
|
|
40 |
directories first.
|
|
41 |
||
42 |
:note: If the export fails, the destination directory will be
|
|
43 |
left in a half-assed state.
|
|
44 |
"""
|
|
3613.2.2
by Robert Collins
Refactor exporters to remove obvious duplication to a helper function. |
45 |
mutter('export version %r', tree) |
1185.31.12
by John Arbash Meinel
Refactored the export code to make it easier to add new export formats. |
46 |
os.mkdir(dest) |
3613.2.2
by Robert Collins
Refactor exporters to remove obvious duplication to a helper function. |
47 |
for dp, ie in _export_iter_entries(tree, subdir): |
3368.2.32
by Ian Clatworthy
add --filters to export command |
48 |
fullpath = osutils.pathjoin(dest, dp) |
49 |
if ie.kind == "file": |
|
50 |
if filtered: |
|
51 |
chunks = tree.get_file_lines(ie.file_id) |
|
52 |
filters = tree._content_filter_stack(dp) |
|
3368.2.33
by Ian Clatworthy
expand filter context to support interesting stuff |
53 |
context = ContentFilterContext(dp, tree, ie) |
3368.2.32
by Ian Clatworthy
add --filters to export command |
54 |
contents = filtered_output_bytes(chunks, filters, context) |
55 |
content = ''.join(contents) |
|
56 |
fileobj = StringIO.StringIO(content) |
|
57 |
else: |
|
58 |
fileobj = tree.get_file(ie.file_id) |
|
59 |
osutils.pumpfile(fileobj, file(fullpath, 'wb')) |
|
60 |
if tree.is_executable(ie.file_id): |
|
61 |
os.chmod(fullpath, 0755) |
|
62 |
elif ie.kind == "directory": |
|
63 |
os.mkdir(fullpath) |
|
64 |
elif ie.kind == "symlink": |
|
65 |
try: |
|
66 |
os.symlink(ie.symlink_target, fullpath) |
|
67 |
except OSError,e: |
|
68 |
raise errors.BzrError( |
|
69 |
"Failed to create symlink %r -> %r, error: %s" |
|
70 |
% (fullpath, self.symlink_target, e)) |
|
71 |
else: |
|
72 |
raise errors.BzrError("don't know how to export {%s} of kind %r" % |
|
73 |
(ie.file_id, ie.kind)) |