~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/scripts/garbo.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-14 13:26:42 UTC
  • mfrom: (13646.11.20 denorm-bspph-garbo)
  • Revision ID: launchpad@pqm.canonical.com-20110914132642-ubgik3qizdj05o62
[r=jtv][bug=826516][incr] Add a garbo job that will populate
        BPPH.binarypackagename and SPPH.sourcepackagename.

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
    SilentLaunchpadScriptFailure,
87
87
    )
88
88
from lp.services.session.model import SessionData
 
89
from lp.soyuz.model.publishing import (
 
90
    BinaryPackagePublishingHistory,
 
91
    SourcePackagePublishingHistory,
 
92
    )
89
93
from lp.translations.interfaces.potemplate import IPOTemplateSet
90
94
from lp.translations.model.potranslation import POTranslation
91
95
from lp.translations.model.potmsgset import POTMsgSet
950
954
        transaction.commit()
951
955
 
952
956
 
 
957
# XXX: StevenK 2011-09-14 bug=849683: This can be removed when done.
 
958
class SourcePackagePublishingHistorySPNPopulator(TunableLoop):
 
959
    """Populate the new sourcepackagename column of SPPH."""
 
960
 
 
961
    done = False
 
962
    maximum_chunk_size = 5000
 
963
 
 
964
    def findSPPHs(self):
 
965
        return IMasterStore(SourcePackagePublishingHistory).find(
 
966
            SourcePackagePublishingHistory,
 
967
            SourcePackagePublishingHistory.sourcepackagename == None
 
968
            ).order_by(SourcePackagePublishingHistory.id)
 
969
 
 
970
    def isDone(self):
 
971
        """See `TunableLoop`."""
 
972
        return self.done
 
973
 
 
974
    def __call__(self, chunk_size):
 
975
        """See `TunableLoop`."""
 
976
        spphs = self.findSPPHs()[:chunk_size]
 
977
        for spph in spphs:
 
978
            spph.sourcepackagename = (
 
979
                spph.sourcepackagerelease.sourcepackagename)
 
980
        transaction.commit()
 
981
        self.done = self.findSPPHs().is_empty()
 
982
 
 
983
 
 
984
# XXX: StevenK 2011-09-14 bug=849683: This can be removed when done.
 
985
class BinaryPackagePublishingHistoryBPNPopulator(TunableLoop):
 
986
    """Populate the new binarypackagename column of BPPH."""
 
987
 
 
988
    done = False
 
989
    maximum_chunk_size = 5000
 
990
 
 
991
    def findBPPHs(self):
 
992
        return IMasterStore(BinaryPackagePublishingHistory).find(
 
993
            BinaryPackagePublishingHistory,
 
994
            BinaryPackagePublishingHistory.binarypackagename == None
 
995
            ).order_by(BinaryPackagePublishingHistory.id)
 
996
 
 
997
    def isDone(self):
 
998
        """See `TunableLoop`."""
 
999
        return self.done
 
1000
 
 
1001
    def __call__(self, chunk_size):
 
1002
        """See `TunableLoop`."""
 
1003
        bpphs = self.findBPPHs()[:chunk_size]
 
1004
        for bpph in bpphs:
 
1005
            bpph.binarypackagename = (
 
1006
                bpph.binarypackagerelease.binarypackagename)
 
1007
        transaction.commit()
 
1008
        self.done = self.findBPPHs().is_empty()
 
1009
 
 
1010
 
953
1011
class BaseDatabaseGarbageCollector(LaunchpadCronScript):
954
1012
    """Abstract base class to run a collection of TunableLoops."""
955
1013
    script_name = None  # Script name for locking and database user. Override.
1199
1257
        UnusedSessionPruner,
1200
1258
        DuplicateSessionPruner,
1201
1259
        BugHeatUpdater,
 
1260
        SourcePackagePublishingHistorySPNPopulator,
 
1261
        BinaryPackagePublishingHistoryBPNPopulator,
1202
1262
        ]
1203
1263
    experimental_tunable_loops = []
1204
1264