~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/model/distributionsourcepackage.py

  • Committer: Jelmer Vernooij
  • Date: 2011-09-21 14:28:02 UTC
  • mfrom: (14006 devel)
  • mto: This revision was merged to the branch mainline in revision 14010.
  • Revision ID: jelmer@canonical.com-20110921142802-7ggkc204igsy532w
MergeĀ lp:launchpad

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2009-2011 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
207
207
        # in the database.
208
208
        return self._get(self.distribution, self.sourcepackagename)
209
209
 
 
210
    def delete(self):
 
211
        """See `DistributionSourcePackage`."""
 
212
        dsp_in_db = self._self_in_database
 
213
        no_spph = self.publishing_history.count() == 0
 
214
        if dsp_in_db is not None and no_spph:
 
215
            store = IStore(dsp_in_db)
 
216
            store.remove(dsp_in_db)
 
217
            return True
 
218
        return False
 
219
 
210
220
    def recalculateBugHeatCache(self):
211
221
        """See `IHasBugHeat`."""
212
222
        row = IStore(Bug).find(
527
537
        return dsp
528
538
 
529
539
    @classmethod
530
 
    def ensure(cls, spph):
 
540
    def ensure(cls, spph=None, sourcepackage=None):
531
541
        """Create DistributionSourcePackage record, if necessary.
532
542
 
533
 
        Only create a record for primary archives (i.e. not for PPAs).
 
543
        Only create a record for primary archives (i.e. not for PPAs) or
 
544
        for official package branches. Requires either a SourcePackage
 
545
        or a SourcePackagePublishingHistory.
 
546
 
 
547
        :param spph: A SourcePackagePublishingHistory to create a DSP
 
548
            to represent an official uploaded/published package.
 
549
        :param sourcepackage: A SourcePackage to create a DSP to represent an
 
550
            official package branch.
534
551
        """
535
 
        if spph.archive.purpose != ArchivePurpose.PRIMARY:
536
 
            return
537
 
 
538
 
        distribution = spph.distroseries.distribution
539
 
        sourcepackagename = spph.sourcepackagerelease.sourcepackagename
 
552
        if spph is None and sourcepackage is None:
 
553
            raise ValueError(
 
554
                'ensure() must be called with either a SPPH '
 
555
                'or a SourcePackage.')
 
556
        if spph is not None:
 
557
            if spph.archive.purpose != ArchivePurpose.PRIMARY:
 
558
                return
 
559
            distribution = spph.distroseries.distribution
 
560
            sourcepackagename = spph.sourcepackagerelease.sourcepackagename
 
561
        else:
 
562
            distribution = sourcepackage.distribution
 
563
            sourcepackagename = sourcepackage.sourcepackagename
540
564
        dsp = cls._get(distribution, sourcepackagename)
541
565
        if dsp is None:
542
566
            upstream_link_allowed = is_upstream_link_allowed(spph)
572
596
    po_message_count = Int()
573
597
    is_upstream_link_allowed = Bool()
574
598
    enable_bugfiling_duplicate_search = Bool()
 
599
 
 
600
    @property
 
601
    def currentrelease(self):
 
602
        """See `IDistributionSourcePackage`."""
 
603
        releases = self.distribution.getCurrentSourceReleases(
 
604
            [self.sourcepackagename])
 
605
        return releases.get(self)