-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathverifLabelRegressionDiff.py
More file actions
241 lines (203 loc) · 9.86 KB
/
verifLabelRegressionDiff.py
File metadata and controls
241 lines (203 loc) · 9.86 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/pkg/qct/software/python/3.5.2/bin/python
###############################################################################
# Filename: verifLabelRegressionDiff.py
# Author: cskebriti
# Description:
# Creates HTML for diffRegVerifLabel to be displayed on http://napier_mac/
# It stores the file on disk and performs an SQL INSERT into the HeliumDB
###############################################################################
import sys, os # Std Lib: used here to print error message
import setup.config as config # local app: top level config variables
import json # Std Lib: used to import email addr of blk owners
import pymssql # pip module: used for db connection and sql actions
import setup.sql_setup as sql_setup # local app: keeps db passwd in separate file obfiscated
import helper.myfunc as myUtils # local app: keep common functions there
#import trigger_consecutive_label_fail
#import emailBlockOwner # local app: called with list of block names
import collections, operator
import subprocess
import re
from datetime import datetime
import helper.regressionBehindHtmlGenerator \
as regressionBehindHtmlGenerator
import helper.regressionBehindEmailer as regressionBehindEmailer
DEBUG = config.DEBUG
#DEBUG = 3 #Override
NAPIER = config.NAPIER
PROJ = config.PROJ
data = config.myJsonData
miniTable = config.miniTable#string
fullTable = config.fullTable#string
dbTables = config.dbTables #tuple
DEPOT = config.DEPOT
PRJ_BRANCH = config.PRJ_BRANCH
projectName = config.projectName
bookKeepFull = config.lithiumRegBookKeepingFileMini
bookKeepMini = config.lithiumRegBookKeepingFileFull
inputParamFileFull = config.lithiumRegParamInputFileFull
inputParamFileMini = config.lithiumRegParamInputFileMini
#Named Tuple Obj
Block = config.Block
EMAIL_FLAG = config.EMAIL_FLAG
#######################Json Keys######################################
#JNAME_P4 = 'P4FilesCollection'
JNAME_SQL = 'SqlQueryCollection'
#BlockNameQuery = 'NapierBlocks' if NAPIER else 'HawkeyeBlocks'
JNAME_P4 = 'P4Labels_NAPIER' if NAPIER else 'P4Labels_HAWKEYE'
######################################################################
#Output file for HTML, type=pathlib.PosixPath
HtmlOutputFile = config.VerifDiffLabelHtmlOutputFile
diffRegTable = config.VerifDiffLabelHtmlFileDBTable
if not (HtmlOutputFile and diffRegTable):
print ("No HTML output file specified or HeliumDB table to put the Html file into!")
raise SystemExit
########################################################################
########################################################################
########################################################################
########################################################################
########################################################################
# Main: Start of Program #
########################################################################
########################################################################
if 'main' in __name__: print ("Start of Program")
os.environ['PATH'] += os.pathsep + '/pkg/qct/software/p4'
os.putenv('P4PORT', "p2.qca.qualcomm.com:1666")
# Create db connection
db,cursor = sql_setup.opendb()
config.setDB(db,cursor)
from helper.p4_functions import *
# Create global list to store tuples
myRecords = list()
try:
for i in data[JNAME_P4]:#['XP4Labels_NAPIER']:
print ("\n\tBlock {}".format(i))
if DEBUG: print ("Using '{}' for labelname \n and '{}' for VERIF filename".format(
data[JNAME_P4][i], getAndParseRecommendedLabel(data[JNAME_P4][i]).split('#')[0]))
##
labelsyncName = data[JNAME_P4][i]
#####################################################################################
#
####
blockname = i
#
latestRev = \
getP4LatestRev(labelsyncName)
#
latestRecommendedLabel = \
getP4LatestRecommendedLabel(labelsyncName)
#
lastRunMiniReg = \
getLastRunMiniReg(blockname)
#
lastRunFullReg = \
getLastRunFullReg(blockname)
#
recomendedLabelsBehindLastMiniRun = \
getRecomendedLabelsBehindLastMiniRun(lastRunMiniReg,latestRecommendedLabel)
#
recomendedDaysBehindLastMiniRun = \
getRecomendedDaysBehindLastMiniRun(labelsyncName,lastRunFullReg,latestRecommendedLabel)
#
miniLabelsBehindLatestRev = \
getMiniLabelsBehindLatestRev(lastRunMiniReg,latestRev)
#
fullLabelsBehindLatestRev = \
getFullLabelsBehindLatestRev(lastRunFullReg,latestRev)
#
miniDaysBehindLatestRev = \
getMiniDaysBehindLatestRev(labelsyncName,lastRunMiniReg,latestRev)
#
fullDaysBehindLatestRev = \
getFullDaysBehindLatestRev(labelsyncName,lastRunFullReg,latestRev)
#
miniLabelsBehindRecommendedLabel = \
getMiniLabelsBehindRecommendedLabel(lastRunMiniReg,latestRecommendedLabel)
#
fullLabelsBehindRecommendedLabel = \
getFullLabelsBehindRecommendedLabel(lastRunFullReg,latestRecommendedLabel)
#
miniDaysBehindRecommendedLabel = \
getMiniDaysBehindRecommendedLabel(labelsyncName,lastRunMiniReg,latestRecommendedLabel)
#
fullDaysBehindRecommendedLabel = \
getFullDaysBehindRecommendedLabel(labelsyncName,lastRunFullReg,latestRecommendedLabel)
#
#
#####################################################################################
# Create the tuple and append to the list
##############################################################
newBlock = Block(
blockname = blockname,
latestRev = latestRev,
latestRecommendedLabel = latestRecommendedLabel,
lastRunMiniReg = lastRunMiniReg,
lastRunFullReg = lastRunFullReg,
recomendedLabelsBehindLastMiniRun = recomendedLabelsBehindLastMiniRun,
recomendedDaysBehindLastMiniRun = recomendedLabelsBehindLastMiniRun,
miniLabelsBehindLatestRev = miniLabelsBehindLatestRev,
fullLabelsBehindLatestRev = fullLabelsBehindLatestRev,
miniDaysBehindLatestRev = miniDaysBehindLatestRev,
fullDaysBehindLatestRev = fullDaysBehindLatestRev,
miniLabelsBehindRecommendedLabel= miniLabelsBehindRecommendedLabel,
fullLabelsBehindRecommendedLabel= fullLabelsBehindRecommendedLabel,
miniDaysBehindRecommendedLabel = miniDaysBehindRecommendedLabel,
fullDaysBehindRecommendedLabel = fullDaysBehindRecommendedLabel )
##############################################################
myRecords.append(newBlock)
####
####
# Print a summary, sort myRecords, and print the generated Html output
####
print ("\n{}\n{}".format("My Records Summary:".center(62),"="*62))
for i in myRecords:
msg = "{:30} {:3} {:3} {:3} {:3} {:3} {:3} {:3} {:3} {:3} {:3}"
print (msg.format(
i.blockname,
i.latestRev,
i.latestRecommendedLabel,
i.lastRunMiniReg,
i.lastRunFullReg,
i.miniLabelsBehindLatestRev,
i.fullLabelsBehindLatestRev,
i.miniDaysBehindLatestRev,
i.fullDaysBehindLatestRev,
i.fullLabelsBehindRecommendedLabel,
i.fullDaysBehindRecommendedLabel))
print ("blockname latestRev latestRecommendedLabel lastRunMiniReg lastRunFullReg \
miniLabelsBehindLatestRev fullLabelsBehindLatestRev miniDaysBehindLatestRev fullDaysBehindLatestRev\
fullLabelsBehindRecommendedLabel fullDaysBehindRecommendedLabel\n\n")
myRecords = sorted(myRecords, key=operator.attrgetter('blockname'))
#######################################################################
## Run the automation script for sending email notifications
if EMAIL_FLAG: regressionBehindEmailer.dispatchEmails(myRecords)
#######################################################################
#####################################################################################################
# Now let's save the Html file as text and stuff the it into the Helium DB for the dashboard
#####################################################################################################
myHtmlAsText = regressionBehindHtmlGenerator.createHTML(myRecords)
#
##Save to file
print ("\nSave to file '{}'".format(HtmlOutputFile))
HtmlOutputFile.write_text(myHtmlAsText)
#
##Make sure no single quotes are used in the Html text, use only double quotes. Check and replace any
# single quotest as an extra precaution before we execute the sql statement
myHtmlAsText.replace("'", '"')
#
##
print ("Insert into table '{}'".format(diffRegTable))
if DEBUG < 3:
sql = \
"""
IF NOT EXISTS (SELECT * FROM [dbo].[{1}]
WHERE HTMLfile = '{0}')
INSERT INTO {1} (HTMLfile) values('{0}')
"""
cursor.execute(sql.format(myHtmlAsText,diffRegTable))
db.commit()
####
# No matter what exception occurs, close the DB connection
####
finally: # Disconnect from server
print ("\n\n**Closing DB connection**\n")
sql_setup.closedb(db,cursor)