~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/cmd_version_info.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-02-03 10:06:19 UTC
  • mfrom: (4999.3.2 apport)
  • Revision ID: pqm@pqm.ubuntu.com-20100203100619-f76bo5y5bd5c14wk
(mbp) use apport to send bugs, not just store them

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2009 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
16
16
 
17
17
"""Commands for generating snapshot information about a bzr tree."""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
19
from bzrlib.lazy_import import lazy_import
22
20
 
23
21
lazy_import(globals(), """
24
22
from bzrlib import (
25
23
    branch,
26
24
    errors,
 
25
    ui,
27
26
    version_info_formats,
28
27
    workingtree,
29
28
    )
30
 
from bzrlib.i18n import gettext
31
29
""")
32
30
 
33
31
from bzrlib.commands import Command
44
42
        return version_info_formats.get_builder(format)
45
43
    except KeyError:
46
44
        formats = version_info_formats.get_builder_formats()
47
 
        raise errors.BzrCommandError(gettext('No known version info format {0}.'
48
 
                                     ' Supported types are: {1}').format(
49
 
                                     format, formats))
 
45
        raise errors.BzrCommandError('No known version info format %s.'
 
46
                                     ' Supported types are: %s'
 
47
                                     % (format, formats))
50
48
 
51
49
 
52
50
class cmd_version_info(Command):
53
 
    __doc__ = """Show version information about this tree.
 
51
    """Show version information about this tree.
54
52
 
55
53
    You can use this command to add information about version into
56
54
    source code of an application. The output can be in one of the
85
83
                     Option('include-file-revisions',
86
84
                            help='Include the last revision for each file.'),
87
85
                     Option('template', type=str, help='Template for the output.'),
88
 
                     'revision',
89
86
                     ]
90
87
    takes_args = ['location?']
91
88
 
93
90
 
94
91
    def run(self, location=None, format=None,
95
92
            all=False, check_clean=False, include_history=False,
96
 
            include_file_revisions=False, template=None,
97
 
            revision=None):
98
 
 
99
 
        if revision and len(revision) > 1:
100
 
            raise errors.BzrCommandError(
101
 
                gettext('bzr version-info --revision takes exactly'
102
 
                        ' one revision specifier'))
 
93
            include_file_revisions=False, template=None):
103
94
 
104
95
        if location is None:
105
96
            location = '.'
107
98
        if format is None:
108
99
            format = version_info_formats.format_registry.get()
109
100
 
 
101
        wt = None
110
102
        try:
111
103
            wt = workingtree.WorkingTree.open_containing(location)[0]
112
104
        except errors.NoWorkingTree:
113
105
            b = branch.Branch.open(location)
114
 
            wt = None
115
106
        else:
116
107
            b = wt.branch
117
108
 
118
 
        if all:
 
109
        if all or template:
119
110
            include_history = True
120
111
            check_clean = True
121
 
            include_file_revisions = True
122
 
        if template:
123
 
            include_history = True
124
 
            include_file_revisions = True
125
 
            if '{clean}' in template:
126
 
                check_clean = True
127
 
 
128
 
        if revision is not None:
129
 
            revision_id = revision[0].as_revision_id(b)
130
 
        else:
131
 
            revision_id = None
 
112
            include_file_revisions=True
132
113
 
133
114
        builder = format(b, working_tree=wt,
134
115
                check_for_clean=check_clean,
135
116
                include_revision_history=include_history,
136
117
                include_file_revisions=include_file_revisions,
137
 
                template=template, revision_id=revision_id)
138
 
        builder.generate(self.outf)
 
118
                template=template)
 
119
        builder.generate(ui.ui_factory.make_output_stream())