~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/model/bugtracker.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-05-23 18:43:31 UTC
  • mfrom: (13084.2.6 page-match-rewrite-url)
  • Revision ID: launchpad@pqm.canonical.com-20110523184331-dhd2c7cgfuu49epw
[r=sinzui][bug=784273] Adds facility to the PageMatch to handle bad
        URIs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
# pylint: disable-msg=E0611,W0212
58
58
    SQLBase,
59
59
    )
60
60
from canonical.launchpad.helpers import shortlist
 
61
from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities
61
62
from canonical.launchpad.interfaces.lpstorm import IStore
62
63
from canonical.launchpad.webapp.interfaces import (
63
64
    DEFAULT_FLAVOR,
65
66
    MAIN_STORE,
66
67
    )
67
68
from lp.app.errors import NotFoundError
68
 
from lp.app.interfaces.launchpad import ILaunchpadCelebrities
69
69
from lp.app.validators.email import valid_email
70
70
from lp.app.validators.name import sanitize_name
71
71
from lp.bugs.interfaces.bugtracker import (
271
271
 
272
272
        if component_name is None:
273
273
            return None
274
 
        elif component_name.isdigit():
275
 
            component_id = int(component_name)
276
 
            return Store.of(self).find(
277
 
                BugTrackerComponent,
278
 
                BugTrackerComponent.id == component_id,
279
 
                BugTrackerComponent.component_group == self.id).one()
280
274
        else:
281
275
            return Store.of(self).find(
282
276
                BugTrackerComponent,
283
 
                BugTrackerComponent.name == component_name,
284
 
                BugTrackerComponent.component_group == self.id).one()
 
277
                (BugTrackerComponent.name == component_name)).one()
285
278
 
286
279
    def addCustomComponent(self, component_name):
287
280
        """Adds a component locally that isn't synced from a remote tracker
455
448
        description = description.encode('utf-8')
456
449
 
457
450
        if self.bugtrackertype == BugTrackerType.SOURCEFORGE:
458
 
            try:
459
 
                # SourceForge bug trackers use a group ID and an ATID to
460
 
                # file a bug, rather than a product name. remote_product
461
 
                # should be an ampersand-separated string in the form
462
 
                # 'group_id&atid'
463
 
                group_id, at_id = remote_product.split('&')
464
 
            except ValueError:
465
 
                # If remote_product contains something that's not valid
466
 
                # in a SourceForge context we just return early.
467
 
                return None
 
451
            # SourceForge bug trackers use a group ID and an ATID to
 
452
            # file a bug, rather than a product name. remote_product
 
453
            # should be an ampersand-separated string in the form
 
454
            # 'group_id&atid'
 
455
            group_id, at_id = remote_product.split('&')
468
456
 
469
457
            # If this bug tracker is the SourceForge celebrity the link
470
458
            # is to the new bug tracker rather than the old one.
687
675
        """See `IBugTracker`."""
688
676
        component_group = None
689
677
        store = IStore(BugTrackerComponentGroup)
690
 
        if component_group_name.isdigit():
691
 
            component_group_id = int(component_group_name)
692
 
            component_group = store.find(
693
 
                BugTrackerComponentGroup,
694
 
                BugTrackerComponentGroup.id == component_group_id).one()
695
 
        else:
696
 
            component_group = store.find(
697
 
                BugTrackerComponentGroup,
698
 
                BugTrackerComponentGroup.name == component_group_name).one()
 
678
        component_group = store.find(
 
679
            BugTrackerComponentGroup,
 
680
            name = component_group_name).one()
699
681
        return component_group
700
682
 
701
 
    def getRemoteComponentForDistroSourcePackageName(
702
 
        self, distribution, sourcepackagename):
703
 
        """See `IBugTracker`."""
704
 
        if distribution is None:
705
 
            return None
706
 
        dsp = distribution.getSourcePackage(sourcepackagename)
707
 
        if dsp is None:
708
 
            return None
709
 
        return Store.of(self).find(
710
 
            BugTrackerComponent,
711
 
            BugTrackerComponent.distribution == distribution.id,
712
 
            BugTrackerComponent.source_package_name ==
713
 
                dsp.sourcepackagename.id).one()
714
 
 
715
683
 
716
684
class BugTrackerSet:
717
685
    """Implements IBugTrackerSet for a container or set of BugTrackers,
778
746
        # Without context, cannot tell what store flavour is desirable.
779
747
        store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR)
780
748
        if active is not None:
781
 
            clauses = [BugTracker.active == active]
 
749
            clauses = [BugTracker.active==active]
782
750
        else:
783
751
            clauses = []
784
752
        results = store.find(BugTracker, *clauses)