~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help_topics.py

  • Committer: Martin Pool
  • Date: 2005-09-30 05:56:05 UTC
  • mto: (1185.14.2)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: mbp@sourcefrog.net-20050930055605-a2c534529b392a7d
- fix upgrade for transport changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
"""A collection of extra help information for using bzr.
18
 
 
19
 
Help topics are meant to be help for items that aren't commands, but will
20
 
help bzr become fully learnable without referring to a tutorial.
21
 
"""
22
 
 
23
 
from bzrlib import registry
24
 
 
25
 
 
26
 
class HelpTopicRegistry(registry.Registry):
27
 
    """A Registry customized for handling help topics."""
28
 
 
29
 
    def register(self, topic, detail, summary):
30
 
        """Register a new help topic.
31
 
 
32
 
        :param topic: Name of documentation entry
33
 
        :param detail: Function or string object providing detailed
34
 
            documentation for topic.  Function interface is detail(topic).
35
 
            This should return a text string of the detailed information.
36
 
        :param summary: String providing single-line documentation for topic.
37
 
        """
38
 
        # The detail is stored as the 'object' and the 
39
 
        super(HelpTopicRegistry, self).register(topic, detail, info=summary)
40
 
 
41
 
    def register_lazy(self, topic, module_name, member_name, summary):
42
 
        """Register a new help topic, and import the details on demand.
43
 
 
44
 
        :param topic: Name of documentation entry
45
 
        :param module_name: The module to find the detailed help.
46
 
        :param member_name: The member of the module to use for detailed help.
47
 
        :param summary: String providing single-line documentation for topic.
48
 
        """
49
 
        super(HelpTopicRegistry, self).register_lazy(topic, module_name,
50
 
                                                     member_name, info=summary)
51
 
 
52
 
    def get_detail(self, topic):
53
 
        """Get the detailed help on a given topic."""
54
 
        obj = self.get(topic)
55
 
        if callable(obj):
56
 
            return obj(topic)
57
 
        else:
58
 
            return obj
59
 
 
60
 
    def get_summary(self, topic):
61
 
        """Get the single line summary for the topic."""
62
 
        return self.get_info(topic)
63
 
 
64
 
 
65
 
topic_registry = HelpTopicRegistry()
66
 
 
67
 
 
68
 
#----------------------------------------------------
69
 
 
70
 
def _help_on_topics(dummy):
71
 
    """Write out the help for topics to outfile"""
72
 
 
73
 
    topics = topic_registry.keys()
74
 
    lmax = max(len(topic) for topic in topics)
75
 
        
76
 
    out = []
77
 
    for topic in topics:
78
 
        summary = topic_registry.get_summary(topic)
79
 
        out.append("%-*s %s\n" % (lmax, topic, summary))
80
 
    return ''.join(out)
81
 
 
82
 
 
83
 
def _help_on_revisionspec(name):
84
 
    """"Write the summary help for all documented topics to outfile."""
85
 
    import bzrlib.revisionspec
86
 
 
87
 
    out = []
88
 
    out.append("\nRevision prefix specifier:"
89
 
               "\n--------------------------\n")
90
 
 
91
 
    for i in bzrlib.revisionspec.SPEC_TYPES:
92
 
        doc = i.help_txt
93
 
        if doc == bzrlib.revisionspec.RevisionSpec.help_txt:
94
 
            doc = "N/A\n"
95
 
        while (doc[-2:] == '\n\n' or doc[-1:] == ' '):
96
 
            doc = doc[:-1]
97
 
 
98
 
        out.append("  %s %s\n\n" % (i.prefix, doc))
99
 
 
100
 
    return ''.join(out)
101
 
 
102
 
 
103
 
_basic_help= \
104
 
"""Bazaar -- a free distributed version-control tool
105
 
http://bazaar-vcs.org/
106
 
 
107
 
Basic commands:
108
 
  bzr init           makes this directory a versioned branch
109
 
  bzr branch         make a copy of another branch
110
 
 
111
 
  bzr add            make files or directories versioned
112
 
  bzr ignore         ignore a file or pattern
113
 
  bzr mv             move or rename a versioned file
114
 
 
115
 
  bzr status         summarize changes in working copy
116
 
  bzr diff           show detailed diffs
117
 
 
118
 
  bzr merge          pull in changes from another branch
119
 
  bzr commit         save some or all changes
120
 
 
121
 
  bzr log            show history of changes
122
 
  bzr check          validate storage
123
 
 
124
 
  bzr help init      more help on e.g. init command
125
 
  bzr help commands  list all commands
126
 
  bzr help topics    list all help topics
127
 
"""
128
 
 
129
 
 
130
 
_global_options =\
131
 
"""Global Options
132
 
 
133
 
These options may be used with any command, and may appear in front of any
134
 
command.  (e.g. "bzr --quiet help").
135
 
 
136
 
--quiet        Suppress informational output; only print errors and warnings
137
 
--version      Print the version number
138
 
 
139
 
--no-aliases   Do not process command aliases when running this command
140
 
--builtin      Use the built-in version of a command, not the plugin version.
141
 
               This does not suppress other plugin effects
142
 
--no-plugins   Do not process any plugins
143
 
 
144
 
-Derror        Instead of normal error handling, always print a traceback on
145
 
               error.
146
 
--profile      Profile execution using the hotshot profiler
147
 
--lsprof       Profile execution using the lsprof profiler
148
 
--lsprof-file  Profile execution using the lsprof profiler, and write the
149
 
               results to a specified file.
150
 
 
151
 
Note: --version must be supplied before any command.
152
 
"""
153
 
 
154
 
