-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeTraceTable.py
77 lines (64 loc) · 2.21 KB
/
makeTraceTable.py
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
#!/usr/bin/env python
import csv
import re
import sys
with open(sys.argv[1], "r") as f:
reader = csv.reader(f)
# Extract component list from first (header) line
header = next(reader)
components = []
component_reqs = dict()
for c in header:
# Separate component from package
component = c.split(" [")[0]
# Protect ampersand and underscore from LaTeX and make readable
component = re.sub(r'\&', 'and', component)
component = re.sub(r'_', '\\_', component)
# Remove leading digits used for sort ordering
component = re.sub(r'^\d+\s+', '', component)
components.append(component)
component_reqs[component] = []
n = len(components)
print(r"""
\newpage
\section{Appendix: Traceability}\label{appendix-traceability}
\subsection{Requirement to Component
Traceability}\label{requirement-to-component-traceability}
\footnotesize
\begin{longtable}{p{0.4\textwidth}p{0.55\textwidth}}
\hline
\multicolumn{1}{c}{\textbf{Requirement}} &
\multicolumn{1}{c}{\textbf{Components}} \\ \hline
\endhead
""")
# Each succeeding line corresponds to a requirement
for row in reader:
req = row[0]
# Separate requirement from package
req = req.split(" [")[0]
# Protect ampersand from LaTeX and make readable
req = re.sub(r'\&', 'and', req)
# Remove digits after req id used for sort ordering
req = re.sub(r'([A-Z]-\d+)\s+\d+', r'\1', req)
clist = []
for i in range(1, n):
if row[i]:
clist.append(components[i])
component_reqs[components[i]].append(req)
print("{} & {} \\\\ \\hline".format(req, ", ".join(clist)))
print(r"""
\end{longtable}
\normalsize
\subsection{Component to Requirement
Traceability}\label{component-to-requirement-traceability}
Note that only ``leaf'' components are traced to requirements.
\setitemize{noitemsep,topsep=0pt,parsep=0pt,partopsep=0pt}
\footnotesize
""")
for component in components:
if len(component_reqs[component]) == 0:
continue
print(component + r" \begin{itemize}" +
"\n\\item " +
"\n\\item ".join(component_reqs[component]) +
"\n" + r"\end{itemize}")