Merge lp:~thumper/juju-core/man-page into lp:~juju/juju-core/trunk

Proposed by Tim Penhey
Status: Merged
Approved by: William Reade
Approved revision: no longer in the source branch.
Merged at revision: 1104
Proposed branch: lp:~thumper/juju-core/man-page
Merge into: lp:~juju/juju-core/trunk
Diff against target: 233 lines (+224/-0)
2 files modified
scripts/generate-docs.py (+64/-0)
scripts/jujuman.py (+160/-0)
To merge this branch: bzr merge lp:~thumper/juju-core/man-page
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+156728@code.launchpad.net

Description of the change

Add a python script to generate the man page.

To generate a man page locally, first build and install juju (as the python
script calls juju to get the information), then run
  ./scripts/generate-docs.py man

This will create a local juju.1 file. You can use man to look at this by:
  man ./juju.1

To make the gzipped one installed in the right place:
  ./scripts/generate-docs.py man -o - | gzip | sudo tee /usr/share/man/man1/juju.1.gz > /dev/null

There is probably an easier way, but I couldn't figure it out, and gave up looking.

https://codereview.appspot.com/8300043/

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Reviewers: mp+156728_code.launchpad.net,

Message:
Please take a look.

Description:
Add a python script to generate the man page.

To generate a man page locally, first build and install juju (as the
python
script calls juju to get the information), then run
   ./scripts/generate-docs.py man

This will create a local juju.1 file. You can use man to look at this
by:
   man ./juju.1

To make the gzipped one installed in the right place:
   ./scripts/generate-docs.py man -o - | gzip | sudo tee
/usr/share/man/man1/juju.1.gz > /dev/null

There is probably an easier way, but I couldn't figure it out, and gave
up looking.

https://code.launchpad.net/~thumper/juju-core/man-page/+merge/156728

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/8300043/

Affected files:
   A [revision details]
   A scripts/generate-docs.py
   A scripts/jujuman.py
   M version/current_test.go
   M version/version.go

Revision history for this message
Tim Penhey (thumper) wrote :
Revision history for this message
Dimiter Naydenov (dimitern) wrote :

LGTM, nice!

Please link it to lp:1160097, as Dave suggests.

https://codereview.appspot.com/8300043/

Revision history for this message
Tim Penhey (thumper) wrote :

*** Submitted:

Add a python script to generate the man page.

To generate a man page locally, first build and install juju (as the
python
script calls juju to get the information), then run
   ./scripts/generate-docs.py man

This will create a local juju.1 file. You can use man to look at this
by:
   man ./juju.1

To make the gzipped one installed in the right place:
   ./scripts/generate-docs.py man -o - | gzip | sudo tee
/usr/share/man/man1/juju.1.gz > /dev/null

There is probably an easier way, but I couldn't figure it out, and gave
up looking.

R=
CC=
https://codereview.appspot.com/8300043

