~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Colin Watson
  • Date: 2012-01-05 17:09:42 UTC
  • mto: This revision was merged to the branch mainline in revision 14643.
  • Revision ID: cjwatson@canonical.com-20120105170942-7kgdx750aa6mrf49
Simplify garbo job, thanks to Gavin Panella.

Show diffs side-by-side

added added

removed removed

Lines of Context:
884
884
    def __init__(self, log, abort_time=None):
885
885
        super(SourcePackageReleaseDscBinariesUpdater, self).__init__(
886
886
            log, abort_time)
887
 
        self.offset = 0
888
887
        self.store = IMasterStore(SourcePackageRelease)
889
 
        self.store.execute("DROP TABLE IF EXISTS MatchedSourcePackageRelease")
890
 
        self.store.execute("""
891
 
            CREATE TEMPORARY TABLE MatchedSourcePackageRelease AS
892
 
            SELECT id AS spr
893
 
            FROM SourcePackageRelease
894
 
            -- Get all SPR IDs which have an incorrectly-separated
895
 
            -- dsc_binaries value (space rather than comma-space).
896
 
            WHERE dsc_binaries ~ '[a-z0-9+.-] '
897
 
            -- Skip rows with dsc_binaries in dependency relationship
898
 
            -- format.  This is a different bug.
899
 
                AND dsc_binaries NOT LIKE '%(%'
900
 
            """, noresult=True)
901
 
        self.store.execute("""
902
 
            CREATE INDEX matchedsourcepackagerelease__spr__idx
903
 
            ON MatchedSourcePackageRelease(spr)
904
 
            """, noresult=True)
905
 
        self.matched_spr_count = self.store.execute("""
906
 
            SELECT COUNT(*) FROM MatchedSourcePackageRelease
907
 
            """).get_one()[0]
 
888
        self.ids = list(
 
889
            self.store.find(
 
890
                SourcePackageRelease.id,
 
891
                # Get all SPR IDs which have an incorrectly-separated
 
892
                # dsc_binaries value (space rather than comma-space).
 
893
                SQL("dsc_binaries ~ '[a-z0-9+.-] '"),
 
894
                # Skip rows with dsc_binaries in dependency relationship
 
895
                # format.  This is a different bug.
 
896
                SQL("dsc_binaries NOT LIKE '%(%'")))
908
897
 
909
898
    def isDone(self):
910
899
        """See `TunableLoop`."""
911
 
        return self.offset >= self.matched_spr_count
 
900
        return len(self.ids) == 0
912
901
 
913
902
    def __call__(self, chunk_size):
914
903
        """See `TunableLoop`."""
 
904
        chunk_ids = self.ids[:chunk_size]
 
905
        del self.ids[:chunk_size]
915
906
        self.store.execute("""
916
907
            UPDATE SourcePackageRelease
917
908
            SET dsc_binaries = regexp_replace(
918
909
                dsc_binaries, '([a-z0-9+.-]) ', E'\\\\1, ', 'g')
919
 
            FROM (
920
 
                SELECT spr
921
 
                FROM MatchedSourcePackageRelease
922
 
                ORDER BY spr
923
 
                OFFSET %d
924
 
                LIMIT %d
925
 
                ) AS MatchedSourcePackageRelease
926
 
            WHERE SourcePackageRelease.id = MatchedSourcePackageRelease.spr
927
 
            """ % (self.offset, chunk_size), noresult=True)
928
 
        self.offset += chunk_size
 
910
            WHERE id IN %s""" % sqlvalues(chunk_ids), noresult=True)
929
911
        transaction.commit()
930
912
 
931
913