-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·100 lines (81 loc) · 2.96 KB
/
Copy pathbuild.py
File metadata and controls
executable file
·100 lines (81 loc) · 2.96 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
#!/usr/bin/env python3
import argparse
import shutil
from pathlib import Path
from wireviz import wireviz
HARNESS_DIR = Path('harness')
DOCS_DIR = Path('docs')
GENERATED_EXTENSIONS = ['.gv', '.bom.tsv', '.png', '.svg', '.html']
def build(harness_dir: Path = HARNESS_DIR, docs_dir: Path = DOCS_DIR):
docs_dir.mkdir(exist_ok=True)
yml_files = sorted(harness_dir.glob('*.yml'))
for yml_file in yml_files:
print(f' Building {yml_file}')
wireviz.parse_file(str(yml_file))
for ext in GENERATED_EXTENSIONS:
src = yml_file.with_suffix(ext)
if src.exists():
shutil.move(str(src), docs_dir / src.name)
generate_index(yml_files, docs_dir)
print('Done.')
def generate_index(yml_files, docs_dir: Path):
harness_names = [f.stem for f in yml_files]
rows = '\n'.join(
f' <li><a href="{name}.html">{name}</a>'
f' — <a href="{name}.bom.tsv">BOM</a></li>'
for name in harness_names
)
html = f"""\
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Zero SR/S Wire Harness</title>
<style>
body {{ font-family: sans-serif; max-width: 860px; margin: 2rem auto; padding: 0 1.5rem; color: #222; }}
h1 {{ border-bottom: 2px solid #333; padding-bottom: .4rem; }}
ul {{ line-height: 2.2; padding-left: 1.2rem; }}
a {{ color: #0066cc; }}
footer {{ margin-top: 3rem; font-size: .85rem; color: #666; border-top: 1px solid #ddd; padding-top: .8rem; }}
</style>
</head>
<body>
<h1>Zero SR/S Wire Harness</h1>
<p>Wiring harness documentation traced from a Zero Motorcycles SR/S (Gen3 FST platform).</p>
<p>Each link opens an interactive diagram with a bill of materials.</p>
<ul>
{rows}
</ul>
<footer>Generated by <a href="https://github.com/formatc1702/WireViz">WireViz</a>.
Source on <a href="https://github.com/atomicdog/ZeroMotoWireharness">GitHub</a>.</footer>
</body>
</html>
"""
(docs_dir / 'index.html').write_text(html)
print(f' Generated {docs_dir}/index.html')
def clean(harness_dir: Path = HARNESS_DIR, docs_dir: Path = DOCS_DIR):
# Remove any leftover generated files from harness dir
for yml_file in harness_dir.glob('*.yml'):
for ext in GENERATED_EXTENSIONS:
f = yml_file.with_suffix(ext)
if f.exists():
print(f' rm {f}')
f.unlink()
# Remove docs dir contents
if docs_dir.exists():
for f in docs_dir.iterdir():
if f.is_file():
print(f' rm {f}')
f.unlink()
print('Done.')
def main():
parser = argparse.ArgumentParser(description='Build wire harness diagrams')
parser.add_argument('action', nargs='?', choices=['build', 'clean'], default='build')
args = parser.parse_args()
if args.action == 'build':
build()
elif args.action == 'clean':
clean()
if __name__ == '__main__':
main()