forked from WorldVistA/VistA
-
Notifications
You must be signed in to change notification settings - Fork 1
/
VistAPackageInfoFetcher.py
718 lines (682 loc) · 26.3 KB
/
VistAPackageInfoFetcher.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
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
#---------------------------------------------------------------------------
# Copyright 2012 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.
#---------------------------------------------------------------------------
from __future__ import with_statement
import sys
import re
import argparse
from VistATestClient import VistATestClientFactory, createTestClientArgParser
from datetime import datetime
from LoggerManager import logger, initConsoleLogging, initFileLogging
from VistAMenuUtil import VistAMenuUtil
""" class to fetch package related information from a running vista instance """
class VistAPackageInfoFetcher(object):
""" Patch install Status list """
PATCH_INSTALL_STATUS_LIST = [
"Loaded from Distribution", # status 0
"Queued for Install", # status 1
"Start of Install", # status 2
"Install Completed", # status 3
"De-Installed" # status 4
]
def __init__(self, vistATestClient):
self._testClient = vistATestClient
self._packageMapping = dict()
self._packagePatchHist = dict()
""" get all packages and package namespace mapping from a running Vista """
def createAllPackageMapping(self):
self._packageMapping.clear()
connection = self._testClient.getConnection()
result = None
menuUtil = VistAMenuUtil(duz=1) # set duz as 1
menuUtil.gotoFileManPrintFileEntryMenu(self._testClient)
# print file entry
connection.send("9.4\r") # Package file with fileman #9.4
connection.expect("SORT BY:")
connection.send("\r")
connection.expect("START WITH")
connection.send("\r")
connection.expect("FIRST PRINT FIELD:")
connection.send(".01\r") # fileman field# .01 is NAME
connection.expect("THEN PRINT FIELD:")
connection.send("1\r") # fileman field# 1 is the PREFIX
connection.expect("THEN PRINT FIELD:")
connection.send("\r")
connection.expect("PACKAGE LIST//")
connection.send("\r")
connection.expect("DEVICE:")
connection.send(";132;99999\r")
connection.expect("Select OPTION: ")
self.__parseAllPackages__(connection.before)
menuUtil.exitFileManMenu(self._testClient, waitOption=False)
def __parseAllPackages__(self, allPackageString):
MAX_PACKAGE_NAME_LEN = 32
allLines = allPackageString.split('\r\n')
packageStart = False
for line in allLines:
line = line.strip()
if len(line) == 0:
continue
if re.search("^-+$", line):
packageStart = True
continue
if packageStart:
packageName = line[:MAX_PACKAGE_NAME_LEN].strip()
packageNamespace = line[MAX_PACKAGE_NAME_LEN:].strip()
self._packageMapping[packageNamespace] = packageName
def getPackagePatchHistory(self, packageName, namespace, version=None):
if not self._packageMapping:
self.createAllPackageMapping()
connection = self._testClient.getConnection()
result = None
menuUtil = VistAMenuUtil(duz=1) # set duz as 1
menuUtil.gotoKidsUtilMenu(self._testClient)
connection.send("Display\r")
connection.expect("Select PACKAGE NAME:")
connection.send("%s\r" % packageName)
while True:
index = connection.expect(["Select VERSION: [0-9.VvTtPp]+\/\/",
"Select VERSION: ",
"Select Utilities ",
"CHOOSE [0-9]+-[0-9]+"])
if index == 3:
outchoice = findChoiceNumber(connection.before, packageName, namespace)
if outchoice:
connection.send("%s\r" % outchoice)
else: # no match
connection.send("\r")
continue
if index == 0 or index == 1:
if index == 0:
if version:
connection.send("%s\r" % version)
else:
connection.send("\r")
else:
connection.send("1.0\r")
""" handle the case that same version could also have different
history, like test version T1, T2 or V1, V2, or package does not
have a version information (old system)
"""
while True:
idx = connection.expect(["Do you want to see the Descriptions\?",
"CHOOSE [0-9]+-[0-9]+",
"Select VERSION: ",
"DEVICE:"])
if idx == 0:
connection.send("\r")
continue
elif idx == 1:
connection.send("1\r") # always use the latest one
continue
elif idx == 2:
connection.send('^\r')
break
elif idx ==3 :
connection.send(";132;99999\r")
break
connection.expect("Select Utilities ")
result = parsePackagePatchHistory(connection.before,
packageName, namespace, version)
break
else:
break
menuUtil.exitKidsUtilMenu(self._testClient)
if not result:
return result
assert result.version
# ignore the non-floating version
try:
curVer = float(result.version)
except ValueError as ve:
return None
if packageName not in self._packagePatchHist:
self._packagePatchHist[packageName] = dict()
verDict = self._packagePatchHist[packageName]
curVer = float(result.version)
if curVer in verDict:
logger.info("already has hist for ver:%s, package:%s" %
(result.version, packageName))
self._packagePatchHist[packageName][curVer] = result
return result
def getAllPatchesInstalledByTime(self, datetime):
if not self._packageMapping:
self.createAllPackageMapping()
if not self._packagePatchHist:
self.getAllPackagesPatchHistory()
outputResult = []
for packageName in self._packagePatchHist:
for ver in self._packagePatchHist[packageName]:
packageHistList = self._packagePatchHist[packageName][ver]
patchHist = packageHistList.patchHistory
for patchInfo in patchHist:
if patchInfo.datetime and patchInfo.datetime > datetime:
outputResult.append([packageHistList.namespace,
packageHistList.version,
patchInfo.patchNo,
patchInfo.seqNo,
patchInfo.datetime])
""" sort the result """
outputResult = sorted(outputResult, key=lambda item: item[4])
return outputResult
def getAllPatchInstalledAfterByTime(self, dateTime):
""" This will search install file to find out all patches installed
after specific time
"""
connection = self._testClient.getConnection()
menuUtil = VistAMenuUtil(duz=1)
menuUtil.gotoFileManSearchFileEntryMenu(self._testClient)
connection.send("9.7\r") # INSTALL file #
connection.expect("-A- SEARCH FOR INSTALL FIELD: ")
connection.send("17\r") # field # for INSTALL COMPLETE TIME
connection.expect("-A- CONDITION: ")
connection.send("GREATER THAN\r")
connection.expect("-A- GREATER THAN DATE: ")
connection.send("%s\r" % dateTime)
connection.expect("-B- SEARCH FOR INSTALL FIELD: ")
connection.send("\r")
connection.expect("IF: A// ")
connection.send("\r")
connection.expect("STORE RESULTS OF SEARCH IN TEMPLATE: ")
connection.send("\r")
connection.expect(["SORT BY: ", "SORT BY: NAME// "])
connection.send("17\r") # sort by INSTALL COMPLETE TIME
connection.expect(["START WITH INSTALL COMPLETE TIME: ",
"START WITH INSTALL COMPLETE TIME: FIRST// ",])
connection.send("\r")
connection.expect("WITHIN INSTALL COMPLETE TIME, SORT BY: ")
connection.send("\r")
connection.expect("FIRST PRINT FIELD: ")
connection.send("NAME\r")
connection.expect("THEN PRINT FIELD: ")
connection.send("17\r")
connection.expect("THEN PRINT FIELD: ")
connection.send("\r")
connection.expect("Heading \(S/C\): INSTALL SEARCH// ")
connection.send("\r") # use default heading
connection.expect("DEVICE:")
connection.send(";132;99999\r")
connection.expect("[0-9]+ MATCH(ES)? FOUND\.")
result = connection.before.split("\r\n")
output = []
resultStart = False
DATETIME_INDENT = 52
for line in result:
line = line.strip()
if len(line) == 0:
continue
if resultStart:
output.append((line[:DATETIME_INDENT].rstrip(),
datetime.strptime(line[DATETIME_INDENT:],
"%b %d,%Y %H:%M")))
continue
if re.search('^-+$',line):
resultStart = True
menuUtil.exitFileManMenu(self._testClient)
return output
def getAllPackagesPatchHistory(self):
self.createAllPackageMapping()
self._packagePatchHist.clear()
for (namespace, package) in self._packageMapping.iteritems():
logger.info("Parsing Package %s, namespace %s" % (package, namespace))
#if not (package[0] == "PHARMACY" and package[1] == "PS"): continue
self.getPackagePatchHistory(package, namespace)
def getPackagePatchHistByName(self, packageName, version=None):
if not self._packageMapping:
self.createAllPackageMapping()
if not packageName:
return None
if packageName in self._packagePatchHist:
result = self._getPackageHistListByVer(packageName, version)
if result:
return result
for (namespace, package) in self._packageMapping.iteritems():
if package == packageName:
result = self.getPackagePatchHistory(package, namespace, version)
return result
return None
def _getPackageHistListByVer(self, package, version):
verDict = self._packagePatchHist[package]
if version:
floatVer = float(version)
if floatVer in verDict:
return verDict[floatVer]
else:
return None
else:
return verDict[sorted(verDict.keys(),reverse=True)[0]]
def getPackagePatchHistByNamespace(self, namespace, version=None):
if not self._packageMapping:
self.createAllPackageMapping()
if namespace in self._packageMapping:
package = self._packageMapping[namespace]
if package in self._packagePatchHist:
result = self._getPackageHistListByVer(package, version)
if result:
return result
result = self.getPackagePatchHistory(package, namespace, version)
return result
def hasPatchHistoryList(self, namespace):
if namespace not in self._packageMapping:
return False
return self._packageMapping[namespace] in self._packagePatchHist
def getPackageMapping(self):
return self._packageMapping
def getPackagePatchHistoryMap(self):
return self._packagePatchHist
def getPackageName(self, namespace):
return self._packageMapping.get(namespace)
def getPackageNamespaceByName(self, pgkName):
for (namespace, packageName) in self._packageMapping.iteritems():
if pgkName == packageName:
return namespace
return None
def hasNamespace(self, namespace):
return namespace in self._packageMapping
""" check to see if patch is already installed via patch history """
def hasPatchInstalled(self, installName, namespace, version,
patchNo, seqNo = None):
if namespace not in self._packageMapping:
logger.info("this is a new namespace %s" % namespace)
return False
packageName = self._packageMapping[namespace]
if packageName not in self._packagePatchHist:
patchHist = self.getPackagePatchHistByNamespace(namespace, version)
else:
patchHist = self._getPackageHistListByVer(packageName, version)
if not patchHist:
patchHist = self.getPackagePatchHistByNamespace(namespace, version)
if patchHist:
if seqNo:
if patchHist.hasSeqNo(seqNo):
return True
if patchHist.version:
try:
if float(patchHist.version) != float(version):
logger.info("Diff ver %s, %s" % (patchHist.version, version))
except Exception as ex:
logger.error(ex)
if patchNo:
return patchHist.hasPatchNo(patchNo)
status = self.getInstallationStatus(installName)
return self.isInstallCompleted(status)
""" check to see if the installation is not installed """
@staticmethod
def isNotInstalled(status):
return status == -1
""" check to see if the installation is loaded from distribution"""
@staticmethod
def isLoadedFromDistribution(status):
return status == 0
""" check to see if the installation is Queued for install"""
@staticmethod
def isQueuedForInstall(status):
return status == 1
""" check to see if the installation is already started """
@staticmethod
def isInstallStarted(status):
return status == 2
""" check to see if the installation is completed """
@staticmethod
def isInstallCompleted(status):
return status == 3
""" check to see if the installation is De-installed """
@staticmethod
def isDeinstalled(status):
return status == 4
""" get the installation status for an install
@parameter installName: patch KIDS install name
@return -1 if installName not found
0 if Loaded from Distribution
1 if Queued for install
2 if Start of Install
3 if Install Completed
4 if De-installed
"""
def getInstallationStatus(self, installName):
connection = self._testClient.getConnection()
result = -1 # default is not installed
menuUtil = VistAMenuUtil(duz=1)
menuUtil.gotoFileManInquireFileEntryMenu(self._testClient)
connection.send("9.7\r") # Package file with fileman #9.7
connection.expect("Select INSTALL NAME:")
connection.send("%s\r" % installName)
while True:
index = connection.expect(["Select INSTALL NAME: ",
"ANOTHER ONE: ",
"CHOOSE 1-[0-9]+: "])
if index == 0:
connection.send("\r")
break
elif index == 1:
txtToSearch = connection.before.replace("\r\n","")
logger.debug(txtToSearch)
result = indexOfInstallStatus(txtToSearch)
connection.send("^\r")
break
# handle if the install has multiple install status
elif index == 2:
linesToSearch = connection.before.split("\r\n")
for line in linesToSearch: # only care the the first line
line = line.strip("\r\n ")
if not re.search("^1 ", line): continue
result = indexOfInstallStatus(line)
break
connection.send("^\r")
continue
menuUtil.exitFileManMenu(self._testClient)
return result
""" use Kernel KIDS API to check the installation status.
This method might not work if install name does not
belong to a namespace, like "ECLAIM BUNDLE 1.0".
"""
def isPatchInstalled(self, installName):
connection = self._testClient.getConnection()
self._testClient.waitForPrompt()
connection.send('W $$PATCH^XPDUTL("%s")\r' % installName)
self._testClient.waitForPrompt()
connection.send('\r')
result = connection.before
for line in result.split('\r\n'):
line = line.strip(' \r\n')
if re.search('^[0-1]$', line):
try:
if int(line) == 1:
return True
except ValueError as ve:
pass
return False
def printPackagePatchHist(self, packageName):
import pprint
if packageName in self._packagePatchHist:
print ("-----------------------------------------")
print ("--- Package %s Patch History Info ---" % packageName)
print ("-----------------------------------------")
verDict = self._packagePatchHist[packageName]
for ver in sorted(verDict.keys(), reverse=True):
pprint.pprint(verDict[float(ver)].patchHistory)
def printPackageLastPatch(self, packageName):
import pprint
if packageName in self._packagePatchHist:
print ("-----------------------------------------")
print ("--- Package %s Last Patch Info ---" % packageName)
print ("-----------------------------------------")
verDict = self._packagePatchHist[packageName]
for ver in sorted(verDict.keys(), reverse=True):
pprint.pprint("VERSION: %s" % ver)
pprint.pprint(verDict[float(ver)].patchHistory[-1])
""" a utility class to find out the choice number from VistA choice prompt """
def findChoiceNumber(choiceTxt, matchString, extraInfo=None):
logger.debug("txt is [%s]" % choiceTxt)
matchRegEx = None
if extraInfo and len(extraInfo) > 0:
matchRegEx = re.compile('^ +(?P<number>[0-9]+) %s +%s$' %
(matchString, extraInfo))
else:
matchRegEx = re.compile('^ +(?P<number>[0-9]+) %s$' % (matchString))
choiceLines = choiceTxt.split('\r\n')
for line in choiceLines:
line = line.rstrip()
if len(line) == 0:
continue
result = matchRegEx.search(line)
if result:
return result.group('number')
else:
continue
return None
"""Store the Patch History related to a Package
"""
class PackagePatchHistory(object):
def __init__(self, packageName, namespace):
self.packageName = packageName
self.namespace = namespace
self.patchHistory = []
self.version = None
def addPatchInstallLog(self, PatchInstallLog):
self.patchHistory.append(PatchInstallLog)
def hasPatchHistory(self):
return len(self.patchHistory) > 0
def setVersion(self, version):
self.version = version
def hasSeqNo(self, seqNo):
for patchLog in self.patchHistory:
if patchLog.seqNo == int(seqNo):
return True
return False
def hasPatchNo(self, patchNo):
for patchLog in self.patchHistory:
if patchLog.patchNo == int(patchNo):
return True;
return False
def getLastPatchInfo(self):
if len(self.patchHistory) == 0:
return None
return self.patchHistory[-1]
def getLatestSeqNo(self):
if not self.hasPatchHistory():
return 0
last = len(self.patchHistory)
for index in range(last,0,-1):
patchLog = self.patchHistory[index-1]
if patchLog.seqNo:
return patchLog.seqNo
return 0
def __str__(self):
return self.patchHistory.__str__()
def __repr__(self):
return self.patchHistory.__str__()
"""
a class to parse and store Patch install history info
"""
class PatchInstallLog(object):
PATCH_HISTORY_LINE_REGEX = re.compile("^ [0-9]")
PATCH_VERSION_LINE_REGEX = re.compile("^VERSION: [0-9.]+ ?")
PATCH_VERSION_START_INDEX = 3
PATCH_APPLIED_DATETIME_INDEX = 20
PATCH_APPLIED_USERNAME_INDEX = 50
DATETIME_FORMAT_STRING = "%b %d, %Y@%H:%M:%S"
DATE_FORMAT_STRING = "%b %d, %Y"
DATE_TIME_SEPERATOR = "@"
def __init__(self, historyLine):
self.patchNo = None
self.seqNo = None
self.datetime = None
self.userName = None
self.version = None
self.__parseHistoryLine__(historyLine)
def __parseHistoryLine__(self, historyLine):
totalLen = len(historyLine)
if totalLen < self.PATCH_VERSION_START_INDEX:
return
pos = historyLine.find(";Created on") # handle informal history line
datetimeIndent = self.PATCH_APPLIED_DATETIME_INDEX
userIndent = self.PATCH_APPLIED_USERNAME_INDEX
if pos >= 0: # ignore the Created on format
logger.debug(historyLine)
historyLine = historyLine[:pos].rstrip()
totalLen = len(historyLine)
if totalLen > datetimeIndent:
historyLine = historyLine.split('-')[0].rstrip()
totalLen = len(historyLine)
logger.debug("total len is %d" % totalLen)
if totalLen > userIndent:
self.userName = historyLine[userIndent:].strip()
if totalLen > datetimeIndent:
datetimePart = historyLine[datetimeIndent:userIndent].strip()
pos = datetimePart.find(self.DATE_TIME_SEPERATOR)
if pos >=0:
if len(datetimePart) - pos == 3:
datetimePart += ":00:00"
if len(datetimePart) - pos == 6:
datetimePart +=":00"
self.datetime = datetime.strptime(datetimePart,
self.DATETIME_FORMAT_STRING)
else:
self.datetime = datetime.strptime(datetimePart, self.DATE_FORMAT_STRING)
if self.isVersionLine(historyLine):
self.__parseVersionInfo__(
historyLine[:datetimeIndent].strip())
return
patchPart = historyLine[self.PATCH_VERSION_START_INDEX:datetimeIndent]
seqIndex = patchPart.find("SEQ #")
if seqIndex >= 0:
self.patchNo = int(patchPart[:seqIndex].strip())
self.seqNo = int(patchPart[seqIndex+5:].strip())
else:
try:
self.patchNo = int(patchPart.strip())
except ValueError as ex:
print ex
logger.error("History Line is %s" % historyLine)
self.patchNo = 0
def hasVersion(self):
return self.version != None
def __parseVersionInfo__(self, historyLine):
self.seqNo = None
self.patchNo = None
self.version = historyLine[historyLine.find("VERSION: ")+9:]
@staticmethod
def isValidHistoryLine(historyLine):
return PatchInstallLog.isPatchLine(historyLine) or PatchInstallLog.isVersionLine(historyLine)
@staticmethod
def isPatchLine(patchLine):
return PatchInstallLog.PATCH_HISTORY_LINE_REGEX.search(patchLine) != None
@staticmethod
def isVersionLine(versionLine):
return PatchInstallLog.PATCH_VERSION_LINE_REGEX.search(versionLine) != None
def __str__(self):
retString = ""
if self.version:
retString += "Ver: %s " % self.version
if self.patchNo:
retString += "%d" % self.patchNo
if self.seqNo:
retString += " SEQ #%d" % self.seqNo
if self.datetime:
retString += " %s " % self.datetime.strftime(self.DATETIME_FORMAT_STRING)
if self.userName:
retString += " %s" % self.userName
return retString
def __repr__(self):
return self.__str__()
""" Utility Function to check to see if has the right install status """
def indexOfInstallStatus(statusTxt):
statusList = VistAPackageInfoFetcher.PATCH_INSTALL_STATUS_LIST
for idx in range(0,len(statusList)):
if re.search(statusList[idx], statusTxt, re.IGNORECASE):
return idx
return -1
""" function to convert package patch history into PackagePatchHistory """
def parsePackagePatchHistory(historyString, packageName, namespace, version):
allLines = historyString.split('\r\n')
patchHistoryStart = False
result = None
for line in allLines:
line = line.rstrip()
if len(line) == 0:
continue
if re.search("^-+$", line): # find line with '----'
patchHistoryStart = True
continue
if patchHistoryStart:
if not PatchInstallLog.isValidHistoryLine(line):
continue
if not result: result = PackagePatchHistory(packageName, namespace)
patchLog = PatchInstallLog(line)
result.addPatchInstallLog(patchLog)
if patchLog.hasVersion():
if version:
try:
if float(version) != float(patchLog.version):
logger.error("version mismatch, %s:%s" %
(version, patchLog.version))
except ValueError as ve:
logger.error(ve)
result.setVersion(patchLog.version)
return result
""" test the fetcher class """
def testMain():
testClient = createTestClient()
import logging
with testClient:
initConsoleLogging(logging.INFO)
packagePatchHist = VistAPackageInfoFetcher(testClient)
packagePatchHist.getAllPackagesPatchHistory()
packagePatchHist.getPackagePatchHistByName("TOOLKIT")
packagePatchHist.printPackageLastPatch("TOOLKIT")
packagePatchHist.getPackagePatchHistByNamespace("FMDC")
packagePatchHist.printPackagePatchHist("FILEMAN DELPHI COMPONENTS")
packagePatchHist.getPackagePatchHistByName("IMAGING")
packagePatchHist.printPackageLastPatch("IMAGING")
packagePatchHist.getPackagePatchHistByNamespace("VPR")
packagePatchHist.printPackagePatchHist("VIRTUAL PATIENT RECORD")
packagePatchHist.printPackageLastPatch("VIRTUAL PATIENT RECORD")
packagePatchHist.getPackagePatchHistByNamespace("DENT")
packagePatchHist.printPackagePatchHist("DENTAL")
packagePatchHist.getPackagePatchHistByNamespace("NUPA")
packagePatchHist.printPackagePatchHist("PATIENT ASSESSMENT DOCUM")
def createTestClient():
testClientParser = createTestClientArgParser()
parser = argparse.ArgumentParser(description='VistA Patch Info Query',
parents=[testClientParser])
result = parser.parse_args();
print (result)
testClient = VistATestClientFactory.createVistATestClientWithArgs(result)
return testClient
def testIsInstallCompleted():
testClient = createTestClient()
assert testClient
import logging
with testClient:
initConsoleLogging(logging.INFO)
packagePatchHist = VistAPackageInfoFetcher(testClient)
installNameLst = [
"ECLAIMS 5 BUNDLE 1.0",
"TEST 1.0",
"XOBU 1.6",
"LR*5.2*334",
"XU*8.0*80",
"TERATOGENIC MEDICATIONS ORDER CHECKS 1.0"
]
for installName in installNameLst:
result = packagePatchHist.isPatchInstalled(installName)
if not result:
print ("%s installation status is %s" % (installName, "Not Installed"))
else:
print ("%s installation status is %s" % (installName, "Installed"))
result = packagePatchHist.getInstallationStatus(installName)
if packagePatchHist.isNotInstalled(result):
print ("%s installation status is %s" % (installName, "Not Installed"))
else:
print ("%s installation status is %s" % (installName,
packagePatchHist.PATCH_INSTALL_STATUS_LIST[result]))
def main():
testClient = createTestClient()
assert testClient
import logging
with testClient:
import pprint
initConsoleLogging(logging.INFO)
packagePatchHist = VistAPackageInfoFetcher(testClient)
packagePatchHist.getPackagePatchHistByNamespace("DI")
packagePatchHist.printPackagePatchHist("VA FILEMAN")
output = packagePatchHist.getAllPatchesInstalledByTime(datetime(2012,8,24))
pprint.pprint(output)
output = packagePatchHist.getAllPatchInstalledAfterByTime("T-365")
pprint.pprint(output)
if __name__ == '__main__':
testIsInstallCompleted()
main()