~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/scripts/bugzilla.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:
31
31
from zope.component import getUtility
32
32
 
33
33
from canonical.launchpad.interfaces.emailaddress import IEmailAddressSet
 
34
from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities
34
35
from canonical.launchpad.interfaces.librarian import ILibraryFileAliasSet
 
36
from canonical.launchpad.interfaces.message import IMessageSet
35
37
from canonical.launchpad.webapp import canonical_url
36
38
from lp.app.errors import NotFoundError
37
 
from lp.app.interfaces.launchpad import ILaunchpadCelebrities
38
39
from lp.bugs.interfaces.bug import (
39
40
    CreateBugParams,
40
41
    IBugSet,
54
55
    IPersonSet,
55
56
    PersonCreationRationale,
56
57
    )
57
 
from lp.services.messages.interfaces.message import IMessageSet
58
58
 
59
59
 
60
60
logger = logging.getLogger('lp.bugs.scripts.bugzilla')
61
61
 
62
 
 
63
62
def _add_tz(dt):
64
63
    """Convert a naiive datetime value to a UTC datetime value."""
65
64
    assert dt.tzinfo is None, 'add_tz() only accepts naiive datetime values'
67
66
                             dt.hour, dt.minute, dt.second,
68
67
                             dt.microsecond, tzinfo=pytz.timezone('UTC'))
69
68
 
70
 
 
71
69
class BugzillaBackend:
72
70
    """A wrapper for all the MySQL database access.
73
71
 
210
208
                            'ORDER BY dupe, dupe_of')
211
209
        return [(dupe_of, dupe) for (dupe_of, dupe) in self.cursor.fetchall()]
212
210
 
213
 
 
214
211
class Bug:
215
212
    """Representation of a Bugzilla Bug"""
216
213
    def __init__(self, backend, bug_id):
372
369
 
373
370
        return person
374
371
 
375
 
    def _getPackageName(self, bug):
376
 
        """Returns the source package name for the given bug."""
 
372
    def _getPackageNames(self, bug):
 
373
        """Returns the source and binary package names for the given bug."""
377
374
        # we currently only support mapping Ubuntu bugs ...
378
375
        if bug.product != 'Ubuntu':
379
376
            raise AssertionError('product must be Ubuntu')
392
389
            pkgname = bug.component.encode('ASCII')
393
390
 
394
391
        try:
395
 
            return self.ubuntu.guessPublishedSourcePackageName(pkgname)
 
392
            srcpkg, binpkg = self.ubuntu.guessPackageNames(pkgname)
396
393
        except NotFoundError, e:
397
394
            logger.warning('could not find package name for "%s": %s',
398
395
                           pkgname, str(e))
399
 
            return None
 
396
            srcpkg = binpkg = None
 
397
 
 
398
        return srcpkg, binpkg
400
399
 
401
400
    def getLaunchpadBugTarget(self, bug):
402
401
        """Returns a dictionary of arguments to createBug() that correspond
403
402
        to the given bugzilla bug.
404
403
        """
405
 
        srcpkg = self._getPackageName(bug)
 
404
        srcpkg, binpkg = self._getPackageNames(bug)
406
405
        return {
407
406
            'distribution': self.ubuntu,
408
407
            'sourcepackagename': srcpkg,
436
435
        This function relies on the package -> product linkage having been
437
436
        entered in advance.
438
437
        """
439
 
        srcpkgname = self._getPackageName(bug)
 
438
        srcpkgname, binpkgname = self._getPackageNames(bug)
440
439
        # find a product series
441
440
        series = None
442
441
        for series in self.ubuntu.series:
451
450
            return None
452
451
 
453
452
    _bug_re = re.compile('bug\s*#?\s*(?P<id>\d+)', re.IGNORECASE)
454
 
 
455
453
    def replaceBugRef(self, match):
456
454
        # XXX: jamesh 2005-10-24:
457
455
        # this is where bug number rewriting would be plugged in
459
457
        url = '%s/%d' % (canonical_url(self.bugtracker), bug_id)
460
458
        return '%s [%s]' % (match.group(0), url)
461
459
 
 
460
 
462
461
    def handleBug(self, bug_id):
463
462
        """Maybe import a single bug.
464
463
 
618
617
         * bug A' is a duplicate of bug B'
619
618
         * bug A is not currently a duplicate of any other bug.
620
619
        """
621
 
 
622
620
        logger.info('Processing duplicate bugs')
623
621
        bugmap = {}
624
 
 
625
622
        def getlpbug(bugid):
626
623
            """Get the Launchpad bug corresponding to the given remote ID
627
624