Repository navigation
Expand file tree
/
Copy pathdocs_manager.py
More file actions
75 lines (68 loc) · 2.03 KB
/
Copy pathdocs_manager.py
File metadata and controls
75 lines (68 loc) · 2.03 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
import os
title = "OpenLabTools Materials Tester Documentation"
files = [
"00-getting_started.md",
"01-sourcing_components.md",
"02-cutting_panels.md",
"03-assembly-01_front_enclosure.md",
"03-assembly-02_rear_face.md",
"03-assembly-03_rear_module.md",
"03-assembly-04_electronics.md",
"03-assembly-05_motors.md",
"04-installing_software.md",
"05-commissioning.md",
"06-designing_an_experiment.md",
"07-running_an_experiment.md",
"08-maintenance.md",
"09-customisation.md",
"10-performance.md"]
comment_end = "END TITLE BLOCK"
def commentate(x):
return "\n[//]: # (" + x + ")\n"
def navigate(x):
t = "### %s\n" % title
for z in files:
if z == x:
t += "- **" + titillate(z) + "**\n"
else:
t += "- [" + titillate(z) + "](\\" + z + ")\n"
t += "\n### %s\n" % titillate(x)
t += commentate(comment_end)
return t
def titillate(x):
t = ""
layers = x.split('.md')[0].split("-")[1:]
if len(layers) == 1:
t += layers[0].replace('_', ' ').title()
else:
t += layers[0].replace('_', ' ').title()
t += " Step "
words = layers[1].split('_')
t += words[0].title()
t += " -"
for w in words[1:]:
t += " "
t += w.title()
return t
if __name__ == "__main__":
print "checking for unlisted doc files"
os.chdir("../docs")
current_files = os.listdir(os.getcwd())
for x in current_files:
if x[-3:] == ".md" and x not in files:
print " %s not in file list - removing" % x
os.remove(x)
for x in files:
content = ""
if os.path.isfile(x):
with open(x, 'r+') as f:
content = f.read().split(commentate(comment_end))[1]
f.seek(0)
f.write(navigate(x))
f.write(content)
f.truncate()
else:
with open(x, 'w') as f:
f.write(navigate(x))
f.write(content)
print "complete"