~toddy/bzr/bzr.i18n

« back to all changes in this revision

Viewing changes to bzrlib/version_info_formats/__init__.py

  • Committer: Tobias Toedter
  • Date: 2007-12-30 18:52:13 UTC
  • mfrom: (2438.1.708 +trunk)
  • Revision ID: t.toedter@gmx.net-20071230185213-7xiqpbtshmnsf073
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import time
20
20
 
21
21
from bzrlib.osutils import local_time_offset, format_date
22
 
 
23
 
 
24
 
# This contains a map of format id => formatter
25
 
# None is considered the default formatter
26
 
_version_formats = {}
 
22
from bzrlib import registry
 
23
from bzrlib.symbol_versioning import (
 
24
    deprecated_function,
 
25
    one_zero,
 
26
    )
 
27
 
27
28
 
28
29
def create_date_str(timestamp=None, offset=None):
29
30
    """Just a wrapper around format_date to provide the right format.
48
49
                check_for_clean=False,
49
50
                include_revision_history=False,
50
51
                include_file_revisions=False,
51
 
                ):
 
52
                template=None):
52
53
        """Build up information about the given branch.
53
54
        If working_tree is given, it can be checked for changes.
54
55
 
62
63
            date and message
63
64
        :param include_file_revisions: The output should
64
65
            include the explicit last-changed revision for each file.
 
66
        :param template: Template for the output formatting, not used by
 
67
            all builders.
65
68
        """
66
69
        self._branch = branch
67
70
        self._working_tree = working_tree
68
71
        self._check = check_for_clean
69
72
        self._include_history = include_revision_history
70
73
        self._include_file_revs = include_file_revisions
 
74
        self._template = template
71
75
 
72
76
        self._clean = None
73
77
        self._file_revisions = {}
169
173
        raise NotImplementedError(VersionInfoBuilder.generate)
170
174
 
171
175
 
172
 
 
 
176
format_registry = registry.Registry()
 
177
 
 
178
 
 
179
@deprecated_function(one_zero)
173
180
def register_builder(format, module, class_name):
174
181
    """Register a version info format.
175
182
 
179
186
        can be found
180
187
    :param class_name: The string name of the class to instantiate
181
188
    """
182
 
    if len(_version_formats) == 0:
183
 
        _version_formats[None] = (module, class_name)
184
 
    _version_formats[format] = (module, class_name)
185
 
 
186
 
 
 
189
    format_registry.register_lazy(format, module, class_name)
 
190
 
 
191
 
 
192
@deprecated_function(one_zero)
187
193
def get_builder(format):
188
194
    """Get a handle to the version info builder class
189
195
 
190
196
    :param format: The lookup key supplied to register_builder
191
197
    :return: A class, which follows the VersionInfoBuilder api.
192
198
    """
193
 
    builder_module, builder_class_name = _version_formats[format]
194
 
    module = __import__(builder_module, globals(), locals(),
195
 
                        [builder_class_name])
196
 
    klass = getattr(module, builder_class_name)
197
 
    return klass
198
 
 
199
 
 
 
199
    return format_registry.get(format)
 
200
 
 
201
 
 
202
@deprecated_function(one_zero)
200
203
def get_builder_formats():
201
204
    """Get the possible list of formats"""
202
 
    formats = _version_formats.keys()
203
 
    formats.remove(None)
204
 
    return formats
205
 
 
206
 
 
207
 
register_builder('rio',
208
 
                 'bzrlib.version_info_formats.format_rio',
209
 
                 'RioVersionInfoBuilder')
210
 
register_builder('python',
211
 
                 'bzrlib.version_info_formats.format_python',
212
 
                 'PythonVersionInfoBuilder')
 
205
    return format_registry.keys()
 
206
 
 
207
 
 
208
format_registry.register_lazy(
 
209
    'rio',
 
210
    'bzrlib.version_info_formats.format_rio',
 
211
    'RioVersionInfoBuilder',
 
212
    'Version info in RIO format.')
 
213
format_registry.default_key = 'rio'
 
214
format_registry.register_lazy(
 
215
    'python',
 
216
    'bzrlib.version_info_formats.format_python',
 
217
    'PythonVersionInfoBuilder',
 
218
    'Version info in Python format.')
 
219
format_registry.register_lazy(
 
220
    'custom',
 
221
    'bzrlib.version_info_formats.format_custom',
 
222
    'CustomVersionInfoBuilder',
 
223
    'Version info in Custom template-based format.')