14
14
# permissions and limitations under the License.
15
15
16
16
17
- import sys
17
+ import argparse
18
18
import pathlib
19
+ import sys
19
20
20
21
21
22
DOC_DIR = pathlib .Path (sys .path [0 ]).resolve ()
@@ -89,6 +90,19 @@ RULES = [{
89
90
}]
90
91
91
92
93
+ def get_args ():
94
+ pars = argparse .ArgumentParser (description = "Build documentation for Litani" )
95
+ for arg in [{
96
+ "flags" : ["--no-html" ],
97
+ "action" : "store_false" ,
98
+ "help" : "Do not build a version of the documentation in HTML" ,
99
+ "dest" : "gen_html" ,
100
+ }]:
101
+ flags = arg .pop ("flags" )
102
+ pars .add_argument (* flags , ** arg )
103
+ return pars .parse_args ()
104
+
105
+
92
106
def make_html_unique (man_name , html_man , html_mans , builds ):
93
107
html_unique = HTML_UNIQUE_DIR / f"{ man_name } .html"
94
108
builds .append ({
@@ -118,7 +132,7 @@ def man_to_html(man_name, man_out, builds):
118
132
119
133
120
134
def convert_man_dir_to_man (
121
- src_dir , dst_dir , rule , html_mans , builds , extra_inputs = None ):
135
+ src_dir , dst_dir , rule , html_mans , builds , gen_html , extra_inputs = None ):
122
136
for man in (src_dir ).iterdir ():
123
137
man_name = str (man .name ).split ("." , 1 )[0 ]
124
138
if man .suffix == ".scdoc" :
@@ -140,11 +154,12 @@ def convert_man_dir_to_man(
140
154
"data-path" : man .resolve (),
141
155
}
142
156
})
143
- html_man = man_to_html (man_name , man_out , builds )
144
- make_html_unique (man_name , html_man , html_mans , builds )
157
+ if gen_html :
158
+ html_man = man_to_html (man_name , man_out , builds )
159
+ make_html_unique (man_name , html_man , html_mans , builds )
145
160
146
161
147
- def add_litani_7 (builds , html_mans ):
162
+ def add_litani_7 (builds , html_mans , gen_html ):
148
163
"""The litani(7) man page is special because it contains a table of contents
149
164
of the other pages, so it depends on the others."""
150
165
@@ -171,34 +186,39 @@ def add_litani_7(builds, html_mans):
171
186
"outputs" : [man_out ],
172
187
"rule" : "sc_to_man" ,
173
188
}])
174
- html_man = man_to_html ("litani.7" , man_out , builds )
175
- make_html_unique ("litani.7" , html_man , html_mans , builds )
189
+ if gen_html :
190
+ html_man = man_to_html ("litani.7" , man_out , builds )
191
+ make_html_unique ("litani.7" , html_man , html_mans , builds )
176
192
177
193
178
194
def main ():
195
+ args = get_args ()
179
196
builds = []
180
197
html_mans = []
181
198
182
199
convert_man_dir_to_man (
183
- SRC_DIR / "man" , MAN_DIR , "sc_to_man" , html_mans , builds )
200
+ SRC_DIR / "man" , MAN_DIR , "sc_to_man" , html_mans , builds ,
201
+ args .gen_html )
184
202
convert_man_dir_to_man (
185
203
SRC_DIR / "voluptuous-man" , MAN_DIR , "voluptuous_to_man" , html_mans ,
186
- builds , extra_inputs = [TEMPLATE_DIR / "voluptuous-man.jinja.scdoc" ])
204
+ builds , args .gen_html ,
205
+ extra_inputs = [TEMPLATE_DIR / "voluptuous-man.jinja.scdoc" ])
187
206
188
- add_litani_7 (builds , html_mans )
207
+ add_litani_7 (builds , html_mans , args . gen_html )
189
208
190
- builds .append ({
191
- "inputs" : html_mans + [
192
- BIN_DIR / "build-html-doc" ,
193
- TEMPLATE_DIR / "index.jinja.html" ,
194
- ],
195
- "outputs" : [DOC_DIR / "out" / "html" / "index.html" ],
196
- "rule" : "build_html_doc" ,
197
- "variables" : {
198
- "html-mans" : " " .join ([str (h ) for h in html_mans ]),
199
- "man-html-dir" : HTML_MAN_SRC_DIR ,
200
- }
201
- })
209
+ if args .gen_html :
210
+ builds .append ({
211
+ "inputs" : html_mans + [
212
+ BIN_DIR / "build-html-doc" ,
213
+ TEMPLATE_DIR / "index.jinja.html" ,
214
+ ],
215
+ "outputs" : [DOC_DIR / "out" / "html" / "index.html" ],
216
+ "rule" : "build_html_doc" ,
217
+ "variables" : {
218
+ "html-mans" : " " .join ([str (h ) for h in html_mans ]),
219
+ "man-html-dir" : HTML_MAN_SRC_DIR ,
220
+ }
221
+ })
202
222
203
223
for build in builds :
204
224
for k , v in build .items ():
0 commit comments