Mercurial > cpython-lru_cache-weakref
annotate Lib/cmd.py @ 13163:a09e8635534d legacy-trunk
Don't try to guess the name of a .def file -- if one is supplied, use it,
otherwise just generate an '/export:' option.
| author | Greg Ward <gward@python.net> |
|---|---|
| date | Thu, 29 Jun 2000 23:09:20 +0000 |
| parents | e34991022571 |
| children | 1e7c32bddb8f |
| rev | line source |
|---|---|
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
1 """A generic class to build line-oriented command interpreters. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
2 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
3 Interpreters constructed with this class obey the following conventions: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
4 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
5 1. End of file on input is processed as the command 'EOF'. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
6 2. A command is parsed out of each line by collecting the prefix composed |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
7 of characters in the identchars member. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
8 3. A command `foo' is dispatched to a method 'do_foo()'; the do_ method |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
9 is passed a single argument consisting of the remainder of the line. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
10 4. Typing an empty line repeats the last command. (Actually, it calls the |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
11 method `emptyline', which may be overridden in a subclass.) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
12 5. There is a predefined `help' method. Given an argument `topic', it |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
13 calls the command `help_topic'. With no arguments, it lists all topics |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
14 with defined help_ functions, broken into up to three topics; documented |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
15 commands, miscellaneous help topics, and undocumented commands. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
16 6. The command '?' is a synonym for `help'. The command '!' is a synonym |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
17 for `shell', if a do_shell method exists. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
18 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
19 The `default' method may be overridden to intercept commands for which there |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
20 is no do_ method. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
21 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
22 The data member `self.ruler' sets the character used to draw separator lines |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
23 in the help messages. If empty, no ruler line is drawn. It defaults to "=". |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
24 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
25 If the value of `self.intro' is nonempty when the cmdloop method is called, |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
26 it is printed out on interpreter startup. This value may be overridden |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
27 via an optional argument to the cmdloop() method. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
28 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
29 The data members `self.doc_header', `self.misc_header', and |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
30 `self.undoc_header' set the headers used for the help function's |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
31 listings of documented functions, miscellaneous topics, and undocumented |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
32 functions respectively. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
33 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
34 These interpreters use raw_input; thus, if the readline module is loaded, |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
35 they automatically support Emacs-like command history and editing features. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
36 """ |
| 624 | 37 |
| 38 import string | |
| 39 | |
| 40 PROMPT = '(Cmd) ' | |
| 41 IDENTCHARS = string.letters + string.digits + '_' | |
| 42 | |
| 43 class Cmd: | |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
44 prompt = PROMPT |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
45 identchars = IDENTCHARS |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
46 ruler = '=' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
47 lastcmd = '' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
48 cmdqueue = [] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
49 intro = None |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
50 doc_leader = "" |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
51 doc_header = "Documented commands (type help <topic>):" |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
52 misc_header = "Miscellaneous help topics:" |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
53 undoc_header = "Undocumented commands:" |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
54 nohelp = "*** No help on %s" |
|
1315
acdc0b9a6c78
* aifc.py: don't die on invalid MARK chunk
Guido van Rossum <guido@python.org>
parents:
1086
diff
changeset
|
55 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
56 def __init__(self): pass |
|
8615
e7822b64a33d
Gotta have an __init__() method -- pdb.py calls it!
Guido van Rossum <guido@python.org>
parents:
8584
diff
changeset
|
57 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
58 def cmdloop(self, intro=None): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
59 self.preloop() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
60 if intro != None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
61 self.intro = intro |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
62 if self.intro: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
63 print self.intro |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
64 stop = None |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
65 while not stop: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
66 if self.cmdqueue: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
67 line = self.cmdqueue[0] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
68 del self.cmdqueue[0] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
69 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
70 try: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
71 line = raw_input(self.prompt) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
72 except EOFError: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
73 line = 'EOF' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
74 line = self.precmd(line) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
75 stop = self.onecmd(line) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
76 stop = self.postcmd(stop, line) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
77 self.postloop() |
|
8584
cb7fcfb56275
Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents:
8410
diff
changeset
|
78 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
79 def precmd(self, line): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
80 return line |
|
8584
cb7fcfb56275
Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents:
8410
diff
changeset
|
81 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
82 def postcmd(self, stop, line): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
83 return stop |
|
8584
cb7fcfb56275
Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents:
8410
diff
changeset
|
84 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
85 def preloop(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
86 pass |
|
8584
cb7fcfb56275
Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents:
8410
diff
changeset
|
87 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
88 def postloop(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
89 pass |
| 624 | 90 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
91 def onecmd(self, line): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
92 line = string.strip(line) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
93 if line == '?': |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
94 line = 'help' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
95 elif line == '!': |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
96 if hasattr(self, 'do_shell'): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
97 line = 'shell' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
98 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
99 return self.default(line) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
100 elif not line: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
101 return self.emptyline() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
102 self.lastcmd = line |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
103 i, n = 0, len(line) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
104 while i < n and line[i] in self.identchars: i = i+1 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
105 cmd, arg = line[:i], string.strip(line[i:]) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
106 if cmd == '': |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
107 return self.default(line) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
108 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
109 try: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
110 func = getattr(self, 'do_' + cmd) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
111 except AttributeError: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
112 return self.default(line) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
113 return func(arg) |
| 624 | 114 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
115 def emptyline(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
116 if self.lastcmd: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
117 return self.onecmd(self.lastcmd) |
|
8584
cb7fcfb56275
Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents:
8410
diff
changeset
|
118 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
119 def default(self, line): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
120 print '*** Unknown syntax:', line |
| 624 | 121 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
122 def do_help(self, arg): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
123 if arg: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
124 # XXX check arg syntax |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
125 try: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
126 func = getattr(self, 'help_' + arg) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
127 except: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
128 try: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
129 doc=getattr(self, 'do_' + arg).__doc__ |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
130 if doc: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
131 print doc |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
132 return |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
133 except: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
134 pass |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
135 print self.nohelp % (arg,) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
136 return |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
137 func() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
138 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
139 # Inheritance says we have to look in class and |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
140 # base classes; order is not important. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
141 names = [] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
142 classes = [self.__class__] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
143 while classes: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
144 aclass = classes[0] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
145 if aclass.__bases__: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
146 classes = classes + list(aclass.__bases__) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
147 names = names + dir(aclass) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
148 del classes[0] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
149 cmds_doc = [] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
150 cmds_undoc = [] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
151 help = {} |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
152 for name in names: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
153 if name[:5] == 'help_': |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
154 help[name[5:]]=1 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
155 names.sort() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
156 # There can be duplicates if routines overridden |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
157 prevname = '' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
158 for name in names: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
159 if name[:3] == 'do_': |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
160 if name == prevname: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
161 continue |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
162 prevname = name |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
163 cmd=name[3:] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
164 if help.has_key(cmd): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
165 cmds_doc.append(cmd) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
166 del help[cmd] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
167 elif getattr(self, name).__doc__: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
168 cmds_doc.append(cmd) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
169 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
170 cmds_undoc.append(cmd) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
171 print self.doc_leader |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
172 self.print_topics(self.doc_header, cmds_doc, 15,80) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
173 self.print_topics(self.misc_header, help.keys(),15,80) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
174 self.print_topics(self.undoc_header, cmds_undoc, 15,80) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
175 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
176 def print_topics(self, header, cmds, cmdlen, maxcol): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
177 if cmds: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
178 print header; |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
179 if self.ruler: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
180 print self.ruler * len(header) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
181 (cmds_per_line,junk)=divmod(maxcol,cmdlen) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
182 col=cmds_per_line |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
183 for cmd in cmds: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
184 if col==0: print |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
185 print (("%-"+`cmdlen`+"s") % cmd), |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
186 col = (col+1) % cmds_per_line |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
10820
diff
changeset
|
187 print "\n" |
