60
61
When requesting a specific type of export, load the respective path.
62
def _loader(tree, dest, root, subdir, filtered, force_mtime):
63
def _loader(tree, dest, root, subdir, force_mtime, fileobj):
63
64
func = pyutils.get_named_object(module, funcname)
64
return func(tree, dest, root, subdir, filtered=filtered,
65
force_mtime=force_mtime)
65
return func(tree, dest, root, subdir, force_mtime=force_mtime,
66
68
register_exporter(scheme, extensions, _loader)
69
def export(tree, dest, format=None, root=None, subdir=None, filtered=False,
70
per_file_timestamps=False):
71
"""Export the given Tree to the specific destination.
71
def get_export_generator(tree, dest=None, format=None, root=None, subdir=None,
72
filtered=False, per_file_timestamps=False,
74
"""Returns a generator that exports the given tree.
76
The generator is expected to yield None while exporting the tree while the
77
actual export is written to ``fileobj``.
73
79
:param tree: A Tree (such as RevisionTree) to export
74
:param dest: The destination where the files,etc should be put
81
:param dest: The destination where the files, etc should be put
75
83
:param format: The format (dir, zip, etc), if None, it will check the
76
extension on dest, looking for a match
77
:param root: The root location inside the format.
78
It is common practise to have zipfiles and tarballs
79
extract into a subdirectory, rather than into the
80
current working directory.
81
If root is None, the default root will be
82
selected as the destination without its
84
extension on dest, looking for a match
86
:param root: The root location inside the format. It is common practise to
87
have zipfiles and tarballs extract into a subdirectory, rather than
88
into the current working directory. If root is None, the default root
89
will be selected as the destination without its extension.
84
91
:param subdir: A starting directory within the tree. None means to export
85
92
the entire tree, and anything else should specify the relative path to
86
93
a directory to start exporting from.
87
:param filtered: If True, content filtering is applied to the
89
:param per_file_timestamps: Whether to use the timestamp stored in the
90
tree rather than now(). This will do a revision lookup
91
for every file so will be significantly slower.
95
:param filtered: If True, content filtering is applied to the exported
96
files. Deprecated in favour of passing a ContentFilterTree
99
:param per_file_timestamps: Whether to use the timestamp stored in the tree
100
rather than now(). This will do a revision lookup for every file so
101
will be significantly slower.
103
:param fileobj: Optional file object to use
93
105
global _exporters, _exporter_extensions
107
if format is None and dest is not None:
96
108
for ext in _exporter_extensions:
97
109
if dest.endswith(ext):
98
110
format = _exporter_extensions[ext]
114
126
trace.mutter('export version %r', tree)
129
from bzrlib.filter_tree import ContentFilterTree
131
"passing filtered=True to export is deprecated in bzr 2.4",
133
tree = ContentFilterTree(tree, tree._content_filter_stack)
134
# We don't want things re-filtered by the specific exporter.
118
return _exporters[format](tree, dest, root, subdir, filtered=filtered,
119
force_mtime=force_mtime)
139
for _ in _exporters[format](
140
tree, dest, root, subdir,
141
force_mtime=force_mtime, fileobj=fileobj):
147
def export(tree, dest, format=None, root=None, subdir=None, filtered=False,
148
per_file_timestamps=False, fileobj=None):
149
"""Export the given Tree to the specific destination.
151
:param tree: A Tree (such as RevisionTree) to export
152
:param dest: The destination where the files,etc should be put
153
:param format: The format (dir, zip, etc), if None, it will check the
154
extension on dest, looking for a match
155
:param root: The root location inside the format.
156
It is common practise to have zipfiles and tarballs
157
extract into a subdirectory, rather than into the
158
current working directory.
159
If root is None, the default root will be
160
selected as the destination without its
162
:param subdir: A starting directory within the tree. None means to export
163
the entire tree, and anything else should specify the relative path to
164
a directory to start exporting from.
165
:param filtered: If True, content filtering is applied to the
166
files exported. Deprecated in favor of passing an ContentFilterTree.
167
:param per_file_timestamps: Whether to use the timestamp stored in the
168
tree rather than now(). This will do a revision lookup
169
for every file so will be significantly slower.
170
:param fileobj: Optional file object to use
172
for _ in get_export_generator(tree, dest, format, root, subdir, filtered,
173
per_file_timestamps, fileobj):
124
177
def get_root_name(dest):
125
178
"""Get just the root name for an export.
167
220
final_path = path
168
221
if not tree.has_filename(path):
170
224
yield final_path, entry
173
register_lazy_exporter(None, [], 'bzrlib.export.dir_exporter', 'dir_exporter')
174
register_lazy_exporter('dir', [], 'bzrlib.export.dir_exporter', 'dir_exporter')
175
register_lazy_exporter('tar', ['.tar'], 'bzrlib.export.tar_exporter', 'plain_tar_exporter')
176
register_lazy_exporter('tgz', ['.tar.gz', '.tgz'], 'bzrlib.export.tar_exporter', 'tgz_exporter')
177
register_lazy_exporter('tbz2', ['.tar.bz2', '.tbz2'], 'bzrlib.export.tar_exporter', 'tbz_exporter')
178
register_lazy_exporter('tlzma', ['.tar.lzma'], 'bzrlib.export.tar_exporter', 'tar_lzma_exporter')
179
register_lazy_exporter('txz', ['.tar.xz'], 'bzrlib.export.tar_exporter', 'tar_xz_exporter')
180
register_lazy_exporter('zip', ['.zip'], 'bzrlib.export.zip_exporter', 'zip_exporter')
227
register_lazy_exporter(None, [], 'bzrlib.export.dir_exporter',
228
'dir_exporter_generator')
229
register_lazy_exporter('dir', [], 'bzrlib.export.dir_exporter',
230
'dir_exporter_generator')
231
register_lazy_exporter('tar', ['.tar'], 'bzrlib.export.tar_exporter',
232
'plain_tar_exporter_generator')
233
register_lazy_exporter('tgz', ['.tar.gz', '.tgz'],
234
'bzrlib.export.tar_exporter',
235
'tgz_exporter_generator')
236
register_lazy_exporter('tbz2', ['.tar.bz2', '.tbz2'],
237
'bzrlib.export.tar_exporter', 'tbz_exporter_generator')
238
register_lazy_exporter('tlzma', ['.tar.lzma'], 'bzrlib.export.tar_exporter',
239
'tar_lzma_exporter_generator')
240
register_lazy_exporter('txz', ['.tar.xz'], 'bzrlib.export.tar_exporter',
241
'tar_xz_exporter_generator')
242
register_lazy_exporter('zip', ['.zip'], 'bzrlib.export.zip_exporter',
243
'zip_exporter_generator')