-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility.py
executable file
·71 lines (57 loc) · 2.58 KB
/
utility.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
""" utility.py: check_cvc utility functions
Functions:
OpenFile: Open a possibly compressed file and return file structure.
CompareErrors: Compare 2 error records and return "<", "=", ">", or "?".
Copyright 2106, 2017 D. Mitch Bailey d.mitch.bailey at gmail dot com
This file is part of check_cvc.
check_cvc is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
check_cvc is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with check_cvc. If not, see <http://www.gnu.org/licenses/>.
You can download check_cvc from https://github.com/d-m-bailey/check_cvc.git
"""
from __future__ import division
from __future__ import print_function
import gzip
def OpenFile(theFileName, theMode="r"):
"""Open a possibly compressed file and return file structure.
Errors need to be handled in calling routine.
"""
if theFileName.endswith(".gz"):
myFile = gzip.open(theFileName, mode=theMode + "t")
else:
myFile = open(theFileName, theMode)
return myFile
def CompareErrors(theFirstItem, theSecondItem, thePrintFlag=False):
"""Compare 2 error records and return "<", "=", ">", or "?".
If one value is undefined, the other is less.
If both values are undefined, return "?".
If the priorities are different, use priorities.
If the priorities are the same, use the error data.
"""
if thePrintFlag:
print("first", theFirstItem)
print("second", theSecondItem)
if theFirstItem and not theSecondItem:
return "<"
elif not theFirstItem and theSecondItem:
return ">"
elif not theFirstItem and not theSecondItem:
return "?"
elif theFirstItem['priority'] < theSecondItem['priority']:
return "<"
elif theFirstItem['priority'] > theSecondItem['priority']:
return ">"
elif theFirstItem['keyData'] < theSecondItem['keyData']:
return "<"
elif theFirstItem['keyData'] > theSecondItem['keyData']:
return ">"
else:
return "="
#23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789