https://codereview.appspot.com/8300043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'scripts/generate-docs.py'
2--- scripts/generate-docs.py 1970-01-01 00:00:00 +0000
3+++ scripts/generate-docs.py 2013-04-03 03:09:22 +0000
4@@ -0,0 +1,64 @@
5+#!/usr/bin/env python
6+
7+# Copyright 2013 Canonical Ltd.
8+
9+import os
10+import sys
11+from optparse import OptionParser
12+
13+from jujuman import JujuMan
14+
15+
16+GENERATORS = {
17+ 'man': JujuMan
18+}
19+
20+# Insert the directory that this module is in into the python path.
21+sys.path.insert(0, (os.path.dirname(__file__)))
22+
23+def main(argv):
24+ parser = OptionParser(usage="""%prog [options] OUTPUT_FORMAT
25+
26+Available OUTPUT_FORMAT:
27+
28+ man man page
29+
30+And that is all for now.""")
31+
32+ parser.add_option("-s", "--show-filename",
33+ action="store_true", dest="show_filename", default=False,
34+ help="print default filename on stdout")
35+
36+ parser.add_option("-o", "--output", dest="filename", metavar="FILE",
37+ help="write output to FILE")
38+
39+ (options, args) = parser.parse_args(argv)
40+
41+ if len(args) != 2:
42+ parser.print_help()
43+ sys.exit(1)
44+
45+ try:
46+ doc_generator = GENERATORS[args[1]]()
47+ except KeyError as e:
48+ sys.stderr.write("Unknown documentation generator %r\n" % e.message)
49+ sys.exit(1)
50+
51+ if options.filename:
52+ outfilename = options.filename
53+ else:
54+ outfilename = doc_generator.get_filename(options)
55+
56+ if outfilename == "-":
57+ outfile = sys.stdout
58+ else:
59+ outfile = open(outfilename, "w")
60+ if options.show_filename and (outfilename != "-"):
61+ sys.stdout.write(outfilename)
62+ sys.stdout.write('\n')
63+
64+ doc_generator.write_documentation(options, outfile)
65+
66+
67+if __name__ == "__main__":
68+ main(sys.argv)
69
70=== added file 'scripts/jujuman.py'
71--- scripts/jujuman.py 1970-01-01 00:00:00 +0000
72+++ scripts/jujuman.py 2013-04-03 03:09:22 +0000
73@@ -0,0 +1,160 @@
74+"""Functions for generating the manpage using the juju command."""
75+
76+import subprocess
77+import textwrap
78+import time
79+
80+
81+class JujuMan(object):
82+
83+ def __init__(self):
84+ self.version = self._version()
85+
86+ def get_filename(self, options):
87+ """Provides name of manpage"""
88+ return 'juju.1'
89+
90+ def run_juju(self, *args):
91+ cmd = ['juju'] + list(args)
92+ return subprocess.check_output(cmd).strip()
93+
94+ def _version(self):
95+ juju_version = self.run_juju('version')
96+ return juju_version.split('-')[0]
97+
98+ def commands(self):
99+ commands = self.run_juju('help', 'commands')
100+ result = []
101+ for line in commands.split('\n'):
102+ name, short_help = line.split(' ', 1)
103+ if 'alias for' in short_help:
104+ continue
105+ result.append((name, short_help.strip()))
106+ return result
107+
108+ def write_documentation(self, options, outfile):
109+ """Assembles a man page"""
110+ t = time.time()
111+ tt = time.gmtime(t)
112+ params = {
113+ "cmd": "juju",
114+ "datestamp": time.strftime("%Y-%m-%d",tt),
115+ "timestamp": time.strftime("%Y-%m-%d %H:%M:%S +0000",tt),
116+ "version": self.version,
117+ }
118+ outfile.write(man_preamble % params)
119+ outfile.write(man_escape(man_head % params))
120+ outfile.write(man_escape(self.getcommand_list(params)))
121+ outfile.write("".join(environment_variables()))
122+ outfile.write(man_escape(man_foot % params))
123+
124+ def getcommand_list(self, params):
125+ """Builds summary help for command names in manpage format"""
126+ output = '.SH "COMMAND OVERVIEW"\n'
127+ for cmd_name, short_help in self.commands():
128+ tmp = '.TP\n.B "%s %s"\n%s\n' % (params['cmd'], cmd_name, short_help)
129+ output = output + tmp
130+ return output
131+
132+
133+ENVIRONMENT = (
134+ ('JUJU_ENV', textwrap.dedent("""\
135+ Provides a way for the shell environment to specify the current Juju
136+ environment to use. If the environment is specified explicitly using
137+ -e ENV, this takes precedence.
138+ """)),
139+ ('JUJU_HOME', textwrap.dedent("""\
140+ Overrides the default Juju configuration directory of ~/.juju.
141+ """)),
142+ ('AWS_ACCESS_KEY_ID', textwrap.dedent("""\
143+ The access-key for your AWS account.
144+ """)),
145+ ('AWS_SECRET_ACCESS_KEY', textwrap.dedent("""\
146+ The secret-key for your AWS account.
147+ """)),
148+ ('OS_USERNAME', textwrap.dedent("""\
149+ Your openstack username.
150+ """)),
151+ ('OS_PASSWORD', textwrap.dedent("""\
152+ Your openstack password.
153+ """)),
154+ ('OS_TENANT_NAME', textwrap.dedent("""\
155+ Your openstack tenant name.
156+ """)),
157+ ('OS_REGION_NAME', textwrap.dedent("""\
158+ Your openstack region name.
159+ """)),
160+)
161+
162+def man_escape(string):
163+ """Escapes strings for man page compatibility"""
164+ result = string.replace("\\","\\\\")
165+ result = result.replace("`","\\'")
166+ result = result.replace("'","\\*(Aq")
167+ result = result.replace("-","\\-")
168+ return result
169+
170+
171+def environment_variables():
172+ yield ".SH \"ENVIRONMENT\"\n"
173+
174+ for k, desc in ENVIRONMENT:
175+ yield ".TP\n"
176+ yield ".I \"%s\"\n" % k
177+ yield man_escape(desc) + "\n"
178+
179+
180+man_preamble = """\
181+.\\\"Man page for Juju (%(cmd)s)
182+.\\\"
183+.\\\" Large parts of this file are autogenerated from the output of
184+.\\\" \"%(cmd)s help commands\"
185+.\\\" \"%(cmd)s help <cmd>\"
186+.\\\"
187+.\\\" Generation time: %(timestamp)s
188+.\\\"
189+
190+.ie \\n(.g .ds Aq \\(aq
191+.el .ds Aq '
192+"""
193+
194+man_head = """\
195+.TH %(cmd)s 1 "%(datestamp)s" "%(version)s" "Juju"
196+.SH "NAME"
197+%(cmd)s - Juju -- devops distilled
198+.SH "SYNOPSIS"
199+.B "%(cmd)s"
200+.I "command"
201+[
202+.I "command_options"
203+]
204+.br
205+.B "%(cmd)s"
206+.B "help"
207+.br
208+.B "%(cmd)s"
209+.B "help"
210+.I "command"
211+.SH "DESCRIPTION"
212+
213+Juju provides easy, intelligent service orchestration on top of environments
214+such as OpenStack, Amazon AWS, or bare metal.
215+"""
216+
217+man_foot = """\
218+.SH "FILES"
219+.TP
220+.I "~/.juju/environments.yaml"
221+This is the Juju config file, which you can use to specify multiple
222+environments in which to deploy.
223+
224+A config file can be created using
225+.B juju init -w
226+which you can then edit to provide the secret keys, or use environment
227+variables to provide the secret values.
228+
229+.SH "SEE ALSO"
230+.UR https://juju.ubuntu.com/
231+.BR https://juju.ubuntu.com/
232+"""
233+

Subscribers

People subscribed via source and target branches