/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/help.py

  • Committer: John Ferlito
  • Date: 2009-09-02 04:31:45 UTC
  • mto: (4665.7.1 serve-init)
  • mto: This revision was merged to the branch mainline in revision 4913.
  • Revision ID: johnf@inodes.org-20090902043145-gxdsfw03ilcwbyn5
Add a debian init script for bzr --serve

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2006 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
21
21
 
22
22
# TODO: `help commands --all` should show hidden commands
23
23
 
24
 
from . import (
 
24
import sys
 
25
import textwrap
 
26
 
 
27
from bzrlib import (
25
28
    commands as _mod_commands,
26
29
    errors,
27
30
    help_topics,
28
31
    osutils,
29
32
    plugin,
30
 
    ui,
31
 
    utextwrap,
 
33
    symbol_versioning,
32
34
    )
33
35
 
34
36
 
35
 
class NoHelpTopic(errors.BzrError):
36
 
 
37
 
    _fmt = ("No help could be found for '%(topic)s'. "
38
 
            "Please use 'brz help topics' to obtain a list of topics.")
39
 
 
40
 
    def __init__(self, topic):
41
 
        self.topic = topic
42
 
 
43
 
 
44
37
def help(topic=None, outfile=None):
45
38
    """Write the help for the specific topic to outfile"""
46
39
    if outfile is None:
47
 
        outfile = ui.ui_factory.make_output_stream()
 
40
        outfile = sys.stdout
48
41
 
49
42
    indices = HelpIndices()
50
43
 
52
45
    try:
53
46
        topics = indices.search(topic)
54
47
        shadowed_terms = []
55
 
        for index, topic_obj in topics[1:]:
 
48
        for index, topic in topics[1:]:
56
49
            shadowed_terms.append('%s%s' % (index.prefix,
57
 
                                            topic_obj.get_help_topic()))
 
50
                topic.get_help_topic()))
58
51
        source = topics[0][1]
59
52
        outfile.write(source.get_help_text(shadowed_terms))
60
 
    except NoHelpTopic:
 
53
    except errors.NoHelpTopic:
61
54
        if alias is None:
62
55
            raise
63
56
 
64
57
    if alias is not None:
65
 
        outfile.write("'brz %s' is an alias for 'brz %s'.\n" % (topic,
66
 
                                                                " ".join(alias)))
 
58
        outfile.write("'bzr %s' is an alias for 'bzr %s'.\n" % (topic,
 
59
            " ".join(alias)))
67
60
 
68
61
 
69
62
def help_commands(outfile=None):
70
63
    """List all commands"""
71
64
    if outfile is None:
72
 
        outfile = ui.ui_factory.make_output_stream()
 
65
        outfile = sys.stdout
73
66
    outfile.write(_help_commands_to_text('commands'))
74
67
 
75
68
 
85
78
    shown_commands = [(n, o) for n, o in commands if o.hidden == hidden]
86
79
    max_name = max(len(n) for n, o in shown_commands)
87
80
    indent = ' ' * (max_name + 1)
88
 
    width = osutils.terminal_width()
89
 
    if width is None:
90
 
        width = osutils.default_terminal_width
91
 
    # we need one extra space for terminals that wrap on last char
92
 
    width = width - 1
 
81
    width = osutils.terminal_width() - 1
93
82
 
94
83
    for cmd_name, cmd_object in sorted(shown_commands):
95
84
        plugin_name = cmd_object.plugin_name()
104
93
        else:
105
94
            firstline = ''
106
95
        helpstring = '%-*s %s%s' % (max_name, cmd_name, firstline, plugin_name)
107
 
        lines = utextwrap.wrap(
 
96
        lines = textwrap.wrap(
108
97
            helpstring, subsequent_indent=indent,
109
98
            width=width,
110
99
            break_long_words=False)
143
132
            help_topics.HelpTopicIndex(),
144
133
            _mod_commands.HelpCommandIndex(),
145
134
            plugin.PluginsHelpIndex(),
146
 
            help_topics.ConfigOptionHelpIndex(),
147
135
            ]
148
136
 
149
137
    def _check_prefix_uniqueness(self):
150
138
        """Ensure that the index collection is able to differentiate safely."""
151
 
        prefixes = set()
 
139
        prefixes = {}
152
140
        for index in self.search_path:
153
 
            prefix = index.prefix
154
 
            if prefix in prefixes:
 
141
            prefixes.setdefault(index.prefix, []).append(index)
 
142
        for prefix, indices in prefixes.items():
 
143
            if len(indices) > 1:
155
144
                raise errors.DuplicateHelpPrefix(prefix)
156
 
            prefixes.add(prefix)
157
145
 
158
146
    def search(self, topic):
159
147
        """Search for topic across the help search path.
165
153
        self._check_prefix_uniqueness()
166
154
        result = []
167
155
        for index in self.search_path:
168
 
            result.extend([(index, _topic)
169
 
                           for _topic in index.get_topics(topic)])
 
156
            result.extend([(index, _topic) for _topic in index.get_topics(topic)])
170
157
        if not result:
171
 
            raise NoHelpTopic(topic)
 
158
            raise errors.NoHelpTopic(topic)
172
159
        else:
173
160
            return result