~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to cronscripts/update-debwatches.py

  • Committer: Francis J. Lacoste
  • Date: 2011-04-27 21:40:03 UTC
  • mto: This revision was merged to the branch mainline in revision 12971.
  • Revision ID: francis.lacoste@canonical.com-20110427214003-iiqhcyyswppyqjsx
Change the default timeout to production value, improved options documentation and use only one bin above timeout value.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# zope bits
16
16
from zope.component import getUtility
17
17
 
18
 
from canonical.database.constants import UTC_NOW
19
 
from lp.app.errors import NotFoundError
20
 
from lp.app.interfaces.launchpad import ILaunchpadCelebrities
21
18
from lp.bugs.interfaces.bug import IBugSet
22
19
from lp.bugs.interfaces.bugtask import (
23
20
    BugTaskSearchParams,
28
25
from lp.bugs.scripts import debbugs
29
26
from lp.services.scripts.base import (LaunchpadCronScript,
30
27
    LaunchpadScriptFailure)
31
 
from lp.services.messages.interfaces.message import (
 
28
from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities
 
29
from canonical.launchpad.interfaces.message import (
32
30
    InvalidEmailMessage,
33
31
    IMessageSet,
34
32
    )
35
 
 
 
33
from canonical.database.constants import UTC_NOW
36
34
 
37
35
# setup core values and defaults
38
36
debbugs_location_default = '/srv/bugs-mirror.debian.org/'
42
40
    loglevel = logging.WARNING
43
41
 
44
42
    def add_my_options(self):
45
 
        self.parser.add_option(
46
 
            '--max', action='store', type='int', dest='max',
 
43
        self.parser.add_option('--max', action='store', type='int', dest='max',
47
44
            default=None, help="The maximum number of bugs to synchronise.")
48
45
        self.parser.add_option('--debbugs', action='store', type='string',
49
46
            dest='debbugs',
51
48
            help="The location of your debbugs database.")
52
49
 
53
50
    def main(self):
54
 
        if not os.path.exists(
55
 
            os.path.join(self.options.debbugs, 'index/index.db')):
 
51
        if not os.path.exists(os.path.join(self.options.debbugs, 'index/index.db')):
56
52
            raise LaunchpadScriptFailure('%s is not a debbugs db.'
57
53
                                         % self.options.debbugs)
58
54
 
71
67
        debwatches = debbugs_tracker.watches
72
68
 
73
69
        previousimportset = set([b.remotebug for b in debwatches])
74
 
        self.logger.info(
75
 
            '%d debbugs previously imported.' % len(previousimportset))
 
70
        self.logger.info('%d debbugs previously imported.' % len(previousimportset))
76
71
 
77
72
        target_watches = [watch for watch in debwatches if watch.needscheck]
78
 
        self.logger.info(
79
 
            '%d debbugs watches to syncronise.' % len(target_watches))
 
73
        self.logger.info('%d debbugs watches to syncronise.' % len(target_watches))
80
74
 
81
75
        self.logger.info('Sorting bug watches...')
82
76
        target_watches.sort(key=lambda a: a.remotebug)
105
99
        debian = getUtility(ILaunchpadCelebrities).debian
106
100
        debbugs_tracker = getUtility(ILaunchpadCelebrities).debbugs
107
101
 
108
 
        # make sure we have tasks for all the debian package linkages, and
109
 
        # also make sure we have updated their status and severity
110
 
        # appropriately.
 
102
        # make sure we have tasks for all the debian package linkages, and also
 
103
        # make sure we have updated their status and severity appropriately
111
104
        for packagename in debian_bug.packagelist():
112
105
            try:
113
 
                srcpkgname = debian.guessPublishedSourcePackageName(
114
 
                    packagename)
115
 
            except NotFoundError:
 
106
                srcpkgname, binpkgname = debian.guessPackageNames(packagename)
 
107
            except ValueError:
116
108
                self.logger.error(sys.exc_value)
117
109
                continue
118
110
            search_params = BugTaskSearchParams(user=None, bug=malone_bug,
121
113
            bugtasks = bugtaskset.search(search_params)
122
114
            if len(bugtasks) == 0:
123
115
                # we need a new task to link the bug to the debian package
124
 
                self.logger.info('Linking %d and debian %s' % (
125
 
                    malone_bug.id, srcpkgname.name))
 
116
                self.logger.info('Linking %d and debian %s/%s' % (
 
117
                    malone_bug.id, srcpkgname.name, binpkgname.name))
126
118
                # XXX: kiko 2007-02-03:
127
119
                # This code is completely untested and broken.
128
120
                bugtask = malone_bug.addTask(
134
126
                assert len(bugtasks) == 1, 'Should only find a single task'
135
127
                bugtask = bugtasks[0]
136
128
            status = bugtask.status
137
 
            if status != bugtask.setStatusFromDebbugs(debian_bug.status):
 
129
            if status <> bugtask.setStatusFromDebbugs(debian_bug.status):
138
130
                waschanged = True
139
131
            severity = bugtask.severity
140
 
            if severity != bugtask.setSeverityFromDebbugs(
141
 
                debian_bug.severity):
 
132
            if severity <> bugtask.setSeverityFromDebbugs(debian_bug.severity):
142
133
                waschanged = True
143
134
 
144
135
        known_msg_ids = set([msg.rfc822msgid for msg in malone_bug.messages])
165
156
            if msg is None:
166
157
                continue
167
158
 
168
 
            # Create the link between the bug and this message.
169
 
            malone_bug.linkMessage(msg)
 
159
            # create the link between the bug and this message
 
160
            bugmsg = malone_bug.linkMessage(msg)
170
161
 
171
 
            # ok, this is a new message for this bug, so in effect something
172
 
            # has changed
 
162
            # ok, this is a new message for this bug, so in effect something has
 
163
            # changed
173
164
            waschanged = True
174
165
 
175
166
            # now we need to analyse the message for useful data
176
167
            watches = bugwatchset.fromMessage(msg, malone_bug)
177
168
            for watch in watches:
178
 
                self.logger.info(
179
 
                    'New watch for #%s on %s' % (watch.bug.id, watch.url))
 
169
                self.logger.info('New watch for #%s on %s' % (watch.bug.id, watch.url))
180
170
                waschanged = True
181
171
 
182
172
            # and also for CVE ref clues
200
190
        if (len(debian_bug.mergedwith) > 0 and
201
191
            min(debian_bug.mergedwith) > debian_bug.id):
202
192
            for merged_id in debian_bug.mergedwith:
203
 
                merged_bug = bugset.queryByRemoteBug(
204
 
                    debbugs_tracker, merged_id)
 
193
                merged_bug = bugset.queryByRemoteBug(debbugs_tracker, merged_id)
205
194
                if merged_bug is not None:
206
195
                    # Bug has been imported already
207
196
                    if merged_bug.duplicateof == malone_bug:
209
198
                        continue
210
199
                    elif merged_bug.duplicateof is not None:
211
200
                        # Interesting, we think it's a dup of something else
212
 
                        self.logger.warning(
213
 
                            'Debbugs thinks #%d is a dup of #%d' % (
 
201
                        self.logger.warning('Debbugs thinks #%d is a dup of #%d' % (
214
202
                            merged_bug.id, merged_bug.duplicateof))
215
203
                        continue
216
204
                    # Go ahead and merge it
217
 
                    self.logger.info(
218
 
                        "Malone #%d is a duplicate of Malone #%d" % (
 
205
                    self.logger.info("Malone #%d is a duplicate of Malone #%d" % (
219
206
                        merged_bug.id, malone_bug.id))
220
207
                    merged_bug.duplicateof = malone_bug.id
221
208
 
223
210
                    waschanged = True
224
211
 
225
212
        # make a note of the remote watch status, if it has changed
226
 
        if watch.remotestatus != debian_bug.status:
 
213
        if watch.remotestatus <> debian_bug.status:
227
214
            watch.remotestatus = debian_bug.status
228
215
            waschanged = True
229
216
 
238
225
if __name__ == '__main__':
239
226
    script = DebWatchUpdater('launchpad-debbugs-sync')
240
227
    script.lock_and_run()
 
228