Gavin Panella has proposed merging lp:~allenap/launchpad/wipe-precise-translations into lp:launchpad.
Requested reviews: Launchpad code reviewers (launchpad-reviewers) For more details, see: https://code.launchpad.net/~allenap/launchpad/wipe-precise-translations/+merge/82422 Script to wipe Precise's translations in production so that we can reattempt the opening (see https://wiki.canonical.com/Launchpad/Translations/UbuntuOpenings). This will just be run once and not landed. -- https://code.launchpad.net/~allenap/launchpad/wipe-precise-translations/+merge/82422 Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/launchpad/wipe-precise-translations into lp:launchpad.
=== added file 'wipeprecisetrans.py' --- wipeprecisetrans.py 1970-01-01 00:00:00 +0000 +++ wipeprecisetrans.py 2011-11-16 16:19:25 +0000 @@ -0,0 +1,104 @@ +#!/usr/bin/python2.6 -S + +__metaclass__ = type + +import _pythonpath + +from zope.component import getUtility +from zope.interface import implements + +from canonical.launchpad.interfaces.looptuner import ITunableLoop +from canonical.launchpad.utilities.looptuner import DBLoopTuner +from canonical.launchpad.webapp.interfaces import ( + IStoreSelector, + MAIN_STORE, + MASTER_FLAVOR, + ) +from lp.services.scripts.base import LaunchpadScript + + +select_precise = """\ +SELECT DistroSeries.id + FROM DistroSeries + JOIN Distribution ON + Distribution.id = DistroSeries.distribution + WHERE Distribution.name = 'ubuntu' + AND DistroSeries.name = 'precise' +""" + +delete_pofiletranslator = """\ +DELETE FROM POFileTranslator + WHERE POFileTranslator.pofile IN ( + SELECT POFile.id + FROM POFile, POTemplate + WHERE POFile.potemplate = POTemplate.id + AND POTemplate.distroseries = (%s) + LIMIT ?) +""" % select_precise + +delete_pofile = """\ +DELETE FROM POFile + WHERE POFile.potemplate IN ( + SELECT POTemplate.id + FROM POTemplate + WHERE POTemplate.distroseries = (%s) + LIMIT ?) +""" % select_precise + +delete_translationtemplateitem = """\ +DELETE FROM TranslationTemplateItem + WHERE TranslationTemplateItem.potemplate IN ( + SELECT POTemplate.id + FROM POTemplate + WHERE POTemplate.distroseries = (%s) + LIMIT ?) +""" % select_precise + +delete_potemplate = """\ +DELETE FROM POTemplate + WHERE POTemplate.id IN ( + SELECT POTemplate.id + FROM POTemplate + WHERE POTemplate.distroseries = (%s) + LIMIT ?) +""" % select_precise + +statements = [ + delete_pofiletranslator, + delete_pofile, + delete_translationtemplateitem, + delete_potemplate, + ] + + +class ExecuteLoop: + + implements(ITunableLoop) + + def __init__(self, statement): + self.statement = statement + self.done = False + + def isDone(self): + return self.done + + def __call__(self, chunk_size): + store = getUtility(IStoreSelector).get(MAIN_STORE, MASTER_FLAVOR) + result = store.execute(self.statement, (chunk_size,)) + self.done = (result.rowcount == 0) + store.commit() + + +class WipePreciseTranslationsScript(LaunchpadScript): + + description = "Wipe Ubuntu Precise's translations." + + def main(self): + for statement in statements: + delete = ExecuteLoop(statement) + tuner = DBLoopTuner(delete, 2.0, maximum_chunk_size=5000) + tuner.run() + + +if __name__ == '__main__': + WipePreciseTranslationsScript(dbuser='rosettaadmin').run()
_______________________________________________ Mailing list: https://launchpad.net/~launchpad-reviewers Post to : [email protected] Unsubscribe : https://launchpad.net/~launchpad-reviewers More help : https://help.launchpad.net/ListHelp

