~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
316
318
--builtin      Use the built-in version of a command, not the plugin version.
317
319
               This does not suppress other plugin effects.
318
320
--no-plugins   Do not process any plugins.
 
321
--no-l10n      Do not translate messages.
319
322
--concurrency  Number of processes that can be run concurrently (selftest).
320
323
 
321
324
--profile      Profile execution using the hotshot profiler.
328
331
               will be a pickle.
329
332
--coverage     Generate line coverage report in the specified directory.
330
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
 
331
338
See http://doc.bazaar.canonical.com/developers/profiling.html for more
332
339
information on profiling.
333
340
 
512
519
 
513
520
  checkout     Create a working tree when a branch does not have one.
514
521
  remove-tree  Removes the working tree from a branch when it is safe to do so.
515
 
  update       When a working tree is out of sync with it's associated branch
 
522
  update       When a working tree is out of sync with its associated branch
516
523
               this will update the tree to match the branch.
517
524
"""
518
525
 
588
595
"""
589
596
 
590
597
 
591
 
_env_variables = \
592
 
"""Environment Variables
593
 
 
594
 
=================== =======================================================================
595
 
BZRPATH             Path where bzr is to look for shell plugin external commands.
596
 
BZR_EMAIL           E-Mail address of the user. Overrides EMAIL.
597
 
EMAIL               E-Mail address of the user.
598
 
BZR_EDITOR          Editor for editing commit messages. Overrides EDITOR.
599
 
EDITOR              Editor for editing commit messages.
600
 
BZR_PLUGIN_PATH     Paths where bzr should look for plugins.
601
 
BZR_DISABLE_PLUGINS Plugins that bzr should not load.
602
 
BZR_PLUGINS_AT      Plugins to load from a directory not in BZR_PLUGIN_PATH.
603
 
BZR_HOME            Directory holding .bazaar config dir. Overrides HOME.
604
 
BZR_HOME (Win32)    Directory holding bazaar config dir. Overrides APPDATA and HOME.
605
 
BZR_REMOTE_PATH     Full name of remote 'bzr' command (for bzr+ssh:// URLs).
606
 
BZR_SSH             Path to SSH client, or one of paramiko, openssh, sshcorp, plink.
607
 
BZR_LOG             Location of .bzr.log (use '/dev/null' to suppress log).
608
 
BZR_LOG (Win32)     Location of .bzr.log (use 'NUL' to suppress log).
609
 
BZR_COLUMNS         Override implicit terminal width.
610
 
BZR_CONCURRENCY     Number of processes that can be run concurrently (selftest).
611
 
BZR_PROGRESS_BAR    Override the progress display. Values are 'none', 'dots', or 'tty'.
612
 
BZR_PDB             Control whether to launch a debugger on error.
613
 
BZR_SIGQUIT_PDB     Control whether SIGQUIT behaves normally or invokes a breakin debugger.
614
 
=================== =======================================================================
615
 
"""
616
 
 
 
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)
617
635
 
618
636
_files = \
619
637
r"""Files
726
744
topic_registry.register('basic', _basic_help, "Basic commands", SECT_HIDDEN)
727
745
topic_registry.register('topics', _help_on_topics, "Topics list", SECT_HIDDEN)
728
746
def get_current_formats_topic(topic):
729
 
    from bzrlib import bzrdir
 
747
    from bzrlib import controldir
730
748
    return "Current Storage Formats\n\n" + \
731
 
        bzrdir.format_registry.help_topic(topic)
 
749
        controldir.format_registry.help_topic(topic)
732
750
def get_other_formats_topic(topic):
733
 
    from bzrlib import bzrdir
 
751
    from bzrlib import controldir
734
752
    return "Other Storage Formats\n\n" + \
735
 
        bzrdir.format_registry.help_topic(topic)
 
753
        controldir.format_registry.help_topic(topic)
736
754
topic_registry.register('current-formats', get_current_formats_topic,
737
755
    'Current storage formats')
738
756
topic_registry.register('other-formats', get_other_formats_topic,
756
774
                        'Information on configuration and log files')
757
775
topic_registry.register_lazy('hooks', 'bzrlib.hooks', 'hooks_help_text',
758
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')
759
780
 
760
781
# Load some of the help topics from files. Note that topics which reproduce API
761
782
# details will tend to skew (quickly usually!) so please seek other solutions
768
789
                        'Types of conflicts and what to do about them')
769
790
topic_registry.register('debug-flags', _load_from_file,
770
791
                        'Options to show or record debug information')
771
 
topic_registry.register('location-alias', _load_from_file,
772
 
                        'Aliases for remembered locations')
773
792
topic_registry.register('log-formats', _load_from_file,
774
793
                        'Details on the logging formats available')
 
794
topic_registry.register('url-special-chars', _load_from_file,
 
795
                        'Special character handling in URLs')
775
796
 
776
797
 
777
798
# Register concept topics.
836
857
            return []
837
858
 
838
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
 
839
869
class RegisteredTopic(object):
840
870
    """A help topic which has been registered in the HelpTopicRegistry.
841
871
 
859
889
            returned instead of plain text.
860
890
        """
861
891
        result = topic_registry.get_detail(self.topic)
862
 
        # there is code duplicated here and in bzrlib/plugin.py's
863
 
        # matching Topic code. This should probably be factored in
864
 
        # to a helper function and a common base class.
865
 
        if additional_see_also is not None:
866
 
            see_also = sorted(set(additional_see_also))
867
 
        else:
868
 
            see_also = None
869
 
        if see_also:
870
 
            result += '\n:See also: '
871
 
            result += ', '.join(see_also)
872
 
            result += '\n'
 
892
        result += _format_see_also(additional_see_also)
873
893
        if plain:
874
894
            result = help_as_plain_text(result)
 
895
        i18n.install()
 
896
        result = i18n.gettext_per_paragraph(result)
875
897
        return result
876
898
 
877
899
    def get_help_topic(self):
892
914
        elif line.endswith('::'):
893
915
            line = line[:-1]
894
916
        # Map :doc:`xxx-help` to ``bzr help xxx``
895
 
        line = re.sub(":doc:`(.+)-help`", r'``bzr help \1``', line)
 
917
        line = re.sub(":doc:`(.+?)-help`", r'``bzr help \1``', line)
896
918
        result.append(line)
897
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