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
from bzrlib import errors, osutils
25
from bzrlib.export import _export_iter_entries
26
from bzrlib.filters import (
28
filtered_output_bytes,
21
30
from bzrlib.trace import mutter
23
def dir_exporter(tree, dest, root):
33
def dir_exporter(tree, dest, root, subdir, filtered=False):
24
34
"""Export this tree to a new directory.
26
36
`dest` should not exist, and will be created holding the
32
42
:note: If the export fails, the destination directory will be
33
43
left in a half-assed state.
37
45
mutter('export version %r', tree)
39
entries = inv.iter_entries()
40
entries.next() # skip root
41
for dp, ie in entries:
42
# .bzrignore has no meaning outside of a working tree
44
if dp == ".bzrignore":
47
ie.put_on_disk(dest, dp, tree)
49
if e.errno == errno.EEXIST:
50
# check if directory empty
51
if os.listdir(dest) != []:
52
raise errors.BzrError("Can't export tree to non-empty directory.")
55
for dp, ie in _export_iter_entries(tree, subdir):
56
fullpath = osutils.pathjoin(dest, dp)
59
chunks = tree.get_file_lines(ie.file_id)
60
filters = tree._content_filter_stack(dp)
61
context = ContentFilterContext(dp, tree, ie)
62
contents = filtered_output_bytes(chunks, filters, context)
63
content = ''.join(contents)
64
fileobj = StringIO.StringIO(content)
66
fileobj = tree.get_file(ie.file_id)
67
osutils.pumpfile(fileobj, file(fullpath, 'wb'))
68
if tree.is_executable(ie.file_id):
69
os.chmod(fullpath, 0755)
70
elif ie.kind == "directory":
72
elif ie.kind == "symlink":
74
symlink_target = tree.get_symlink_target(ie.file_id)
75
os.symlink(symlink_target, fullpath)
77
raise errors.BzrError(
78
"Failed to create symlink %r -> %r, error: %s"
79
% (fullpath, symlink_target, e))
81
raise errors.BzrError("don't know how to export {%s} of kind %r" %
82
(ie.file_id, ie.kind))