/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

  • Committer: Martin Pool
  • Date: 2009-12-14 06:06:59 UTC
  • mfrom: (4889 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4891.
  • Revision ID: mbp@sourcefrog.net-20091214060659-1ucv8hpnky0cbnaj
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
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
16
16
 
17
17
"""Export functionality, which can take a Tree and create a different representation.
18
18
 
32
32
    """Register an exporter.
33
33
 
34
34
    :param format: This is the name of the format, such as 'tgz' or 'zip'
35
 
    :param extensions: Extensions which should be used in the case that a 
 
35
    :param extensions: Extensions which should be used in the case that a
36
36
                       format was not explicitly specified.
37
37
    :type extensions: List
38
38
    :param func: The function. It will be called with (tree, dest, root)
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, filtered):
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, filtered=filtered)
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, filtered=False):
66
66
    """Export the given Tree to the specific destination.
67
67
 
68
68
    :param tree: A Tree (such as RevisionTree) to export
70
70
    :param format: The format (dir, zip, etc), if None, it will check the
71
71
                   extension on dest, looking for a match
72
72
    :param root: The root location inside the format.
73
 
                 It is common practise to have zipfiles and tarballs 
 
73
                 It is common practise to have zipfiles and tarballs
74
74
                 extract into a subdirectory, rather than into the
75
75
                 current working directory.
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.
 
82
    :param filtered: If True, content filtering is applied to the
 
83
                     files exported.
79
84
    """
80
85
    global _exporters, _exporter_extensions
81
86
 
94
99
        raise errors.NoSuchExportFormat(format)
95
100
    tree.lock_read()
96
101
    try:
97
 
        return _exporters[format](tree, dest, root)
 
102
        return _exporters[format](tree, dest, root, subdir, filtered=filtered)
98
103
    finally:
99
104
        tree.unlock()
100
105
 
129
134
    return dest
130
135
 
131
136
 
 
137
def _export_iter_entries(tree, subdir):
 
138
    """Iter the entries for tree suitable for exporting.
 
139
 
 
140
    :param tree: A tree object.
 
141
    :param subdir: None or the path of a directory to start exporting from.
 
142
    """
 
143
    inv = tree.inventory
 
144
    if subdir is None:
 
145
        subdir_id = None
 
146
    else:
 
147
        subdir_id = inv.path2id(subdir)
 
148
    entries = inv.iter_entries(subdir_id)
 
149
    if subdir is None:
 
150
        entries.next() # skip root
 
151
    for entry in entries:
 
152
        # The .bzr* namespace is reserved for "magic" files like
 
153
        # .bzrignore and .bzrrules - do not export these
 
154
        if entry[0].startswith(".bzr"):
 
155
            continue
 
156
        if subdir is None:
 
157
            if not tree.has_filename(entry[0]):
 
158
                continue
 
159
        else:
 
160
            if not tree.has_filename(os.path.join(subdir, entry[0])):
 
161
                continue
 
162
        yield entry
 
163
 
 
164
 
132
165
register_lazy_exporter(None, [], 'bzrlib.export.dir_exporter', 'dir_exporter')
133
166
register_lazy_exporter('dir', [], 'bzrlib.export.dir_exporter', 'dir_exporter')
134
167
register_lazy_exporter('tar', ['.tar'], 'bzrlib.export.tar_exporter', 'tar_exporter')