~ubuntu-branches/ubuntu/precise/bughelper/precise

« back to all changes in this revision

Viewing changes to bugHelper/infoFiles.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-04-10 11:54:41 UTC
  • Revision ID: james.westby@ubuntu.com-20070410115441-7hix742g1qi8ztp7
Tags: 0.2~169
* Fixed numerous bugs. (LP: #93658, #89728, #95223, #81434, #99586, #102355,
  #99642, #103318, #102480, #107554 ,#107735, #107959, #99726, #79136,
  #79136, #79136, #79140, #109533, #79140, #109533).
* debian/control:
  - updated XS-Vcs-Bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Written by Henrik Nilsen Omma
2
2
# (C) Canonical, Ltd. Licensed under the GPL
3
3
 
 
4
import re
4
5
import os
5
 
import urllib
 
6
import urllib2
6
7
 
7
8
import XMLOperations
8
9
from infoFilesDefinitions import clueCondition as clueCondition
9
10
from infoFilesDefinitions import bugClue as bugClue
10
11
 
 
12
def search_ng(cond,attribute,case_sensitive=None):
 
13
    if type(attribute) == str:
 
14
        if case_sensitive:
 
15
            if cond.startswith("r'") and cond.endswith("'"):
 
16
                res = re.search(cond, attribute, re.MULTILINE) is not None
 
17
            else:
 
18
                res = attribute.count(cond)>0
 
19
        else:
 
20
            low_text =attribute.lower()
 
21
            a = re.search(r"^r'(.*)'$",cond)
 
22
            if a:
 
23
                res = re.search(a.group(1), low_text, re.MULTILINE|re.IGNORECASE) is not None
 
24
            else:
 
25
                low_cond = cond.lower()
 
26
                res = low_text.count(cond.lower())>0
 
27
        return res
 
28
        
 
29
    elif type(attribute) == list or type(attribute) == tuple:
 
30
        a = [search_ng(cond,l) for l in attribute]
 
31
        #print a
 
32
        if True in a: return True
 
33
        return False
 
34
 
 
35
    else:
 
36
        assert None, "Unknown type of attribute: %s" % type(attribute)
 
37
 
 
38
 
11
39
class InfoFiles(object):
12
40
    def __init__(self, packages_dirs):
13
41
        self.files = dict()
73
101
        self.inherited_clues = inherited_clues
74
102
        
75
103
 
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)
 
106
            try:
 
107
                return self.condition_matches(condition, bug_or_attachment, case_sensitive)
 
108
            except AttributeError:
 
109
                return False
79
110
 
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:
82
 
            if case_sensitive:
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))
 
115
            if cond.cond_field:
 
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
 
120
                # does not match
 
121
                search_text = getattr(bug_or_attachment,cond.cond_field)
84
122
            else:
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
 
124
           
 
125
            res = search_ng(cond.simple_cond, search_text,case_sensitive)
88
126
            return cond.not_cond != res
89
127
        
90
128
        if cond.and_cond:
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
95
133
            
96
134
        if cond.or_cond:
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
100
138
 
101
139
        return False
102