forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jujuman.py
181 lines (157 loc) · 5.06 KB
/
jujuman.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# Copyright 2013 Canonical Ltd.
# Licensed under the AGPLv3, see LICENCE file for details.
"""Functions for generating the manpage using the juju command."""
import subprocess
import textwrap
import time
class JujuMan(object):
def __init__(self):
self.version = self._version()
def get_filename(self, options):
"""Provides name of manpage"""
return 'juju.1'
def run_juju(self, *args):
cmd = ['juju'] + list(args)
return subprocess.check_output(cmd).strip().decode('utf-8')
def _version(self):
juju_version = self.run_juju('version')
return juju_version.split('-')[0]
def commands(self):
commands = self.run_juju('help', 'commands')
result = []
for line in commands.split('\n'):
name, short_help = line.split(' ', 1)
if 'alias for' in short_help:
continue
result.append((name, short_help.strip()))
return result
def write_documentation(self, options, outfile):
"""Assembles a man page"""
t = time.time()
tt = time.gmtime(t)
params = {
"cmd": "juju",
"datestamp": time.strftime("%Y-%m-%d",tt),
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S +0000",tt),
"version": self.version,
}
outfile.write(man_preamble % params)
outfile.write(man_escape(man_head % params))
outfile.write(man_escape(self.getcommand_list(params)))
outfile.write("".join(environment_variables()))
outfile.write(man_escape(man_foot % params))
def getcommand_list(self, params):
"""Builds summary help for command names in manpage format"""
output = '.SH "COMMAND OVERVIEW"\n'
for cmd_name, short_help in self.commands():
tmp = '.TP\n.B "%s %s"\n%s\n' % (params['cmd'], cmd_name, short_help)
output = output + tmp
return output
ENVIRONMENT = (
('JUJU_MODEL', textwrap.dedent("""\
Provides a way for the shell environment to specify the current Juju
model to use. If the model is specified explicitly using
-m MODEL, this takes precedence.
""")),
('JUJU_DATA', textwrap.dedent("""\
Overrides the default Juju configuration directory of $XDG_DATA_HOME/juju or ~/.local/share/juju
if $XDG_DATA_HOME is not defined.
""")),
('AWS_ACCESS_KEY_ID', textwrap.dedent("""\
The access-key for your AWS account.
""")),
('AWS_SECRET_ACCESS_KEY', textwrap.dedent("""\
The secret-key for your AWS account.
""")),
('OS_USERNAME', textwrap.dedent("""\
Your OpenStack username.
""")),
('OS_PASSWORD', textwrap.dedent("""\
Your OpenStack password.
""")),
('OS_TENANT_NAME', textwrap.dedent("""\
Your OpenStack tenant name.
""")),
('OS_REGION_NAME', textwrap.dedent("""\
Your OpenStack region name.
""")),
)
def man_escape(string):
"""Escapes strings for man page compatibility"""
result = string.replace("\\","\\\\")
result = result.replace("`","\\'")
result = result.replace("'","\\*(Aq")
result = result.replace("-","\\-")
return result
def environment_variables():
yield ".SH \"ENVIRONMENT\"\n"
for k, desc in ENVIRONMENT:
yield ".TP\n"
yield ".I \"%s\"\n" % k
yield man_escape(desc) + "\n"
man_preamble = """\
.\\\"Man page for Juju (%(cmd)s)
.\\\"
.\\\" Large parts of this file are autogenerated from the output of
.\\\" \"%(cmd)s help commands\"
.\\\" \"%(cmd)s help <cmd>\"
.\\\"
.\\\" Generation time: %(timestamp)s
.\\\"
.ie \\n(.g .ds Aq \\(aq
.el .ds Aq '
"""
man_head = """\
.TH %(cmd)s 1 "%(datestamp)s" "%(version)s" "Juju"
.SH "NAME"
%(cmd)s - Juju -- devops distilled
.SH "SYNOPSIS"
.B "%(cmd)s"
.I "command"
[
.I "command_options"
]
.br
.B "%(cmd)s"
.B "help"
.br
.B "%(cmd)s"
.B "help"
.I "command"
.SH "DESCRIPTION"
Juju is model & service management software designed to leverage the power
of existing resource pools, particularly cloud-based ones. It has built-in
support for cloud providers such as Amazon EC2, Google GCE, Microsoft Azure,
OpenStack, and Rackspace. It also works very well with MAAS and LXD.
"""
man_foot = """\
.SH "FILES"
.TP
.I "~/.local/share/juju/accounts.yaml"
Records the current authorised Juju users and their
passwords.
.TP
.I "~/.local/share/juju/bootstrap-config.yaml"
Records any configuration values which were used in the
creation of running controllers.
.TP
.I "~/.local/share/juju/clouds.yaml"
Records any user-specified clouds which have been
added to Juju.
.TP
.I "~/.local/share/juju/controllers.yaml"
Records all the running controllers, their UUIDS,
api-endpoints and CA certificates.
.TP
.I "~/.local/share/juju/credentials.yaml"
Records all the cloud credentials known to Juju.
.TP
.I "~/.local/share/juju/models.yaml"
Records the UUIDs of all models known to Juju.
.TP
.I "~/.local/share/juju/ssh/"
A directory containing the SSH credentials for the Juju client.
.SH "SEE ALSO"
.UR https://juju.is/docs/olm
.BR https://juju.is/docs/olm
"""