_checkouts = \
155
 
"""Checkouts
156
 
 
157
 
Checkouts are source trees that are connected to a branch, so that when
158
 
you commit in the source tree, the commit goes into that branch.  They
159
 
allow you to use a simpler, more centralized workflow, ignoring some of
160
 
Bazaar's decentralized features until you want them. Using checkouts
161
 
with shared repositories is very similar to working with SVN or CVS, but
162
 
doesn't have the same restrictions.  And using checkouts still allows
163
 
others working on the project to use whatever workflow they like.
164
 
 
165
 
A checkout is created with the bzr checkout command (see "help checkout").
166
 
You pass it a reference to another branch, and it will create a local copy
167
 
for you that still contains a reference to the branch you created the
168
 
checkout from (the master branch). Then if you make any commits they will be
169
 
made on the other branch first. This creates an instant mirror of your work, or
170
 
facilitates lockstep development, where each developer is working together,
171
 
continuously integrating the changes of others.
172
 
 
173
 
However the checkout is still a first class branch in Bazaar terms, so that
174
 
you have the full history locally.  As you have a first class branch you can
175
 
also commit locally if you want, for instance due to the temporary loss af a
176
 
network connection. Use the --local option to commit to do this. All the local
177
 
commits will then be made on the master branch the next time you do a non-local
178
 
commit.
179
 
 
180
 
If you are using a checkout from a shared branch you will periodically want to
181
 
pull in all the changes made by others. This is done using the "update"
182
 
command. The changes need to be applied before any non-local commit, but
183
 
Bazaar will tell you if there are any changes and suggest that you use this
184
 
command when needed.
185
 
 
186
 
It is also possible to create a "lightweight" checkout by passing the
187
 
--lightweight flag to checkout. A lightweight checkout is even closer to an
188
 
SVN checkout in that it is not a first class branch, it mainly consists of the
189
 
working tree. This means that any history operations must query the master
190
 
branch, which could be slow if a network connection is involved. Also, as you
191
 
don't have a local branch, then you cannot commit locally.
192
 
 
193
 
Lightwieght checkouts work best when you have fast reliable access to the
194
 
master branch. This means that if the master branch is on the same disk or LAN
195
 
a lightweight checkout will be faster than a heavyweight one for any commands
196
 
that modify the revision history (as only one copy branch needs to be updated).
197
 
Heavyweight checkouts will generally be faster for any command that uses the
198
 
history but does not change it, but if the master branch is on the same disk
199
 
then there wont be a noticeable difference.
200
 
 
201
 
Another possible use for a checkout is to use it with a treeless repository
202
 
containing your branches, where you maintain only only one working tree by
203
 
switching the master branch that the checkout points to when you want to 
204
 
work on a different branch.
205
 
 
206
 
Obviously to commit on a checkout you need to be able to write to the master
207
 
branch. This means that the master branch must be accessable over a writeable
208
 
protocol , such as sftp://, and that you have write permissions at the other
209
 
end. Checkouts also work on the local file system, so that all that matters is
210
 
file permissions.
211
 
 
212
 
You can change the master of a checkout by using the "bind" command (see "help
213
 
bind"). This will change the location that the commits are sent to. The bind
214
 
command can also be used to turn a branch into a heavy checkout. If you
215
 
would like to convert your heavy checkout into a normal branch so that every
216
 
commit is local, you can use the "unbind" command.
217
 
 
218
 
Related commands:
219
 
 
220
 
  checkout    Create a checkout. Pass --lightweight to get a lightweight
221
 
              checkout
222
 
  update      Pull any changes in the master branch in to your checkout
223
 
  commit      Make a commit that is sent to the master branch. If you have
224
 
              a heavy checkout then the --local option will commit to the 
225
 
              checkout without sending the commit to the master
226
 
  bind        Change the master branch that the commits in the checkout will
227
 
              be sent to
228
 
  unbind      Turn a heavy checkout into a standalone branch so that any
229
 
              commits are only made locally
230
 
"""
231
 
 
232
 
 
233
 
topic_registry.register("revisionspec", _help_on_revisionspec,
234
 
                        "Explain how to use --revision")
235
 
topic_registry.register('basic', _basic_help, "Basic commands")
236
 
topic_registry.register('topics', _help_on_topics, "Topics list")
237
 
def get_format_topic(topic):
238
 
    from bzrlib import bzrdir
239
 
    return bzrdir.format_registry.help_topic(topic)
240
 
topic_registry.register('formats', get_format_topic, 'Directory formats')
241
 
topic_registry.register('global-options', _global_options,
242
 
                        'Options that can be used with any command')
243
 
topic_registry.register('checkouts', _checkouts,
244
 
                        'Information on what a checkout is')
245