3
# Copyright 2009 Canonical Ltd. This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
6
"""Populate some new columns on the Person table."""
13
from optparse import OptionParser
16
from canonical.database.sqlbase import connect, ISOLATION_LEVEL_AUTOCOMMIT
17
from canonical.launchpad.scripts import db_options
18
from canonical.launchpad.scripts.logger import log, logger_options
20
def update_until_done(con, table, query, vacuum_every=100):
21
log.info("Running %s" % query)
28
rowcount = cur.rowcount
29
total_rows += rowcount
30
log.debug("Updated %d" % total_rows)
31
if loops % vacuum_every == 0:
32
log.debug("Vacuuming %s" % table)
33
cur.execute("VACUUM %s" % table)
38
parser = OptionParser()
39
logger_options(parser)
41
options, args = parser.parse_args()
43
con = connect(isolation=ISOLATION_LEVEL_AUTOCOMMIT)
45
# People have so far updated translation credits, often mis-crediting people,
46
# or removing credits to upstream translators: we want to disable all of these
47
# translation, so automatic handling will pick up from now on.
48
update_until_done(con, 'posubmission', """
49
UPDATE posubmission SET active=FALSE WHERE id IN (
50
SELECT posubmission.id
56
posubmission.active IS TRUE AND
57
posubmission.pomsgset=pomsgset.id AND
58
potmsgset=potmsgset.id AND
59
primemsgid=pomsgid.id AND
60
published IS NOT TRUE AND
61
(msgid='translation-credits' OR
62
msgid='translator-credits' OR
63
msgid='translator_credits' OR
64
msgid=E'_: EMAIL OF TRANSLATORS\nYour emails' OR
65
msgid=E'_: NAME OF TRANSLATORS\nYour names')
70
# Set any existing inactive published translations as active
71
update_until_done(con, 'posubmission', """
72
UPDATE posubmission SET active=TRUE WHERE id IN (
73
SELECT posubmission.id
79
posubmission.active IS FALSE AND
80
posubmission.pomsgset=pomsgset.id AND
81
pomsgset.potmsgset=potmsgset.id AND
82
potmsgset.primemsgid=pomsgid.id AND
83
posubmission.published IS TRUE AND
84
(msgid='translation-credits' OR
85
msgid='translator-credits' OR
86
msgid='translator_credits' OR
87
msgid=E'_: EMAIL OF TRANSLATORS\nYour emails' OR
88
msgid=E'_: NAME OF TRANSLATORS\nYour names')
93
# Remove reviewer, date_reviewed from all translation credit POMsgSets
94
update_until_done(con, 'pomsgset', """
95
UPDATE POMsgSet SET reviewer=NULL, date_reviewed=NULL
98
FROM POMsgSet, POTMsgSet, POMsgId
100
POMsgSet.reviewer IS NOT NULL AND
101
POMsgSet.potmsgset=POTMsgSet.id AND
102
POTMsgSet.primemsgid=POMsgId.id AND
103
(msgid='translation-credits' OR
104
msgid='translator-credits' OR
105
msgid='translator_credits' OR
106
msgid=E'_: EMAIL OF TRANSLATORS\nYour emails' OR
107
msgid=E'_: NAME OF TRANSLATORS\nYour names')