|
1 | 1 | #!/usr/bin/env python3
|
| 2 | +import os |
2 | 3 | import re
|
3 | 4 | from argparse import ArgumentParser, ArgumentTypeError
|
4 | 5 | from dataclasses import dataclass
|
|
9 | 10 |
|
10 | 11 | BASE_DIR = Path(__file__).resolve().parent
|
11 | 12 |
|
12 |
| -ANSI_STOP = "\033[0m" |
13 | 13 | ANSI_BLUE = "\033[34m"
|
| 14 | +ANSI_STOP = "\033[0m" |
| 15 | +ANSI_YELLOW = "\033[33m" |
14 | 16 |
|
15 | 17 |
|
16 | 18 | def main(args):
|
17 | 19 | doc_path, product, version, mdx_file, html_file, cover_file, pdf_file = setup(args)
|
18 | 20 |
|
19 |
| - print(f"{ANSI_BLUE}building {pdf_file}{ANSI_STOP}") |
20 |
| - |
21 | 21 | files = list_files(doc_path)
|
22 | 22 | if len(files) == 0:
|
23 |
| - raise Exception(f"no files in {doc_path}") |
| 23 | + print(f"{ANSI_YELLOW}skipping {pdf_file}{ANSI_STOP}") |
| 24 | + return |
| 25 | + |
| 26 | + print(f"{ANSI_BLUE}building {pdf_file}{ANSI_STOP}") |
24 | 27 |
|
25 | 28 | pattern = re.compile('div id="(.*?)" class="registered_link"')
|
26 | 29 | for elem in files:
|
@@ -91,11 +94,10 @@ def main(args):
|
91 | 94 | run(["open", html_file])
|
92 | 95 | else:
|
93 | 96 | print("generating cover page")
|
94 |
| - with open(BASE_DIR / "cover.html") as source, open(cover_file, "w") as output: |
95 |
| - data = source.read() |
96 |
| - data = data.replace("[PRODUCT]", title) |
97 |
| - data = data.replace("[VERSION]", version) |
98 |
| - output.write(data) |
| 97 | + data = (BASE_DIR / "cover.html").read_text() |
| 98 | + data = data.replace("[PRODUCT]", title) |
| 99 | + data = data.replace("[VERSION]", version) |
| 100 | + cover_file.write_text(data) |
99 | 101 |
|
100 | 102 | header_footer_common = [
|
101 | 103 | "--header-font-name",
|
@@ -202,11 +204,15 @@ def filter_path(path):
|
202 | 204 | if path.is_dir() and not path.match("*images*"):
|
203 | 205 | return True
|
204 | 206 | elif path.suffix in [".mdx", ".md"]:
|
205 |
| - with open(path) as f: |
206 |
| - content = re.sub( |
207 |
| - "^---$.*?^---$", "", f.read(), flags=re.DOTALL | re.MULTILINE |
208 |
| - ).strip() |
209 |
| - return False if content == "" else True |
| 207 | + content = re.sub( |
| 208 | + "^---$.*?^---$", "", path.read_text(), flags=re.DOTALL | re.MULTILINE |
| 209 | + ).strip() |
| 210 | + |
| 211 | + no_content = content == "" or ( |
| 212 | + len(content.split(os.linesep)) == 1 and "StubCards" in content |
| 213 | + ) |
| 214 | + |
| 215 | + return False if no_content else True |
210 | 216 | else:
|
211 | 217 | return False
|
212 | 218 |
|
|
0 commit comments