~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help_topics/__init__.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-16 09:33:16 UTC
  • mfrom: (6059.3.6 747050-config-help)
  • Revision ID: pqm@pqm.ubuntu.com-20110816093316-favbhalxcbqwxhuw
(vila) Implement per-config option help (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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
37
37
 
38
38
import bzrlib
39
39
from bzrlib import (
 
40
    config,
40
41
    osutils,
41
42
    registry,
42
43
    )
65
66
        :param section: Section in reference manual - see SECT_* identifiers.
66
67
        """
67
68
        # The detail is stored as the 'object' and the metadata as the info
68
 
        info=(summary,section)
 
69
        info = (summary, section)
69
70
        super(HelpTopicRegistry, self).register(topic, detail, info=info)
70
71
 
71
72
    def register_lazy(self, topic, module_name, member_name, summary,
79
80
        :param section: Section in reference manual - see SECT_* identifiers.
80
81
        """
81
82
        # The detail is stored as the 'object' and the metadata as the info
82
 
        info=(summary,section)
 
83
        info = (summary, section)
83
84
        super(HelpTopicRegistry, self).register_lazy(topic, module_name,
84
85
                                                     member_name, info=info)
85
86
 
844
845
            return []
845
846
 
846
847
 
 
848
def _format_see_also(see_also):
 
849
    result = ''
 
850
    if see_also:
 
851
        result += '\n:See also: '
 
852
        result += ', '.join(sorted(set(see_also)))
 
853
        result += '\n'
 
854
    return result
 
855
 
 
856
 
847
857
class RegisteredTopic(object):
848
858
    """A help topic which has been registered in the HelpTopicRegistry.
849
859
 
867
877
            returned instead of plain text.
868
878
        """
869
879
        result = topic_registry.get_detail(self.topic)
870
 
        # there is code duplicated here and in bzrlib/plugin.py's
871
 
        # matching Topic code. This should probably be factored in
872
 
        # to a helper function and a common base class.
873
 
        if additional_see_also is not None:
874
 
            see_also = sorted(set(additional_see_also))
875
 
        else:
876
 
            see_also = None
877
 
        if see_also:
878
 
            result += '\n:See also: '
879
 
            result += ', '.join(see_also)
880
 
            result += '\n'
 
880
        result += _format_see_also(additional_see_also)
881
881
        if plain:
882
882
            result = help_as_plain_text(result)
883
883
        return result
903
903
        line = re.sub(":doc:`(.+?)-help`", r'``bzr help \1``', line)
904
904
        result.append(line)
905
905
    return "\n".join(result) + "\n"
 
906
 
 
907
 
 
908
class ConfigOptionHelpIndex(object):
 
909
    """A help index that returns help topics for config options."""
 
910
 
 
911
    def __init__(self):
 
912
        self.prefix = 'configuration/'
 
913
 
 
914
    def get_topics(self, topic):
 
915
        """Search for topic in the registered config options.
 
916
 
 
917
        :param topic: A topic to search for.
 
918
        :return: A list which is either empty or contains a single
 
919
            config.Option entry.
 
920
        """
 
921
        if topic is None:
 
922
            return []
 
923
        elif topic.startswith(self.prefix):
 
924
            topic = topic[len(self.prefix):]
 
925
        if topic in config.option_registry:
 
926
            return [config.option_registry.get(topic)]
 
927
        else:
 
928
            return []
 
929
 
 
930