forked from aws/aws-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtmlgen
More file actions
executable file
·111 lines (96 loc) · 3.86 KB
/
htmlgen
File metadata and controls
executable file
·111 lines (96 loc) · 3.86 KB
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
#!/usr/bin/env python
import os
import sys
import json
import argparse
import awscli.clidriver
from awscli.help import HelpRenderer
REF_PATH = 'reference'
TUT_PATH = 'tutorial'
class FileRenderer(HelpRenderer):
def __init__(self, file_path):
self._file_path = file_path
def render(self, contents):
fp = open(self._file_path, 'wb')
fp.write(contents)
fp.close()
def do_operation(driver, service_path, operation_name, operation_command):
file_path = os.path.join(service_path,
operation_name + '.rst')
help_command = operation_command.create_help_command()
if help_command is None:
# Do not document anything that does not have a help command.
return
help_command.doc.target = 'html'
help_command.renderer = FileRenderer(file_path)
help_command(None, None)
def do_service(driver, ref_path, service_name, service_command):
print('...%s' % service_name)
service_path = os.path.join(ref_path, service_name)
if not os.path.isdir(service_path):
os.mkdir(service_path)
index_path = os.path.join(service_path, 'index.rst')
help_command = service_command.create_help_command()
if help_command is None:
# Do not document anything that does not have a help command.
return
help_command.doc.target = 'html'
help_command.renderer = FileRenderer(index_path)
help_command(None, None)
for operation_name in help_command.command_table:
if operation_name == 'help':
continue
operation_command = help_command.command_table[operation_name]
do_operation(driver, service_path, operation_name, operation_command)
def do_provider(driver):
help_command = driver.create_help_command()
help_command.doc.target = 'html'
help_command.renderer = FileRenderer(os.path.join(REF_PATH, 'index.rst'))
help_command(None, None)
services = sorted(help_command.command_table)
for service_name in services:
if service_name == 'help':
continue
service_command = help_command.command_table[service_name]
do_service(driver, REF_PATH, service_name, service_command)
def build_service_list(tut_path, ref_path, driver):
file_path = os.path.join(tut_path, 'services.rst')
fp = open(file_path, 'w')
fp.write('\n')
l = []
help_command = driver.create_help_command()
for service_name in help_command.command_table:
if service_name == 'help':
continue
service_command = help_command.command_table[service_name]
if not hasattr(service_command, '_service_object'):
continue
service = service_command._service_object
l.append((service.service_full_name, service_name))
l = sorted(l, key=lambda x: x[1])
for full_name, service_name in l:
service_ref_path = os.path.join(ref_path, service_name)
service_ref_path = os.path.join(service_ref_path, 'index')
fp.write('* :doc:`%s <..%s%s>`\n' % (full_name,
os.path.sep,
service_ref_path))
fp.write('\n')
fp.close()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--service',
help='Name of service, or else all services')
parser.add_argument('-o', '--operations',
help='Name of operations, or else all operations',
nargs='*')
args = parser.parse_args()
driver = awscli.clidriver.create_clidriver()
if not os.path.isdir(REF_PATH):
os.mkdir(REF_PATH)
if not os.path.isdir(TUT_PATH):
os.mkdir(TUT_PATH)
print('Generating ReST documents for all services...')
do_provider(driver)
print('Generating service list ReST document...')
build_service_list(TUT_PATH, REF_PATH, driver)
print('Done!')