/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: Andrew Bennetts
  • Date: 2010-04-13 04:33:55 UTC
  • mfrom: (5147 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5149.
  • Revision ID: andrew.bennetts@canonical.com-20100413043355-lg3id0uwtju0k3zs
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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
 
19
19
Such as non-controlled directories, tarfiles, zipfiles, etc.
20
20
"""
21
21
 
22
 
from bzrlib.trace import mutter
23
22
import os
24
23
import bzrlib.errors as errors
25
24
 
32
31
    """Register an exporter.
33
32
 
34
33
    :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 
 
34
    :param extensions: Extensions which should be used in the case that a
36
35
                       format was not explicitly specified.
37
36
    :type extensions: List
38
37
    :param func: The function. It will be called with (tree, dest, root)
55
54
 
56
55
    When requesting a specific type of export, load the respective path.
57
56
    """
58
 
    def _loader(tree, dest, root, subdir):
 
57
    def _loader(tree, dest, root, subdir, filtered, per_file_timestamps):
59
58
        mod = __import__(module, globals(), locals(), [funcname])
60
59
        func = getattr(mod, funcname)
61
 
        return func(tree, dest, root, subdir)
 
60
        return func(tree, dest, root, subdir, filtered=filtered,
 
61
                    per_file_timestamps=per_file_timestamps)
62
62
    register_exporter(scheme, extensions, _loader)
63
63
 
64
64
 
65
 
def export(tree, dest, format=None, root=None, subdir=None):
 
65
def export(tree, dest, format=None, root=None, subdir=None, filtered=False,
 
66
           per_file_timestamps=False):
66
67
    """Export the given Tree to the specific destination.
67
68
 
68
69
    :param tree: A Tree (such as RevisionTree) to export
70
71
    :param format: The format (dir, zip, etc), if None, it will check the
71
72
                   extension on dest, looking for a match
72
73
    :param root: The root location inside the format.
73
 
                 It is common practise to have zipfiles and tarballs 
 
74
                 It is common practise to have zipfiles and tarballs
74
75
                 extract into a subdirectory, rather than into the
75
76
                 current working directory.
76
77
                 If root is None, the default root will be
79
80
    :param subdir: A starting directory within the tree. None means to export
80
81
        the entire tree, and anything else should specify the relative path to
81
82
        a directory to start exporting from.
 
83
    :param filtered: If True, content filtering is applied to the
 
84
                     files exported.
 
85
    :param per_file_timestamps: Whether to use the timestamp stored in the 
 
86
        tree rather than now(). This will do a revision lookup 
 
87
        for every file so will be significantly slower.
82
88
    """
83
89
    global _exporters, _exporter_extensions
84
90
 
97
103
        raise errors.NoSuchExportFormat(format)
98
104
    tree.lock_read()
99
105
    try:
100
 
        return _exporters[format](tree, dest, root, subdir)
 
106
        return _exporters[format](tree, dest, root, subdir, filtered=filtered,
 
107
                                  per_file_timestamps=per_file_timestamps)
101
108
    finally:
102
109
        tree.unlock()
103
110
 
136
143
    """Iter the entries for tree suitable for exporting.
137
144
 
138
145
    :param tree: A tree object.
139
 
    :param subdir: None or the path of a directory to start exporting from.
 
146
    :param subdir: None or the path of an entry to start exporting from.
140
147
    """
141
148
    inv = tree.inventory
142
149
    if subdir is None:
143
 
        subdir_id = None
 
150
        subdir_object = None
144
151
    else:
145
152
        subdir_id = inv.path2id(subdir)
146
 
    entries = inv.iter_entries(subdir_id)
 
153
        if subdir_id is not None:
 
154
            subdir_object = inv[subdir_id]
 
155
        # XXX: subdir is path not an id, so NoSuchId isn't proper error
 
156
        else:
 
157
            raise errors.NoSuchId(tree, subdir)
 
158
    if subdir_object is not None and subdir_object.kind != 'directory':
 
159
        yield subdir_object.name, subdir_object
 
160
        return
 
161
    else:
 
162
        entries = inv.iter_entries(subdir_object)
147
163
    if subdir is None:
148
164
        entries.next() # skip root
149
165
    for entry in entries:
151
167
        # .bzrignore and .bzrrules - do not export these
152
168
        if entry[0].startswith(".bzr"):
153
169
            continue
 
170
        if subdir is None:
 
171
            if not tree.has_filename(entry[0]):
 
172
                continue
 
173
        else:
 
174
            if not tree.has_filename(os.path.join(subdir, entry[0])):
 
175
                continue
154
176
        yield entry
155
177
 
156
178