~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: 2012-01-05 21:38:46 UTC
  • mfrom: (14625.2.5 gina-dsc-binaries)
  • Revision ID: launchpad@pqm.canonical.com-20120105213846-8lb5f2ql18buf4gp
[r=allenap][bug=911943] Separate dsc_binaries correctly in gina,
        and add a garbo-daily job to clean up existing wreckage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
    MAIN_STORE,
87
87
    MASTER_FLAVOR,
88
88
    )
 
89
from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
89
90
from lp.translations.interfaces.potemplate import IPOTemplateSet
90
91
from lp.translations.model.potmsgset import POTMsgSet
91
92
from lp.translations.model.potranslation import POTranslation
901
902
        self._update_oldest()
902
903
 
903
904
 
 
905
class SourcePackageReleaseDscBinariesUpdater(TunableLoop):
 
906
    """Fix incorrect values for SourcePackageRelease.dsc_binaries."""
 
907
 
 
908
    maximum_chunk_size = 1000
 
909
 
 
910
    def __init__(self, log, abort_time=None):
 
911
        super(SourcePackageReleaseDscBinariesUpdater, self).__init__(
 
912
            log, abort_time)
 
913
        self.store = IMasterStore(SourcePackageRelease)
 
914
        self.ids = list(
 
915
            self.store.find(
 
916
                SourcePackageRelease.id,
 
917
                # Get all SPR IDs which have an incorrectly-separated
 
918
                # dsc_binaries value (space rather than comma-space).
 
919
                SQL("dsc_binaries ~ '[a-z0-9+.-] '"),
 
920
                # Skip rows with dsc_binaries in dependency relationship
 
921
                # format.  This is a different bug.
 
922
                SQL("dsc_binaries NOT LIKE '%(%'")))
 
923
 
 
924
    def isDone(self):
 
925
        """See `TunableLoop`."""
 
926
        return len(self.ids) == 0
 
927
 
 
928
    def __call__(self, chunk_size):
 
929
        """See `TunableLoop`."""
 
930
        chunk_ids = self.ids[:chunk_size]
 
931
        del self.ids[:chunk_size]
 
932
        self.store.execute("""
 
933
            UPDATE SourcePackageRelease
 
934
            SET dsc_binaries = regexp_replace(
 
935
                dsc_binaries, '([a-z0-9+.-]) ', E'\\\\1, ', 'g')
 
936
            WHERE id IN %s""" % sqlvalues(chunk_ids), noresult=True)
 
937
        transaction.commit()
 
938
 
 
939
 
904
940
class SuggestiveTemplatesCacheUpdater(TunableLoop):
905
941
    """Refresh the SuggestivePOTemplate cache.
906
942
 
1265
1301
        ObsoleteBugAttachmentPruner,
1266
1302
        OldTimeLimitedTokenDeleter,
1267
1303
        RevisionAuthorEmailLinker,
 
1304
        SourcePackageReleaseDscBinariesUpdater,
1268
1305
        SuggestiveTemplatesCacheUpdater,
1269
1306
        POTranslationPruner,
1270
1307
        UnusedPOTMsgSetPruner,