/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/export/__init__.py

First attempt to merge .dev and resolve the conflicts (but tests are 
failing)

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
 
56
56
    When requesting a specific type of export, load the respective path.
57
57
    """
58
 
    def _loader(tree, dest, root):
 
58
    def _loader(tree, dest, root, subdir):
59
59
        mod = __import__(module, globals(), locals(), [funcname])
60
60
        func = getattr(mod, funcname)
61
 
        return func(tree, dest, root)
 
61
        return func(tree, dest, root, subdir)
62
62
    register_exporter(scheme, extensions, _loader)
63
63
 
64
64
 
65
 
def export(tree, dest, format=None, root=None):
 
65
def export(tree, dest, format=None, root=None, subdir=None):
66
66
    """Export the given Tree to the specific destination.
67
67
 
68
68
    :param tree: A Tree (such as RevisionTree) to export
76
76
                 If root is None, the default root will be
77
77
                 selected as the destination without its
78
78
                 extension.
 
79
    :param subdir: A starting directory within the tree. None means to export
 
80
        the entire tree, and anything else should specify the relative path to
 
81
        a directory to start exporting from.
79
82
    """
80
83
    global _exporters, _exporter_extensions
81
84
 
92
95
 
93
96
    if format not in _exporters:
94
97
        raise errors.NoSuchExportFormat(format)
95
 
    return _exporters[format](tree, dest, root)
 
98
    tree.lock_read()
 
99
    try:
 
100
        return _exporters[format](tree, dest, root, subdir)
 
101
    finally:
 
102
        tree.unlock()
96
103
 
97
104
 
98
105
def get_root_name(dest):
99
106
    """Get just the root name for an export.
100
107
 
 
108
    >>> get_root_name('../mytest.tar')
 
109
    'mytest'
101
110
    >>> get_root_name('mytar.tar')
102
111
    'mytar'
103
112
    >>> get_root_name('mytar.tar.bz2')
123
132
    return dest
124
133
 
125
134
 
 
135
def _export_iter_entries(tree, subdir):
 
136
    """Iter the entries for tree suitable for exporting.
 
137
 
 
138
    :param tree: A tree object.
 
139
    :param subdir: None or the path of a directory to start exporting from.
 
140
    """
 
141
    inv = tree.inventory
 
142
    if subdir is None:
 
143
        subdir_id = None
 
144
    else:
 
145
        subdir_id = inv.path2id(subdir)
 
146
    entries = inv.iter_entries(subdir_id)
 
147
    if subdir is None:
 
148
        entries.next() # skip root
 
149
    for entry in entries:
 
150
        # The .bzr* namespace is reserved for "magic" files like
 
151
        # .bzrignore and .bzrrules - do not export these
 
152
        if entry[0].startswith(".bzr"):
 
153
            continue
 
154
        yield entry
 
155
 
 
156
 
126
157
register_lazy_exporter(None, [], 'bzrlib.export.dir_exporter', 'dir_exporter')
127
158
register_lazy_exporter('dir', [], 'bzrlib.export.dir_exporter', 'dir_exporter')
128
159
register_lazy_exporter('tar', ['.tar'], 'bzrlib.export.tar_exporter', 'tar_exporter')