forked from WorldVistA/VistA
-
Notifications
You must be signed in to change notification settings - Fork 1
/
OTJKIDSUtilities.py
199 lines (193 loc) · 8.4 KB
/
OTJKIDSUtilities.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
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
#---------------------------------------------------------------------------
# Copyright 2013 The Open Source Electronic Health Record Agent
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#---------------------------------------------------------------------------
import sys,os,re,argparse,fnmatch
from PatchInfoParser import installNameToDirName
from OTJParseEvidenceOutput import ParseOutput,WriteRCheck,WriteRFind,XINDEXParser,GTMRFind,findGTMRoutinesDir
from KIDSBuildParser import KIDSBuildParser
from VistATestClient import VistATestClientFactory, createTestClientArgParser
from DefaultKIDSBuildInstaller import DefaultKIDSBuildInstaller
routineset=[]
def PrintChecksumsbyBuildname(testClient,name,outputDir):
resultsfolder= os.path.join(outputDir,"ChecksumResults")
try:
os.mkdir(resultsfolder)
except:
pass
logpath = os.path.join(resultsfolder,installNameToDirName(name))
testClient.setLogFile(logpath+"PostChecksums.log")
connection = testClient.getConnection()
connection.send("D CHECK1^XTSUMBLD\r")
connection.expect("Build from")
connection.send("Build\r")
connection.expect("Select BUILD NAME")
connection.send(name + "\r")
testClient.waitForPrompt()
connection.send("\r")
def FullXINDEX(testclient,outputDir,routinelist):
resultsfolder= os.path.join(outputDir,"XINDEXResults")
try:
os.mkdir(resultsfolder)
except:
pass
logpath = os.path.join(resultsfolder,"XINDEXAllRoutines")
testclient.setLogFile(logpath+".log")
connection = testclient.getConnection()
connection.send("D ^XINDEX\r")
if testclient.isCache():
connection.expect("All Routines")
connection.send("N\r")
for routine in routinelist:
connection.expect("Routine")
connection.send(routine+"\r")
connection.expect("Routine")
connection.send("\r")
connection.expect("BUILD NAME")
connection.send("\r")
connection.expect("INSTALL NAME")
connection.send("\r")
connection.expect("PACKAGE NAME")
connection.send("\r")
connection.expect("Print more than compiled errors and warnings")
connection.send("\r")
connection.expect("Print summary only")
connection.send("\r")
connection.expect("Print routines")
connection.send("No\r")
connection.expect("Print errors and warnings with each routine")
connection.send("\r")
connection.expect("Index all called routines")
connection.send("N\r")
connection.expect("DEVICE")
connection.send(';;9999\r')
if testclient.isCache():
connection.expect('Right Margin:')
connection.send('\r')
connection.send('\r')
connection.expect('continue:',1200)
connection.send('\r')
connection.expect('--- END ---',12000)
XINDEXParser(resultsfolder,"XINDEXAllRoutines")
def XINDEXbyBuildname(testclient,installname,outputDir):
resultsfolder= os.path.join(outputDir,"XINDEXResults")
try:
os.mkdir(resultsfolder)
except:
pass
logpath = os.path.join(resultsfolder,installNameToDirName(installname))
testclient.setLogFile(logpath+".log")
connection = testclient.getConnection()
connection.send("D ^XINDEX\r")
if testclient.isCache():
connection.expect("All Routines")
connection.send("N\r")
connection.expect("Routine")
connection.send("\r")
connection.expect("BUILD NAME")
connection.send(installname+"\r")
connection.expect("Include the compiled template routines")
connection.send("N\r")
connection.expect("Print more than compiled errors and warnings")
connection.send("\r")
connection.expect("Print summary only")
connection.send("\r")
connection.expect("Print routines")
connection.send("No\r")
connection.expect("Print the DDs, Functions, and Options")
connection.send("\r")
connection.expect("Print errors and warnings with each routine")
connection.send("\r")
connection.expect("Save parameters in ROUTINE file")
connection.send("\r")
connection.expect("Index all called routines")
connection.send("N\r")
connection.expect("DEVICE")
connection.send(';;9999\r')
if testclient.isCache():
connection.expect('Right Margin:')
connection.send('\r')
connection.send('\r')
connection.expect('continue:')
connection.send('\r')
connection.expect('--- END ---',120)
XINDEXParser(resultsfolder,installname)
testClientParser = createTestClientArgParser()
parser = argparse.ArgumentParser(description='Processor for OTJ Evidence with a .KID submission',
parents=[testClientParser])
parser.add_argument('-kb', required=True, dest='KIDSbuild',
help='Path to the .KIDS file')
parser.add_argument('-o', required=True, dest='outputDir',
help='Path to folder to store output files')
#parser.add_argument('-find', required=False, dest='Ffile',
# help='Filepath to the Output file of the RFind function.')
#parser.add_argument('-check', required=False, dest='Cfile',
# help='Filepath to the Output file of the RCheck function.')
result = parser.parse_args()
# Create a test client and run the KIDSBuildParser on the supplied KIDS build
testClient = VistATestClientFactory.createVistATestClientWithArgs(result)
assert testClient
with testClient:
KIDSParser = KIDSBuildParser(result.outputDir)
KIDSParser.parseKIDSBuild(result.KIDSbuild)
KIDSParser.printResult()
for root,dirnames,filenames in os.walk(result.outputDir):
for filename in fnmatch.filter(filenames,'*.m'):
name,ext = filename.split('.')
routineset.append(name)
print "Writing out intial XINDEX information: Start"
FullXINDEX(testClient,result.outputDir,routineset)
print "Writing out intial XINDEX information: Done"
resultsfolder = os.path.join(result.outputDir,"RCheck_RFind")
try:
os.mkdir(resultsfolder)
except:
pass
if testClient.isCache():
print "Writing out initial %RCheck information: Start"
WriteRCheck(testClient,resultsfolder,"RCheckResultsPre.log",routineset)
print "Writing out %RCheck information: Done"
print "Writing out initial %RFind information: Start"
WriteRFind(testClient,resultsfolder,"RFindResultsPre.log",routineset)
print "Writing out %RFind information: Done"
else:
print "%RFIND is an InterSystems Cache Utility, performing a REGEX search through the gtmroutines directory in " + findGTMRoutinesDir()
GTMRFind(resultsfolder,"RFindResultsPre.log",routineset)
# Attempt to install the supplied KIDS build
print "Installation of " + result.KIDSbuild+ " : START"
KIDSInstaller = DefaultKIDSBuildInstaller(result.KIDSbuild,KIDSParser.installNameList[0],None,os.path.join(result.outputDir,'InstallLog.txt'),
KIDSParser.installNameList,1,printTG=result.outputDir)
KIDSInstaller.runInstallation(testClient,KIDSParser.installNameList)
print "Installation of " + result.KIDSbuild+ " : DONE"
# Run the XINDEX utility on each build that was installed by the KIDS build
for name in KIDSParser.installNameList:
print "Running XINDEX and finding Checksums for installed package: " + name
XINDEXbyBuildname(testClient,name,result.outputDir)
PrintChecksumsbyBuildname(testClient,name,result.outputDir)
rfindpost=os.path.join(resultsfolder,"RFindResultsPost.log")
rcheckpost= os.path.join(resultsfolder,"RCheckResultsPost.log")
if testClient.isCache():
print "Writing out post-install %RCheck information: Start"
WriteRCheck(testClient,resultsfolder,"RCheckResultsPost.log",routineset)
print "Writing out post-install %RCheck information: Done"
print "Writing out post-install %RFind information: Start"
WriteRFind(testClient,resultsfolder,"RFindResultsPost.log",routineset)
print "Writing out post-install %RFind information: Done"
print "Parsing Output"
ParseOutput(resultsfolder+"/",rfindpost,rcheckpost,routineset)
else:
print "%RFIND is an InterSystems Cache Utility, performing a REGEX search through the gtmroutines directory in " + findGTMRoutinesDir()
GTMRFind(resultsfolder,"RFindResultsPost.log",routineset)
print "Parsing Output"
ParseOutput(resultsfolder+"/",rfindpost,None,routineset)