File: add-glossary_generator.patch

package info (click to toggle)
tango 10.1.0%2Bdfsg1-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 88,780 kB
  • sloc: cpp: 213,413; sh: 1,641; python: 1,264; javascript: 472; perl: 467; xml: 407; makefile: 294; java: 260; sql: 72
file content (69 lines) | stat: -rw-r--r-- 2,732 bytes parent folder | download
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
Description: Add the missing glossary_generator.py file
 This file was missing from the tango distribution source tarball for version
 10.1.0.
 See: https://gitlab.com/tango-controls/TangoSourceDistribution/-/issues/152
Forwarded: not-needed
Author: Santiago Ruano Rincón <santiago@freexian.com>

Index: tango/doc/src/glossary_generator.py
===================================================================
--- /dev/null
+++ tango/doc/src/glossary_generator.py
@@ -0,0 +1,57 @@
+import glob
+
+path = "source/**/*.md"
+files = glob.glob(path, recursive=True)
+
+key = "%[glossary_term]"
+text = ""
+save = False
+for f in files:
+    with open(f, 'r', encoding="utf-8") as fp:
+        # read all lines in a list
+        lines = fp.readlines()
+        for line in lines:
+            # check current line starts with the glossary signature
+            if line.startswith(key):
+                save = True
+                name = line.replace(key,"")
+                name = name.replace("[","")
+                name = name.replace("]","")
+                text = text + name
+            elif save:
+                if line in ["\n", "\r\n"]:
+                    filelink = f.replace("source/", "")
+                    filelink = filelink.replace(".md", "")
+                    filename = filelink.split("/")[-1]
+                    if filename == "index":
+                        filename = filelink.split("/")[-2]
+                    text = text + " For more details please see the {doc}`"+filename+" <../" +filelink + ">` section.\n\n"
+                    save = False
+                else:
+                    line = line.replace("%","")
+                    text = text + "\t" + line
+
+
+if text:
+    output = ""
+    glossary_started = False
+    with open("source/Reference/glossary_definitions.md", 'r') as fp:
+        lines = fp.readlines()
+        for line in lines:
+            if line.strip() == "```{glossary}" and not glossary_started:
+                glossary_started = True
+            if line.startswith("%"):
+                #ignore comments in definition file
+                continue
+            elif line.strip() == "```" and glossary_started:
+                output = output + "\n" + text + " ```\n"
+                break
+            else:
+                output = output + line
+
+    with open("source/Reference/glossary.md", 'w+') as fp:
+        fp.write("% !!!! This is the auto-generated glossary file. Do not manually add definitions\
+ here as they will be overwritten the next time the documentation is built! Instead add them\
+ in the relevant section using the '%[glossary_term][<term_name>]' label or in\
+ glossary_definitions.md file.\n")
+        fp.write(output)