-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_constr_doc.py
More file actions
executable file
·166 lines (141 loc) · 6.55 KB
/
parse_constr_doc.py
File metadata and controls
executable file
·166 lines (141 loc) · 6.55 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/python
import sys, re, os
import time
from subprocess import *
from operator import itemgetter, attrgetter
# Generic procedure class.
class MJProcedure:
def __init__(self, ProcTitle):
self.ProcedureTitle = ProcTitle
self.Procedure = ""
self.PrimaryContact = ""
self.Revision = ""
self.Status = ""
self.ApprovalDate = ""
self.Task = ""
self.FileOrigin = ""
# Find a specific entry in a procedure and find the corresponding content.
def TEXFindnReturn(s, line): # search f
m = re.search("(?<!%)" + s, line) # make sure line is not commented out.
if m is not None:
n = re.search("{(.*)}|{(.*)", line[m.end():])
if n is not None:
return n.group(0)[1:-1]
# List of all procedures found in the construction document.
ProceduresList = list()
# Grab latest versions from dev and pro directories on svn
devFileName = "/Users/rhenning/MJD-ConDoc_dev.tex"
svnProcess = Popen(["svn", "export", "https://svn.pnl.gov/svn/MJD-ConDoc/MJD-Manual/dev/MJD-ConDoc.tex", "--username", "henning", "--password", "henning", devFileName], stdout=PIPE)
svnProcess.wait()
proFileName = "/Users/rhenning/MJD-ConDoc_pro.tex"
svnProcess = Popen(["svn", "export", "https://svn.pnl.gov/svn/MJD-ConDoc/MJD-Manual/pro/MJD-ConDoc.tex", "--username", "henning", "--password", "henning", proFileName], stdout=PIPE)
svnProcess.wait()
devFile = open(devFileName, 'r')
devString = devFile.read();
devFile.close()
os.remove(devFileName)
proFile = open(proFileName, 'r')
proString = proFile.read();
proFile.close()
os.remove(proFileName)
inString = "<DEV>\n" + devString + "\n<PRO>\n" + proString
lineList = re.split("\n+", inString)
NewProcedure = MJProcedure("dummy")
currentTask = ""
currentOrigin = ""
for line in lineList:
m = re.search('\s+%|^%', line)
if m is None:
if re.search("<DEV>", line) is not None:
currentOrigin = "DEV"
if re.search("<PRO>", line) is not None:
currentOrigin = "PRO"
search_string = TEXFindnReturn('task}', line)
if search_string is not None:
currentTask = search_string
search_string = TEXFindnReturn('proceduretitle}', line)
if search_string is not None:
NewProcedure.Task = currentTask
NewProcedure.FileOrigin = currentOrigin
ProceduresList.append(NewProcedure)
NewProcedure = MJProcedure(search_string)
search_string = TEXFindnReturn('procedure}', line)
if search_string is not None:
NewProcedure.Procedure = search_string
search_string = TEXFindnReturn('primarycontact}', line)
if search_string is not None:
NewProcedure.PrimaryContact = search_string
search_string = TEXFindnReturn('revision}', line)
if search_string is not None:
NewProcedure.Revision = search_string
search_string = TEXFindnReturn('status}', line)
if search_string is not None:
NewProcedure.Status = search_string
search_string = TEXFindnReturn('approvaldate}', line)
if search_string is not None:
NewProcedure.ApprovalDate = search_string
ProceduresList.pop(0) # Remove intial dummy procedure
ProceduresList.pop(0) # Remove template
print 'Processed ' + str(len(ProceduresList)) + ' procedures'
sortedProceduresList = sorted(ProceduresList, key = attrgetter("Revision"))
sortedProceduresList = sorted(sortedProceduresList, key = attrgetter("Procedure"))
sortedProceduresList = sorted(sortedProceduresList, key = attrgetter("Task"))
headerText = "<html>\n\
<body>\n\
<h1> MAJORANA Procedures Status </h1>\n\
<h2> Last Update: " + time.strftime("%d %b %Y %H:%M:%S ET") + "</h2>\n"
tableHeader = "<table border=2 cellspacing=0 cellpadding=4>\n\
<tr> \n\
<td> <h3> Title </h3> </td>\n\
<td> <h3> Task </h3> </td>\n\
<td> <h3> Procedure </h3> </td>\n\
<td> <h3> Primary Contact </h3> </td>\n\
<td> <h3> Revision </h3> </td>\n\
<td> <h3> Status </h3> </td>\n\
<td> <h3> Approval Date </h3> </td>\n\
</tr>\n "
table1 = "<h2> Procedures from /dev and Approved Procedures from /pro </h2>\n" + tableHeader
for myproc in sortedProceduresList:
if re.search("DEV", myproc.FileOrigin) is not None or (re.search("PRO", myproc.FileOrigin) is not None and re.search("Approved", myproc.Status) is not None):
table1 += "<tr>\n"
table1 += "<td>" + myproc.ProcedureTitle + "</td>\n"
table1 += "<td>" + myproc.Task + "</td>\n"
table1 += "<td>" + myproc.Procedure + "</td>\n"
table1 += "<td>" + myproc.PrimaryContact + "</td>\n"
table1 += "<td>" + myproc.Revision + "</td>\n"
table1 += "<td>" + myproc.Status + "</td>\n"
table1 += "<td>" + myproc.ApprovalDate + "</td>\n"
table1 += "</tr>"
table1 += "</table>\n "
table2 = "<h2> Approved Procedures from /pro </h2>\n" + tableHeader
for myproc in sortedProceduresList:
if re.search("PRO", myproc.FileOrigin) is not None and re.search("Approved", myproc.Status) is not None:
table2 += "<tr>\n"
table2 += "<td>" + myproc.ProcedureTitle + "</td>\n"
table2 += "<td>" + myproc.Task + "</td>\n"
table2 += "<td>" + myproc.Procedure + "</td>\n"
table2 += "<td>" + myproc.PrimaryContact + "</td>\n"
table2 += "<td>" + myproc.Revision + "</td>\n"
table2 += "<td>" + myproc.Status + "</td>\n"
table2 += "<td>" + myproc.ApprovalDate + "</td>\n"
table2 += "</tr>"
table2 += "</table>\n "
sortedProceduresList = sorted(sortedProceduresList, key = attrgetter("ApprovalDate"))
table3 = "<h2> Upcoming Procedures from /dev </h2>\n" + tableHeader
for myproc in sortedProceduresList:
if re.search("DEV", myproc.FileOrigin) is not None and re.search("Target", myproc.ApprovalDate) is not None:
table3 += "<tr>\n"
table3 += "<td>" + myproc.ProcedureTitle + "</td>\n"
table3 += "<td>" + myproc.Task + "</td>\n"
table3 += "<td>" + myproc.Procedure + "</td>\n"
table3 += "<td>" + myproc.PrimaryContact + "</td>\n"
table3 += "<td>" + myproc.Revision + "</td>\n"
table3 += "<td>" + myproc.Status + "</td>\n"
table3 += "<td>" + myproc.ApprovalDate + "</td>\n"
table3 += "</tr>"
table3 += "</table>\n "
footerText = "</body>\n </html>\n "
outText = headerText + table2 + table3 + table1 + footerText
outFile = open("/Users/markhowe/Sites/ConDocStatus.html", "w")
outFile.write(outText)
outFile.close()