~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help_topics/__init__.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

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
33
33
rendering on the screen naturally.
34
34
"""
35
35
 
36
 
import sys
 
36
from __future__ import absolute_import
37
37
 
38
38
import bzrlib
39
39
from bzrlib import (
 
40
    config,
40
41
    osutils,
41
42
    registry,
 
43
    i18n,
42
44
    )
43
45
 
44
46
 
65
67
        :param section: Section in reference manual - see SECT_* identifiers.
66
68
        """
67
69
        # The detail is stored as the 'object' and the metadata as the info
68
 
        info=(summary,section)
 
70
        info = (summary, section)
69
71
        super(HelpTopicRegistry, self).register(topic, detail, info=info)
70
72
 
71
73
    def register_lazy(self, topic, module_name, member_name, summary,
79
81
        :param section: Section in reference manual - see SECT_* identifiers.
80
82
        """
81
83
        # The detail is stored as the 'object' and the metadata as the info
82
 
        info=(summary,section)
 
84
        info = (summary, section)
83
85
        super(HelpTopicRegistry, self).register_lazy(topic, module_name,
84
86
                                                     member_name, info=info)
85
87
 
270
272
 
271
273
would refer to ``/home/remote/myproject/trunk``.
272
274
 
273
 
Many commands that accept URLs also accept location aliases too.  See
274
 
::doc:`location-alias-help`.
 
275
Many commands that accept URLs also accept location aliases too.
 
276
See :doc:`location-alias-help` and :doc:`url-special-chars-help`.
275
277
"""
276
278
 
277
279
    return out
329
331
               will be a pickle.
330
332
--coverage     Generate line coverage report in the specified directory.
331
333
 
 
334
-Oname=value   Override the ``name`` config option setting it to ``value`` for
 
335
               the duration of the command.  This can be used multiple times if
 
336
               several options need to be overridden.
 
337
 
332
338
See http://doc.bazaar.canonical.com/developers/profiling.html for more
333
339
information on profiling.
334
340
 
589
595
"""
590
596
 
591
597
 
592
 
_env_variables = \
593
 
"""Environment Variables
594
 
 
595
 
=================== ===========================================================
596
 
BZRPATH             Path where bzr is to look for shell plugin external
597
 
                    commands.
598
 
BZR_EMAIL           E-Mail address of the user. Overrides EMAIL.
599
 
EMAIL               E-Mail address of the user.
600
 
BZR_EDITOR          Editor for editing commit messages. Overrides EDITOR.
601
 
EDITOR              Editor for editing commit messages.
602
 
BZR_PLUGIN_PATH     Paths where bzr should look for plugins.
603
 
BZR_DISABLE_PLUGINS Plugins that bzr should not load.
604
 
BZR_PLUGINS_AT      Plugins to load from a directory not in BZR_PLUGIN_PATH.
605
 
BZR_HOME            Directory holding .bazaar config dir. Overrides HOME.
606
 
BZR_HOME (Win32)    Directory holding bazaar config dir. Overrides APPDATA and
607
 
                    HOME.
608
 
BZR_REMOTE_PATH     Full name of remote 'bzr' command (for bzr+ssh:// URLs).
609
 
BZR_SSH             Path to SSH client, or one of paramiko, openssh, sshcorp,
610
 
                    plink or lsh.
611
 
BZR_LOG             Location of .bzr.log (use '/dev/null' to suppress log).
612
 
BZR_LOG (Win32)     Location of .bzr.log (use 'NUL' to suppress log).
613
 
BZR_COLUMNS         Override implicit terminal width.
614
 
BZR_CONCURRENCY     Number of processes that can be run concurrently (selftest)
615
 
BZR_PROGRESS_BAR    Override the progress display. Values are 'none', 'dots',
616
 
                    or 'tty'.
617
 
BZR_PDB             Control whether to launch a debugger on error.
618
 
BZR_SIGQUIT_PDB     Control whether SIGQUIT behaves normally or invokes a
619
 
                    breakin debugger.
620
 
=================== ===========================================================
621
 
"""
622
 
 
 
598
known_env_variables = [
 
599
    ("BZRPATH", "Path where bzr is to look for shell plugin external commands."),
 
600
    ("BZR_EMAIL", "E-Mail address of the user. Overrides EMAIL."),
 
601
    ("EMAIL", "E-Mail address of the user."),
 
602
    ("BZR_EDITOR", "Editor for editing commit messages. Overrides EDITOR."),
 
603
    ("EDITOR", "Editor for editing commit messages."),
 
604
    ("BZR_PLUGIN_PATH", "Paths where bzr should look for plugins."),
 
605
    ("BZR_DISABLE_PLUGINS", "Plugins that bzr should not load."),
 
606
    ("BZR_PLUGINS_AT", "Plugins to load from a directory not in BZR_PLUGIN_PATH."),
 
607
    ("BZR_HOME", "Directory holding .bazaar config dir. Overrides HOME."),
 
608
    ("BZR_HOME (Win32)", "Directory holding bazaar config dir. Overrides APPDATA and HOME."),
 
609
    ("BZR_REMOTE_PATH", "Full name of remote 'bzr' command (for bzr+ssh:// URLs)."),
 
610
    ("BZR_SSH", "Path to SSH client, or one of paramiko, openssh, sshcorp, plink or lsh."),
 
611
    ("BZR_LOG", "Location of .bzr.log (use '/dev/null' to suppress log)."),
 
612
    ("BZR_LOG (Win32)", "Location of .bzr.log (use 'NUL' to suppress log)."),
 
613
    ("BZR_COLUMNS", "Override implicit terminal width."),
 
614
    ("BZR_CONCURRENCY", "Number of processes that can be run concurrently (selftest)"),
 
615
    ("BZR_PROGRESS_BAR", "Override the progress display. Values are 'none' or 'text'."),
 
616
    ("BZR_PDB", "Control whether to launch a debugger on error."),
 
617
    ("BZR_SIGQUIT_PDB", "Control whether SIGQUIT behaves normally or invokes a breakin debugger."),
 
618
    ("BZR_TEXTUI_INPUT", "Force console input mode for prompts to line-based (instead of char-based)."),
 
619
    ]
 
620
 
 
621
def _env_variables(topic):
 
622
    import textwrap
 
623
    ret = ["Environment Variables\n\n"
 
624
        "See bzr help configuration for more details.\n\n"]
 
625
    max_key_len = max([len(k[0]) for k in known_env_variables])
 
626
    desc_len = (80 - max_key_len - 2)
 
627
    ret.append("=" * max_key_len + " " + "=" * desc_len + "\n")
 
628
    for k, desc in known_env_variables:
 
629
        ret.append(k + (max_key_len + 1 - len(k)) * " ")
 
630
        ret.append("\n".join(textwrap.wrap(
 
631
            desc, width=desc_len, subsequent_indent=" " * (max_key_len + 1))))
 
632
        ret.append("\n")
 
633
    ret += "=" * max_key_len + " " + "=" * desc_len + "\n"
 
634
    return "".join(ret)
623
635
 
624
636
_files = \
625
637
r"""Files
732
744
topic_registry.register('basic', _basic_help, "Basic commands", SECT_HIDDEN)
733
745
topic_registry.register('topics', _help_on_topics, "Topics list", SECT_HIDDEN)
734
746
def get_current_formats_topic(topic):
735
 
    from bzrlib import bzrdir
 
747
    from bzrlib import controldir
736
748
    return "Current Storage Formats\n\n" + \
737
 
        bzrdir.format_registry.help_topic(topic)
 
749
        controldir.format_registry.help_topic(topic)
738
750
def get_other_formats_topic(topic):
739
 
    from bzrlib import bzrdir
 
751
    from bzrlib import controldir
740
752
    return "Other Storage Formats\n\n" + \
741
 
        bzrdir.format_registry.help_topic(topic)
 
753
        controldir.format_registry.help_topic(topic)
742
754
topic_registry.register('current-formats', get_current_formats_topic,
743
755
    'Current storage formats')
744
756
topic_registry.register('other-formats', get_other_formats_topic,
762
774
                        'Information on configuration and log files')
763
775
topic_registry.register_lazy('hooks', 'bzrlib.hooks', 'hooks_help_text',
764
776
                        'Points at which custom processing can be added')
 
777
topic_registry.register_lazy('location-alias', 'bzrlib.directory_service',
 
778
                        'AliasDirectory.help_text',
 
779
                        'Aliases for remembered locations')
765
780
 
766
781
# Load some of the help topics from files. Note that topics which reproduce API
767
782
# details will tend to skew (quickly usually!) so please seek other solutions
774
789
                        'Types of conflicts and what to do about them')
775
790
topic_registry.register('debug-flags', _load_from_file,
776
791
                        'Options to show or record debug information')
777
 
topic_registry.register('location-alias', _load_from_file,
778
 
                        'Aliases for remembered locations')
779
792
topic_registry.register('log-formats', _load_from_file,
780
793
                        'Details on the logging formats available')
 
794
topic_registry.register('url-special-chars', _load_from_file,
 
795
                        'Special character handling in URLs')
781
796
 
782
797
 
783
798
# Register concept topics.
842
857
            return []
843
858
 
844
859
 
 
860
def _format_see_also(see_also):
 
861
    result = ''
 
862
    if see_also:
 
863
        result += '\n:See also: '
 
864
        result += ', '.join(sorted(set(see_also)))
 
865
        result += '\n'
 
866
    return result
 
867
 
 
868
 
845
869
class RegisteredTopic(object):
846
870
    """A help topic which has been registered in the HelpTopicRegistry.
847
871
 
865
889
            returned instead of plain text.
866
890
        """
867
891
        result = topic_registry.get_detail(self.topic)
868
 
        # there is code duplicated here and in bzrlib/plugin.py's
869
 
        # matching Topic code. This should probably be factored in
870
 
        # to a helper function and a common base class.
871
 
        if additional_see_also is not None:
872
 
            see_also = sorted(set(additional_see_also))
873
 
        else:
874
 
            see_also = None
875
 
        if see_also:
876
 
            result += '\n:See also: '
877
 
            result += ', '.join(see_also)
878
 
            result += '\n'
 
892
        result += _format_see_also(additional_see_also)
879
893
        if plain:
880
894
            result = help_as_plain_text(result)
 
895
        i18n.install()
 
896
        result = i18n.gettext_per_paragraph(result)
881
897
        return result
882
898
 
883
899
    def get_help_topic(self):
898
914
        elif line.endswith('::'):
899
915
            line = line[:-1]
900
916
        # Map :doc:`xxx-help` to ``bzr help xxx``
901
 
        line = re.sub(":doc:`(.+)-help`", r'``bzr help \1``', line)
 
917
        line = re.sub(":doc:`(.+?)-help`", r'``bzr help \1``', line)
902
918
        result.append(line)
903
919
    return "\n".join(result) + "\n"
 
920
 
 
921
 
 
922
class ConfigOptionHelpIndex(object):
 
923
    """A help index that returns help topics for config options."""
 
924
 
 
925
    def __init__(self):
 
926
        self.prefix = 'configuration/'
 
927
 
 
928
    def get_topics(self, topic):
 
929
        """Search for topic in the registered config options.
 
930
 
 
931
        :param topic: A topic to search for.
 
932
        :return: A list which is either empty or contains a single
 
933
            config.Option entry.
 
934
        """
 
935
        if topic is None:
 
936
            return []
 
937
        elif topic.startswith(self.prefix):
 
938
            topic = topic[len(self.prefix):]
 
939
        if topic in config.option_registry:
 
940
            return [config.option_registry.get(topic)]
 
941
        else:
 
942
            return []
 
943
 
 
944