comparison document_it.py @ 5:3464eda1af80

better formatting for command line
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 01 Aug 2011 21:54:31 -0700
parents 550f4b240e20
children 5a4c1339b2f9
comparison
equal deleted inserted replaced
4:550f4b240e20 5:3464eda1af80
12 jsbridge/README.txt https://developer.mozilla.org/en/JSbridge 12 jsbridge/README.txt https://developer.mozilla.org/en/JSbridge
13 mozmill/README.txt https://developer.mozilla.org/en/Mozmill 13 mozmill/README.txt https://developer.mozilla.org/en/Mozmill
14 mozmill/docs/ https://developer.mozilla.org/en/Mozmill/ 14 mozmill/docs/ https://developer.mozilla.org/en/Mozmill/
15 """ 15 """
16 16
17 import optparse
17 import os 18 import os
18 import sys 19 import sys
19 import urllib2 20 import urllib2
20 from optparse import OptionParser
21 21
22 # necessary imports 22 # necessary imports
23 try: 23 try:
24 import markdown 24 import markdown
25 except ImportError: 25 except ImportError:
26 raise ImportError("markdown is not installed, run (e.g.):\neasy_install Markdown") 26 raise ImportError("markdown is not installed, run (e.g.):\neasy_install Markdown")
27 27
28 #DEST='http://developer.mozilla.org/' 28 #DEST='http://developer.mozilla.org/'
29 DEST='https://developer-stage9.mozilla.org/' 29 DEST='https://developer-stage9.mozilla.org/jhammel'
30 DIR=os.path.dirname(os.path.abspath(__file__)) 30 DIR=os.path.dirname(os.path.abspath(__file__)) # XXX currently unused
31 README=['README.md', 'README.txt', 'README']
32 31
33 def find_readme(directory): 32 def find_readme(directory):
34 """find a README file in a directory""" 33 """find a README file in a directory"""
35 # XXX currently unused 34 # XXX currently unused
35 README=['README.md', 'README.txt', 'README']
36 for name in README: 36 for name in README:
37 path = os.path.join(directory, name) 37 path = os.path.join(directory, name)
38 if os.path.exists(path): 38 if os.path.exists(path):
39 return path 39 return path
40 40
45 """ 45 """
46 46
47 assert os.path.exists(filename) and os.path.isfile(filename) 47 assert os.path.exists(filename) and os.path.isfile(filename)
48 if directory is None: 48 if directory is None:
49 directory = os.path.dirname(os.path.abspath(filename)) 49 directory = os.path.dirname(os.path.abspath(filename))
50 lines = [line.strip() for file(filename).readlines()] 50 lines = [line.strip() for line in file(filename).readlines()]
51 lines = [line for line in lines 51 lines = [line for line in lines
52 if line and not line.startswith('#')] 52 if line and not line.startswith('#')]
53 items = [] 53 items = []
54 for line in lines: 54 for line in lines:
55 try: 55 try:
67 67
68 def main(args=sys.argv[1:]): 68 def main(args=sys.argv[1:]):
69 69
70 # parse command line options 70 # parse command line options
71 usage = '%prog [options] manifest <manifest> <...>' 71 usage = '%prog [options] manifest <manifest> <...>'
72 parser = OptionParser(usage=usage, description=__doc__) 72
73 # description formatter
74 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
75 def format_description(self, description):
76 if description:
77 return description + '\n'
78 else:
79 return ''
80
81 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter())
73 parser.add_option('-d', '--directory', dest='directory', 82 parser.add_option('-d', '--directory', dest='directory',
74 help='render the documentation to this directory') 83 help='render the documentation to this directory')
75 parser.add_option('--dest', dest='dest', 84 parser.add_option('--dest', dest='dest',
76 default=DEST, 85 default=DEST,
77 help='base URL of destination') 86 help='base URL of destination')
80 parser.add_option('--list', dest='list', action='store_true', 89 parser.add_option('--list', dest='list', action='store_true',
81 help="list packages") 90 help="list packages")
82 options, manifests = parser.parse_args(args) 91 options, manifests = parser.parse_args(args)
83 92
84 if not args: 93 if not args:
85 parser.print_usage() 94 parser.print_help()
86 parser.exit() 95 parser.exit()
87 96
88 # run setup_development.py in this directory 97 # run setup_development.py in this directory
89 # to ensure documentation is up to date 98 # to ensure documentation is up to date
90 # TODO; as yet unneeded 99 # TODO; as yet unneeded