-
Notifications
You must be signed in to change notification settings - Fork 3
/
rpcdoc
executable file
·167 lines (133 loc) · 4.99 KB
/
rpcdoc
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
#!/usr/bin/env python3
from datetime import datetime
import sys
import argparse
import reflectrpc
import reflectrpc.cmdline
def format_type(typename):
if not len(typename):
return typename
if typename[0].isupper():
return '<a href="#type-%s">%s</a>' % (typename, typename)
elif typename.startswith('array<'):
subtypename = typename[len('array<'):-1]
return 'array<%s>' % (format_type(subtypename))
return typename
parser = reflectrpc.cmdline.build_cmdline_parser("Generate documentation from a running ReflectRPC service")
# Add our program-specific arguments
parser.add_argument("outfile", metavar='OUTFILE', type=str, help="Output file")
args = parser.parse_args()
client = reflectrpc.cmdline.connect_client(parser, args)
client.enable_auto_reconnect()
(service_description, functions, custom_types) = reflectrpc.cmdline.fetch_service_metainfo(client)
f = open(args.outfile, "w")
style = """
<style type="text/css">
body {
font-family: Verdana, Geneva, sans-serif;
margin: 3em;
}
a {
color: #4078c0;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: underline;
}
h1 {
border-bottom: 1px solid #ddd;
}
h2 {
border-bottom: 1px solid #ddd;
}
h3 {
margin-bottom: 0;
}
.description {
color: #888;
}
.typename {
font-style:italic;
}
table.withborders {
border-spacing: 0;
border-top: 1px solid #ddd;
border-right: 1px solid #ddd;
}
table.withborders th {
border-left: 1px solid #ddd;
border-bottom: 1px solid #ddd;
padding: 0.5em;
background-color: #eee;
}
table.withborders td {
border-left: 1px solid #ddd;
border-bottom: 1px solid #ddd;
padding: 0.5em;
}
</style>
"""
title = service_description['name'] + ' - ReflectRPC Service Documentation'
f.write('<!DOCTYPE html>\n')
f.write('<html>\n<head>\n<meta charset="UTF-8">\n')
f.write('<title>%s</title>\n%s</head>\n<body>\n' % (title, style))
f.write('<h1>ReflectRPC Service Documentation</h1>\n')
f.write('<table>')
f.write('<tr><td>Service Name:</td><td>%s</td></tr>\n' % (service_description['name']))
f.write('<tr><td>Version:</td><td>%s</td></tr>\n' % (service_description['version']))
f.write('<tr><td>Description:</td><td>%s</td></tr>\n' % (service_description['description']))
f.write('<tr><td> </td><td> </td></tr>\n')
if args.host.startswith('unix://'):
f.write('<tr><td>Generated from:</td><td>%s</td></tr>\n' % (args.host))
else:
f.write('<tr><td>Generated from:</td><td>%s:%d</td></tr>\n' % (args.host, args.port))
f.write('<tr><td>Generated at:</td><td>%s (UTC)</td></tr>\n' % (str(datetime.utcnow().replace(microsecond=0))))
f.write('<tr><td>Generated by:</td><td>ReflectRPC (rpcdoc) %s</td></tr>\n' % (reflectrpc.version))
f.write('</table>')
f.write('<h2>Types</h2>\n')
for t in custom_types:
if t['type'] == 'enum':
f.write('<a name="type-%s"></a>\n' % (t['name']))
f.write('<h3>%s (Enum)</h3>\n' % (t['name']))
f.write('<div class="description">%s</div>\n' % (t['description']))
f.write('<p>Enum values:</p>')
f.write('<table class="withborders">')
f.write('<tr><th>Int value</th><th>String value</th><th>Description</th></tr>')
for value in t['values']:
f.write('<tr><td>%d</td><td>%s</td><td>%s</td></tr>\n' % (value['intvalue'], value['name'], value['description']))
f.write('</table>')
elif t['type'] == 'hash':
f.write('<a name="type-%s"></a>\n' % (t['name']))
f.write('<h3>%s (Named Hash)</h3>\n' % (t['name']))
f.write('<div class="description">%s</div>\n' % (t['description']))
f.write('<p>Fields of this type:</p>')
f.write('<table class="withborders">')
f.write('<tr><th>Name</th><th>Type</th><th>Description</th></tr>')
for field in t['fields']:
f.write('<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n' % (field['name'], format_type(field['type']), field['description']))
f.write('</table>')
else:
f.write('<p>Unknown class of custom type: %s</p>\n' % (t['type']))
f.write('<h2>Functions</h2>\n')
for func_desc in functions:
paramlist = [param['name'] for param in func_desc['params']]
paramlist = ', '.join(paramlist)
f.write('<a name="func-%s"></a>\n' % (func_desc['name']))
f.write("<h3>%s</h3>\n" % (func_desc['name']))
f.write('<div class="description">%s(%s) - %s</div>' % (func_desc['name'], paramlist, func_desc['description']))
f.write('<p>Parameters:</p>')
f.write('<table>')
for param in func_desc['params']:
f.write('<tr><td>%s:</td><td><div class="typename">%s</div></td><td>-</td><td class="description">%s</td></tr>\n' % (param['name'], format_type(param['type']), param['description']))
f.write('</table>')
f.write('<p>Returns: <span class="typename">%s</span> - <span class="description">%s</span></p>\n' % (format_type(func_desc['result_type']), func_desc['result_desc']))
f.write('</body>\n</html>')
f.close()