~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/model/sourcepackage.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:
33
33
from canonical.lazr.utils import smartquote
34
34
from canonical.launchpad.webapp.interfaces import ILaunchBag
35
35
from lp.answers.enums import QUESTION_STATUS_DEFAULT_SEARCH
 
36
from lp.answers.interfaces.questiontarget import IQuestionTarget
36
37
from lp.answers.model.question import (
37
38
    QuestionTargetMixin,
38
39
    QuestionTargetSearch,
44
45
    BugTargetBase,
45
46
    HasBugHeatMixin,
46
47
    )
 
48
from lp.bugs.model.bugtask import BugTask
47
49
from lp.buildmaster.enums import BuildStatus
48
 
from lp.code.model.seriessourcepackagebranch import (
49
 
    SeriesSourcePackageBranchSet,
 
50
from lp.code.interfaces.seriessourcepackagebranch import (
 
51
    IMakeOfficialBranchLinks,
50
52
    )
51
53
from lp.code.model.branch import Branch
52
54
from lp.code.model.hasbranches import (
139
141
    def getAnswerContactsForLanguage(self, language):
140
142
        """See `IQuestionTarget`."""
141
143
        # Sourcepackages are supported by their distribtions too.
142
 
        persons = set(
143
 
            self.distribution.getAnswerContactsForLanguage(language))
144
 
        persons.update(
145
 
            set(QuestionTargetMixin.getAnswerContactsForLanguage(
146
 
            self, language)))
 
144
        persons = self.distribution.getAnswerContactsForLanguage(language)
 
145
        persons.update(QuestionTargetMixin.getAnswerContactsForLanguage(
 
146
            self, language))
147
147
        return sorted(
148
148
            [person for person in persons], key=attrgetter('displayname'))
149
149
 
185
185
        return sorted(answer_contacts, key=attrgetter('displayname'))
186
186
 
187
187
 
188
 
class SourcePackage(BugTargetBase, HasBugHeatMixin, HasCodeImportsMixin,
 
188
class SourcePackage(BugTargetBase, SourcePackageQuestionTargetMixin,
189
189
                    HasTranslationImportsMixin, HasTranslationTemplatesMixin,
190
 
                    HasBranchesMixin, HasMergeProposalsMixin):
 
190
                    HasBranchesMixin, HasMergeProposalsMixin,
 
191
                    HasBugHeatMixin, HasCodeImportsMixin):
191
192
    """A source package, e.g. apache2, in a distroseries.
192
193
 
193
194
    This object is not a true database object, but rather attempts to
196
197
    """
197
198
 
198
199
    implements(
199
 
        ISourcePackage, IHasBugHeat, IHasBuildRecords)
 
200
        ISourcePackage, IHasBugHeat, IHasBuildRecords, IQuestionTarget)
200
201
 
201
202
    classProvides(ISourcePackageFactory)
202
203
 
203
204
    def __init__(self, sourcepackagename, distroseries):
204
 
        # We store the ID of the sourcepackagename and distroseries
205
 
        # simply because Storm can break when accessing them
206
 
        # with implicit flush is blocked (like in a permission check when
207
 
        # storing the object in the permission cache).
208
 
        self.sourcepackagenameID = sourcepackagename.id
209
205
        self.sourcepackagename = sourcepackagename
210
206
        self.distroseries = distroseries
211
 
        self.distroseriesID = distroseries.id
212
207
 
213
208
    @classmethod
214
209
    def new(cls, sourcepackagename, distroseries):
427
422
        # if we are an ubuntu sourcepackage, try the previous series of
428
423
        # ubuntu
429
424
        if self.distribution == ubuntu:
430
 
            ubuntuseries = self.distroseries.priorReleasedSeries()
431
 
            previous_ubuntu_series = ubuntuseries.first()
432
 
            if previous_ubuntu_series is not None:
 
425
            ubuntuseries = self.distroseries.previous_series
 
426
            if ubuntuseries:
 
427
                previous_ubuntu_series = ubuntuseries[0]
433
428
                sp = SourcePackage(sourcepackagename=self.sourcepackagename,
434
429
                                   distroseries=previous_ubuntu_series)
435
430
                return sp.packaging
436
431
        # if we have a parent distroseries, try that
437
 
        if self.distroseries.previous_series is not None:
 
432
        if self.distroseries.parent_series is not None:
438
433
            sp = SourcePackage(sourcepackagename=self.sourcepackagename,
439
 
                               distroseries=self.distroseries.previous_series)
 
434
                               distroseries=self.distroseries.parent_series)
440
435
            return sp.packaging
441
436
        # capitulate
442
437
        return None
499
494
        """See `IBugTarget`."""
500
495
        return self.distroseries.getUsedBugTags()
501
496
 
502
 
    def getUsedBugTagsWithOpenCounts(self, user, tag_limit=0,
503
 
                                     include_tags=None):
504
 
        """See IBugTarget."""
505
 
        # Circular fail.
506
 
        from lp.bugs.model.bugsummary import BugSummary
 
497
    def getUsedBugTagsWithOpenCounts(self, user, wanted_tags=None):
 
498
        """See `IBugTarget`."""
507
499
        return get_bug_tags_open_count(
508
 
            And(BugSummary.distroseries == self.distroseries,
509
 
                BugSummary.sourcepackagename == self.sourcepackagename),
510
 
            user, tag_limit=tag_limit, include_tags=include_tags)
 
500
            And(BugTask.distroseries == self.distroseries,
 
501
                BugTask.sourcepackagename == self.sourcepackagename),
 
502
            user, wanted_tags=wanted_tags)
511
503
 
512
504
    @property
513
505
    def max_bug_heat(self):
593
585
 
594
586
    def __hash__(self):
595
587
        """See `ISourcePackage`."""
596
 
        return hash(self.distroseriesID) ^ hash(self.sourcepackagenameID)
 
588
        return hash(self.distroseries.id) ^ hash(self.sourcepackagename.id)
597
589
 
598
590
    def __eq__(self, other):
599
591
        """See `ISourcePackage`."""
733
725
 
734
726
    def setBranch(self, pocket, branch, registrant):
735
727
        """See `ISourcePackage`."""
736
 
        SeriesSourcePackageBranchSet.delete(self, pocket)
 
728
        series_set = getUtility(IMakeOfficialBranchLinks)
 
729
        series_set.delete(self, pocket)
737
730
        if branch is not None:
738
 
            SeriesSourcePackageBranchSet.new(
 
731
            series_set.new(
739
732
                self.distroseries, pocket, self.sourcepackagename, branch,
740
733
                registrant)
741
734