1
1
# Written by Henrik Nilsen Omma
2
2
# (C) Canonical, Ltd. Licensed under the GPL
8
9
from infoFilesDefinitions import clueCondition as clueCondition
9
10
from infoFilesDefinitions import bugClue as bugClue
12
def search_ng(cond,attribute,case_sensitive=None):
13
if type(attribute) == str:
15
if cond.startswith("r'") and cond.endswith("'"):
16
res = re.search(cond, attribute, re.MULTILINE) is not None
18
res = attribute.count(cond)>0
20
low_text =attribute.lower()
21
a = re.search(r"^r'(.*)'$",cond)
23
res = re.search(a.group(1), low_text, re.MULTILINE|re.IGNORECASE) is not None
25
low_cond = cond.lower()
26
res = low_text.count(cond.lower())>0
29
elif type(attribute) == list or type(attribute) == tuple:
30
a = [search_ng(cond,l) for l in attribute]
32
if True in a: return True
36
assert None, "Unknown type of attribute: %s" % type(attribute)
11
39
class InfoFiles(object):
12
40
def __init__(self, packages_dirs):
13
41
self.files = dict()
73
101
self.inherited_clues = inherited_clues
76
def clue_matches(self, clue, text, case_sensitive=False):
104
def clue_matches(self, clue, bug_or_attachment, case_sensitive=False):
77
105
for condition in clue.conditions:
78
return self.condition_matches(condition, text, case_sensitive)
107
return self.condition_matches(condition, bug_or_attachment, case_sensitive)
108
except AttributeError:
80
def condition_matches(self, cond, text, case_sensitive=False):
111
def condition_matches(self, cond, bug_or_attachment, case_sensitive=False):
81
112
if cond.simple_cond:
83
res = text.count(urllib.unquote(cond.simple_cond))>0
113
#print "tags:",getattr(bug_or_attachment,"proptags",None)
114
#print type(getattr(bug_or_attachment,"text",None))
116
# search only in attribute given by cond.cond_field
117
# if the bug_or_attachment-object does not have the given attribute
118
# this raises an AttributeError, this AttributeError is
119
# catched in clue_matches with the result, that is clue
121
search_text = getattr(bug_or_attachment,cond.cond_field)
85
low_text = text.lower()
86
low_cond = urllib.unquote(cond.simple_cond).lower()
87
res = low_text.count(low_cond)>0
123
search_text = bug_or_attachment.text
125
res = search_ng(cond.simple_cond, search_text,case_sensitive)
88
126
return cond.not_cond != res
91
129
res = len(cond.and_cond) == \
92
[self.condition_matches(n, text, case_sensitive) \
130
[self.condition_matches(n, bug_or_attachment, case_sensitive) \
93
131
for n in cond.and_cond].count(True)
94
132
return cond.not_cond != res
97
res = [self.condition_matches(n, text, case_sensitive) \
135
res = [self.condition_matches(n, bug_or_attachment, case_sensitive) \
98
136
for n in cond.or_cond].count(True) != 0
99
137
return cond.not_cond != res