~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help_topics.py

  • Committer: John Arbash Meinel
  • Date: 2007-04-28 15:04:17 UTC
  • mfrom: (2466 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2566.
  • Revision ID: john@arbash-meinel.com-20070428150417-trp3pi0pzd411pu4
[merge] bzr.dev 2466

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
 
82
82
 
83
83
def _help_on_revisionspec(name):
84
 
    """"Write the summary help for all documented topics to outfile."""
 
84
    """Write the summary help for all documented topics to outfile."""
85
85
    import bzrlib.revisionspec
86
86
 
87
87
    out = []
100
100
    return ''.join(out)
101
101
 
102
102
 
 
103
def _help_on_transport(name):
 
104
    from bzrlib.transport import (
 
105
        transport_list_registry,
 
106
    )
 
107
    import textwrap
 
108
 
 
109
    def add_string(proto, help, maxl, prefix_width=20):
 
110
       help_lines = textwrap.wrap(help, maxl - prefix_width)
 
111
       line_with_indent = '\n' + ' ' * prefix_width
 
112
       help_text = line_with_indent.join(help_lines)
 
113
       return "%-20s%s\n" % (proto, help_text)
 
114
 
 
115
    def sort_func(a,b):
 
116
        a1 = a[:a.rfind("://")]
 
117
        b1 = b[:b.rfind("://")]
 
118
        if a1>b1:
 
119
            return +1
 
120
        elif a1<b1:
 
121
            return -1
 
122
        else:
 
123
            return 0
 
124
 
 
125
    out = []
 
126
    protl = []
 
127
    decl = []
 
128
    protos = transport_list_registry.keys( )
 
129
    protos.sort(sort_func)
 
130
    for proto in protos:
 
131
        shorthelp = transport_list_registry.get_help(proto)
 
132
        if not shorthelp:
 
133
            continue
 
134
        if proto.endswith("://"):
 
135
            protl.extend(add_string(proto, shorthelp, 79))
 
136
        else:
 
137
            decl.extend(add_string(proto, shorthelp, 79))
 
138
 
 
139
 
 
140
    out = "\nSupported URL prefix\n--------------------\n" + \
 
141
            ''.join(protl)
 
142
 
 
143
    if len(decl):
 
144
        out += "\nSupported modifiers\n-------------------\n" + \
 
145
            ''.join(decl)
 
146
 
 
147
    return out
 
148
 
 
149
 
103
150
_basic_help= \
104
151
"""Bazaar -- a free distributed version-control tool
105
152
http://bazaar-vcs.org/
242
289
                        'Options that can be used with any command')
243
290
topic_registry.register('checkouts', _checkouts,
244
291
                        'Information on what a checkout is')
245
 
 
 
292
topic_registry.register('urlspec', _help_on_transport,
 
293
                        "Supported transport protocols")
 
294
def get_bugs_topic(topic):
 
295
    from bzrlib import bugtracker
 
296
    return bugtracker.tracker_registry.help_topic(topic)
 
297
topic_registry.register('bugs', get_bugs_topic, 'Bug tracker support')
 
298
 
 
299
 
 
300
class HelpTopicIndex(object):
 
301
    """A index for bzr help that returns topics."""
 
302
 
 
303
    def __init__(self):
 
304
        self.prefix = ''
 
305
 
 
306
    def get_topics(self, topic):
 
307
        """Search for topic in the HelpTopicRegistry.
 
308
 
 
309
        :param topic: A topic to search for. None is treated as 'basic'.
 
310
        :return: A list which is either empty or contains a single
 
311
            RegisteredTopic entry.
 
312
        """
 
313
        if topic is None:
 
314
            topic = 'basic'
 
315
        if topic in topic_registry:
 
316
            return [RegisteredTopic(topic)]
 
317
        else:
 
318
            return []
 
319
 
 
320
 
 
321
class RegisteredTopic(object):
 
322
    """A help topic which has been registered in the HelpTopicRegistry.
 
323
 
 
324
    These topics consist of nothing more than the name of the topic - all
 
325
    data is retrieved on demand from the registry.
 
326
    """
 
327
 
 
328
    def __init__(self, topic):
 
329
        """Constructor.
 
330
 
 
331
        :param topic: The name of the topic that this represents.
 
332
        """
 
333
        self.topic = topic
 
334
 
 
335
    def get_help_text(self, additional_see_also=None):
 
336
        """Return a string with the help for this topic.
 
337
 
 
338
        :param additional_see_also: Additional help topics to be
 
339
            cross-referenced.
 
340
        """
 
341
        result = topic_registry.get_detail(self.topic)
 
342
        # there is code duplicated here and in bzrlib/plugin.py's 
 
343
        # matching Topic code. This should probably be factored in
 
344
        # to a helper function and a common base class.
 
345
        if additional_see_also is not None:
 
346
            see_also = sorted(set(additional_see_also))
 
347
        else:
 
348
            see_also = None
 
349
        if see_also:
 
350
            result += '\nSee also: '
 
351
            result += ', '.join(see_also)
 
352
            result += '\n'
 
353
        return result
 
354
 
 
355
    def get_help_topic(self):
 
356
        """Return the help topic this can be found under."""
 
357
        return self.topic