~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzr_man.py

  • Committer: John Arbash Meinel
  • Date: 2005-11-08 18:36:26 UTC
  • mto: This revision was merged to the branch mainline in revision 1727.
  • Revision ID: john@arbash-meinel.com-20051108183626-71f8414338043265
Updating unified_diff to take a factory, using the new diff algorithm in the code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
import os, sys
23
23
 
24
 
try:
25
 
    version_info = sys.version_info
26
 
except AttributeError:
27
 
    version_info = 1, 5 # 1.5 or older
28
 
 
29
 
 
30
 
REINVOKE = "__BZR_REINVOKE"    
31
 
NEED_VERS = (2, 3)
32
 
 
33
 
if version_info < NEED_VERS:
34
 
    if not os.environ.has_key(REINVOKE):
35
 
        # mutating os.environ doesn't work in old Pythons
36
 
        os.putenv(REINVOKE, "1")
37
 
        for python in 'python2.4', 'python2.3':
38
 
            try:
39
 
                os.execvp(python, [python] + sys.argv)
40
 
            except OSError:
41
 
                pass
42
 
    print >>sys.stderr, "bzr-man.py: error: cannot find a suitable python interpreter"
43
 
    print >>sys.stderr, "  (need %d.%d or later)" % NEED_VERS
44
 
    sys.exit(1)
45
 
if hasattr(os, "unsetenv"):
46
 
    os.unsetenv(REINVOKE)
47
 
 
48
24
import bzrlib, bzrlib.help
49
25
 
50
26
#>>> code taken from bzr (C) Canonical
91
67
 
92
68
    def parse_line(self, line):
93
69
        m = self.usage_exp.match(line)
 
70
        if line == '':
 
71
                return
94
72
        if m:
95
73
            if self.state == 0:
96
74
                if self.usage:
97
75
                    self.command_usage.append((self.command,self.usage,self.descr))
98
76
                    self.all_commands.append(self.command)
99
 
                self.usage = line
 
77
                self.usage = " ".join(line.split(" ")[1:])
100
78
                self.command = m.groups()[0]
101
79
            else:
102
 
                raise Error, "matching usage line in state %d" % state
 
80
                raise RuntimeError, "matching usage line in state %d" % state
103
81
            self.state = 1
104
82
            return
105
83
        m = self.descr_exp.match(line)
107
85
            if self.state == 1:
108
86
                self.descr = m.groups()[0]
109
87
            else:
110
 
                raise Error, "matching descr line in state %d" % state
 
88
                raise RuntimeError, "matching descr line in state %d" % state
111
89
            self.state = 0
112
90
            return
113
 
        raise Error, "Cannot parse this line"
 
91
        raise RuntimeError, "Cannot parse this line ('%s')." % line
114
92
 
115
93
    def end_parse(self):
116
94
        if self.state == 0:
118
96
                self.command_usage.append((self.command,self.usage,self.descr))
119
97
                self.all_commands.append(self.command)
120
98
        else:
121
 
            raise Error, "ending parse in state %d" % state
 
99
            raise RuntimeError, "ending parse in state %d" % state
122
100
 
123
101
    def write_to_manpage(self, outfile):
124
102
        bzrcmd = self.params["bzrcmd"]
125
103
        outfile.write('.SH "COMMAND OVERVIEW"\n')
126
104
        for (command,usage,descr) in self.command_usage:
127
 
            outfile.write('.TP\n.B "%s %s"\n%s\n\n' % (bzrcmd, usage, descr))
 
105
            outfile.write('.TP\n.B "%s %s"\n%s\n' % (bzrcmd, usage, descr))
128
106
 
129
107
 
130
108
class HelpReader:
194
172
Path where
195
173
.B "%(bzrcmd)s"
196
174
is to look for external command.
197
 
 
198
175
.TP
199
176
.I "BZREMAIL"
200
177
E-Mail address of the user. Overrides
202
179
.IR "EMAIL" .
203
180
Example content:
204
181
.I "John Doe <john@example.com>"
205
 
 
206
182
.TP
207
183
.I "EMAIL"
208
184
E-Mail address of the user. Overridden by the content of the file
209
185
.I "~/.bzr.conf/email"
210
186
and of the environment variable
211
187
.IR "BZREMAIL" .
212
 
 
213
188
.SH "FILES"
214
189
.TP
215
190
.I "~/.bzr.conf/"
220
195
.I "EMAIL"
221
196
environment variable. Example content:
222
197
.I "John Doe <john@example.com>"
223
 
 
224
198
.SH "SEE ALSO"
225
199
.UR http://www.bazaar-ng.org/
226
200
.BR http://www.bazaar-ng.org/,