-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlib.py
120 lines (73 loc) · 2.74 KB
/
lib.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
import re
class MailMessage(object):
def __init__(self, sender, date, subject, uid):
self.sender = sender
self.date = date
self.subject = subject
self.uid = uid
class SearchTechnic(object):
def __init__(self, name, success, warning, failed):
self.name = name
self.senders = []
self.mails = []
self.criterias = []
self.resultState = ResultState(success, warning, failed)
def addCriteria(self, criteria):
self.criterias += [criteria]
def addSender(self, sender):
self.senders += [sender]
def addMail(self, mail):
self.mails += [mail]
def isValid(self, string):
pos = False;
neg = True;
for criteria in self.criterias:
if criteria.boolean == False:
neg = neg and criteria.isValid(string)
else:
pos = pos or criteria.isValid(string)
return neg and pos
def getState(self, string):
if self.resultState.isSuccess(string):
return 'Success'
elif self.resultState.isWarning(string):
return 'Warning'
elif self.resultState.isFailed(string):
return 'Failed'
else:
return 'State undefined'
def getPartSubject(self, string, index):
array = string.split(' - ')
return array[index]
class Criteria(object):
def __init__(self, string, boolean):
self.string = string
self.boolean = boolean
def isValid(self, string):
return (self.string in string) == self.boolean
class ResultState(object):
def __init__(self, success, warning, failed):
self.success = success
self.warning = warning
self.failed = failed
def isSuccess(self, string):
return self.success != None and self.success in string
def isWarning(self, string):
return self.warning != None and self.warning in string
def isFailed(self, string):
return self.failed != None and self.failed in string
class NameTranslation(object):
def __init__(self):
self.names = []
def add(self, searchName, displayName = None):
if displayName == None: displayName = searchName
self.names += [[searchName, displayName]]
def find(self, string):
for name in self.names:
if name[0] in string:
return name[1]
return 'Unknown'
def parse_uid(data):
pattern_uid = re.compile('\d+ \(UID (?P<uid>\d+)\)')
match = pattern_uid.match(data.decode('utf-8'))
return match.group('uid')