forked from reingart/pymotw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
motw
executable file
·65 lines (56 loc) · 1.68 KB
/
motw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2009 Doug Hellmann All rights reserved.
#
"""
"""
#end_pymotw_header
import optparse
import sys
import PyMOTW
def main(args):
try:
_main(args)
except Exception, err:
sys.stderr.write(str(err))
sys.stderr.write('\n')
return 1
return 0
OUTPUT_HANDLERS = {
'text':PyMOTW.show_text,
'html':PyMOTW.show_html,
'web':PyMOTW.show_webpage,
}
def _main(args):
parser = optparse.OptionParser(
usage='usage: %prog [options] <module_name>',
)
parser.add_option('-t', '--text',
help="Print plain-text version of help to stdout",
action='store_const',
const='text',
dest='mode',
)
parser.add_option('-w', '--web',
help="Open HTML version of help from web",
action='store_const',
const='web',
dest='mode',
)
parser.add_option('--html',
help="Open HTML version of help from installed file",
action='store_const',
const='html',
dest='mode',
default='html',
)
options, args = parser.parse_args(args)
if len(args) != 1:
raise ValueError('Please provide the name of exactly one module from the Python standard library.')
module_name = args[0]
handler = OUTPUT_HANDLERS[options.mode]
handler(module_name)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))