/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: John Arbash Meinel
  • Date: 2011-04-20 09:46:28 UTC
  • mfrom: (5609.33.4 2.3)
  • mto: (5609.33.5 2.3)
  • mto: This revision was merged to the branch mainline in revision 5811.
  • Revision ID: john@arbash-meinel.com-20110420094628-l0bafq1lwb6ib1v2
Merge lp:bzr/2.3 @ 5640 so we can update the release notes (aka NEWS)

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
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
 
import bzrlib.errors as errors
 
23
from bzrlib import (
 
24
    errors,
 
25
    pyutils,
 
26
    )
25
27
 
26
28
# Maps format name => export function
27
29
_exporters = {}
55
57
 
56
58
    When requesting a specific type of export, load the respective path.
57
59
    """
58
 
    def _loader(tree, dest, root, subdir, filtered):
59
 
        mod = __import__(module, globals(), locals(), [funcname])
60
 
        func = getattr(mod, funcname)
61
 
        return func(tree, dest, root, subdir, filtered=filtered)
 
60
    def _loader(tree, dest, root, subdir, filtered, per_file_timestamps):
 
61
        func = pyutils.get_named_object(module, funcname)
 
62
        return func(tree, dest, root, subdir, filtered=filtered,
 
63
                    per_file_timestamps=per_file_timestamps)
62
64
    register_exporter(scheme, extensions, _loader)
63
65
 
64
66
 
65
 
def export(tree, dest, format=None, root=None, subdir=None, filtered=False):
 
67
def export(tree, dest, format=None, root=None, subdir=None, filtered=False,
 
68
           per_file_timestamps=False):
66
69
    """Export the given Tree to the specific destination.
67
70
 
68
71
    :param tree: A Tree (such as RevisionTree) to export
81
84
        a directory to start exporting from.
82
85
    :param filtered: If True, content filtering is applied to the
83
86
                     files exported.
 
87
    :param per_file_timestamps: Whether to use the timestamp stored in the 
 
88
        tree rather than now(). This will do a revision lookup 
 
89
        for every file so will be significantly slower.
84
90
    """
85
91
    global _exporters, _exporter_extensions
86
92
 
99
105
        raise errors.NoSuchExportFormat(format)
100
106
    tree.lock_read()
101
107
    try:
102
 
        return _exporters[format](tree, dest, root, subdir, filtered=filtered)
 
108
        return _exporters[format](tree, dest, root, subdir, filtered=filtered,
 
109
                                  per_file_timestamps=per_file_timestamps)
103
110
    finally:
104
111
        tree.unlock()
105
112
 
138
145
    """Iter the entries for tree suitable for exporting.
139
146
 
140
147
    :param tree: A tree object.
141
 
    :param subdir: None or the path of a directory to start exporting from.
 
148
    :param subdir: None or the path of an entry to start exporting from.
142
149
    """
143
150
    inv = tree.inventory
144
151
    if subdir is None:
145
 
        subdir_id = None
 
152
        subdir_object = None
146
153
    else:
147
154
        subdir_id = inv.path2id(subdir)
148
 
    entries = inv.iter_entries(subdir_id)
 
155
        if subdir_id is not None:
 
156
            subdir_object = inv[subdir_id]
 
157
        # XXX: subdir is path not an id, so NoSuchId isn't proper error
 
158
        else:
 
159
            raise errors.NoSuchId(tree, subdir)
 
160
    if subdir_object is not None and subdir_object.kind != 'directory':
 
161
        yield subdir_object.name, subdir_object
 
162
        return
 
163
    else:
 
164
        entries = inv.iter_entries(subdir_object)
149
165
    if subdir is None:
150
166
        entries.next() # skip root
151
167
    for entry in entries: