17
17
import sys
18
18
import pathlib
19
19
20
- import jinja2
21
-
22
20
23
21
DOC_DIR = pathlib .Path (sys .path [0 ]).resolve ()
24
22
sys .path .insert (1 , str (DOC_DIR .parent ))
@@ -36,19 +34,19 @@ SRC_DIR = DOC_DIR / "src"
36
34
TEMPLATE_DIR = DOC_DIR / "templates"
37
35
TMP_DIR = DOC_DIR / "tmp"
38
36
39
- ROFF_DIR = OUT_DIR / "man"
37
+ MAN_DIR = OUT_DIR / "man"
40
38
41
- HTML_MAN_SRC_DIR = TMP_DIR / "roff_to_html "
39
+ HTML_MAN_SRC_DIR = TMP_DIR / "man_to_html "
42
40
HTML_UNIQUE_DIR = TMP_DIR / "html_unique"
43
41
44
42
45
43
RULES = [{
46
- "name" : "sc_to_roff " ,
47
- "description" : "converting ${man-name} to roff " ,
44
+ "name" : "sc_to_man " ,
45
+ "description" : "converting ${man-name} to man " ,
48
46
"command" : "scdoc < ${in} > ${out}"
49
47
}, {
50
- "name" : "voluptuous_to_roff " ,
51
- "description" : "converting ${man-name} to roff " ,
48
+ "name" : "voluptuous_to_man " ,
49
+ "description" : "converting ${man-name} to man " ,
52
50
"command" : f"{ BIN_DIR / 'schema-to-scdoc' } "
53
51
f" --project-root { DOC_DIR .parent } "
54
52
" --page-name ${man-name}"
@@ -57,8 +55,8 @@ RULES = [{
57
55
f" { TEMPLATE_DIR / 'voluptuous-man.jinja.scdoc' } "
58
56
" | scdoc > ${out}"
59
57
}, {
60
- "name" : "roff_to_html " ,
61
- "description" : "converting ${man-name}.roff HTML" ,
58
+ "name" : "man_to_html " ,
59
+ "description" : "converting ${man-name} HTML" ,
62
60
"command" : "mandoc -O fragment -Thtml < ${in} > ${out}"
63
61
}, {
64
62
"name" : "uniquify_header_ids" ,
@@ -79,7 +77,7 @@ RULES = [{
79
77
" --html-manuals ${html-mans}"
80
78
f" --template-dir { TEMPLATE_DIR } "
81
79
" --out-file ${out}"
82
- " --roff -html-dir ${roff -html-dir}"
80
+ " --man -html-dir ${man -html-dir}"
83
81
}]
84
82
85
83
@@ -97,12 +95,12 @@ def make_html_unique(man, html_man, html_mans, builds):
97
95
html_mans .append (html_unique )
98
96
99
97
100
- def roff_to_html (man , roff_out , builds ):
98
+ def man_to_html (man , man_out , builds ):
101
99
html_man = HTML_MAN_SRC_DIR / f"{ man .stem } .html"
102
100
builds .append ({
103
- "inputs" : [roff_out ],
101
+ "inputs" : [man_out ],
104
102
"outputs" : [html_man ],
105
- "rule" : "roff_to_html " ,
103
+ "rule" : "man_to_html " ,
106
104
"variables" : {
107
105
"man-name" : man .stem ,
108
106
"in-file" : html_man ,
@@ -111,30 +109,36 @@ def roff_to_html(man, roff_out, builds):
111
109
return html_man
112
110
113
111
114
- def convert_man_dir_to_roff (src_dir , dst_dir , rule , html_mans , builds ):
112
+ def convert_man_dir_to_man (src_dir , dst_dir , rule , html_mans , builds ):
115
113
for man in (src_dir ).iterdir ():
116
- roff_out = dst_dir / f"{ man .stem } .roff"
114
+ if man .suffix == ".scdoc" :
115
+ with open (man ) as fp :
116
+ line = fp .readline ().rstrip ()
117
+ index = line [line .find ('(' )+ 1 :line .find (')' )]
118
+ man_out = dst_dir / f"{ man .stem } .{ index } "
119
+ else :
120
+ man_out = dst_dir / f"{ man .stem } .5"
117
121
builds .append ({
118
122
"inputs" : [man ],
119
- "outputs" : [roff_out ],
123
+ "outputs" : [man_out ],
120
124
"rule" : rule ,
121
125
"variables" : {
122
126
"man-name" : man .stem ,
123
127
"data-path" : man .resolve (),
124
128
}
125
129
})
126
- html_man = roff_to_html (man , roff_out , builds )
130
+ html_man = man_to_html (man , man_out , builds )
127
131
make_html_unique (man , html_man , html_mans , builds )
128
132
129
133
130
134
def main ():
131
135
builds = []
132
136
html_mans = []
133
137
134
- convert_man_dir_to_roff (
135
- SRC_DIR / "man" , ROFF_DIR , "sc_to_roff " , html_mans , builds )
136
- convert_man_dir_to_roff (
137
- SRC_DIR / "voluptuous-man" , ROFF_DIR , "voluptuous_to_roff " , html_mans ,
138
+ convert_man_dir_to_man (
139
+ SRC_DIR / "man" , MAN_DIR , "sc_to_man " , html_mans , builds )
140
+ convert_man_dir_to_man (
141
+ SRC_DIR / "voluptuous-man" , MAN_DIR , "voluptuous_to_man " , html_mans ,
138
142
builds )
139
143
140
144
builds .append ({
@@ -146,7 +150,7 @@ def main():
146
150
"rule" : "build_html_doc" ,
147
151
"variables" : {
148
152
"html-mans" : " " .join ([str (h ) for h in html_mans ]),
149
- "roff -html-dir" : HTML_MAN_SRC_DIR ,
153
+ "man -html-dir" : HTML_MAN_SRC_DIR ,
150
154
}
151
155
})
152
156
0 commit comments