Colin Watson has proposed merging ~cjwatson/launchpad:stormify-pofile into launchpad:master.
Commit message: Convert POFile to Storm Requested reviews: Launchpad code reviewers (launchpad-reviewers) For more details, see: https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/446602 -- Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:stormify-pofile into launchpad:master.
diff --git a/lib/lp/registry/model/distroseries.py b/lib/lp/registry/model/distroseries.py index 5e934c2..e801a05 100644 --- a/lib/lp/registry/model/distroseries.py +++ b/lib/lp/registry/model/distroseries.py @@ -1010,9 +1010,9 @@ class DistroSeries( .find( Language, Is(Language.visible, True), - Language.id == POFile.languageID, + Language.id == POFile.language_id, Language.code != "en", - POFile.potemplateID == POTemplate.id, + POFile.potemplate_id == POTemplate.id, POTemplate.distroseries == self, Is(POTemplate.iscurrent, True), ) @@ -1537,7 +1537,7 @@ class DistroSeries( POFileTranslator.person_id == Person.id, POFile.id == POFileTranslator.pofile_id, POFile.language == language, - POTemplate.id == POFile.potemplateID, + POTemplate.id == POFile.potemplate_id, POTemplate.distroseries == self, POTemplate.iscurrent == True, ) diff --git a/lib/lp/services/statistics/model/statistics.py b/lib/lp/services/statistics/model/statistics.py index 70a5ce9..4b4ff60 100644 --- a/lib/lp/services/statistics/model/statistics.py +++ b/lib/lp/services/statistics/model/statistics.py @@ -201,17 +201,16 @@ class LaunchpadStatisticSet: ) self.update("potemplate_count", POTemplate.select().count()) ztm.commit() - self.update("pofile_count", POFile.select().count()) + self.update("pofile_count", IStore(POFile).find(POFile).count()) ztm.commit() self.update("pomsgid_count", IStore(POMsgID).find(POMsgID).count()) ztm.commit() self.update( "language_count", - Language.select( - "POFile.language=Language.id", - clauseTables=["POFile"], - distinct=True, - ).count(), + IStore(Language) + .find(Language, POFile.language == Language.id) + .config(distinct=True) + .count(), ) ztm.commit() diff --git a/lib/lp/translations/browser/tests/translationmessage-views.rst b/lib/lp/translations/browser/tests/translationmessage-views.rst index 3c4da4a..d91f403 100644 --- a/lib/lp/translations/browser/tests/translationmessage-views.rst +++ b/lib/lp/translations/browser/tests/translationmessage-views.rst @@ -28,7 +28,7 @@ without the plural form information. >>> translationmessage = IStore(TranslationMessage).get( ... TranslationMessage, 1 ... ) - >>> pofile = POFile.get(1) + >>> pofile = IStore(POFile).get(POFile, 1) >>> language_tlh = getUtility(ILanguageSet).getLanguageByCode("tlh") >>> pofile_tlh = pofile.potemplate.getPlaceholderPOFile(language_tlh) >>> potmsgset = pofile_tlh.potemplate.getPOTMsgSetByMsgIDText( diff --git a/lib/lp/translations/doc/pofile-verify-stats.rst b/lib/lp/translations/doc/pofile-verify-stats.rst index bb92727..8325633 100644 --- a/lib/lp/translations/doc/pofile-verify-stats.rst +++ b/lib/lp/translations/doc/pofile-verify-stats.rst @@ -66,8 +66,9 @@ Reports and correction If for any reason any POFiles' statistics are found to be wrong, the script reports this giving both the wrong and the corrected statistics. + >>> from lp.services.database.interfaces import IStore >>> from lp.translations.model.pofile import POFile - >>> pofile = POFile.get(34) + >>> pofile = IStore(POFile).get(POFile, 34) >>> pofile.getStatistics() (0, 0, 3, 0) diff --git a/lib/lp/translations/doc/pofile.rst b/lib/lp/translations/doc/pofile.rst index abc9267..467d56f 100644 --- a/lib/lp/translations/doc/pofile.rst +++ b/lib/lp/translations/doc/pofile.rst @@ -442,8 +442,9 @@ This method serializes an IPOFile as a .po file. Get a concrete POFile we know doesn't have a UTF-8 encoding. + >>> from lp.services.database.interfaces import IStore >>> from lp.translations.model.pofile import POFile - >>> pofile = POFile.get(24) + >>> pofile = IStore(POFile).get(POFile, 24) >>> print(pofile.header) Project-Id-Version: PACKAGE VERSION ... @@ -652,7 +653,7 @@ can use the getPOFileContributorsByLanguage() method of IDistroSeries. # We can see that there is another translator that doesn't appear in # previous list because the template they translated is not current. - >>> non_current_pofile = POFile.get(31) + >>> non_current_pofile = IStore(POFile).get(POFile, 31) >>> non_current_pofile.potemplate.iscurrent False diff --git a/lib/lp/translations/doc/potmsgset.rst b/lib/lp/translations/doc/potmsgset.rst index 400c533..8b418c1 100644 --- a/lib/lp/translations/doc/potmsgset.rst +++ b/lib/lp/translations/doc/potmsgset.rst @@ -290,7 +290,7 @@ the given timestamp. ... ) >>> potmsgset = translationmessage.potmsgset >>> from lp.translations.model.pofile import POFile - >>> pofile = POFile.get(1) + >>> pofile = IStore(POFile).get(POFile, 1) >>> translationmessage.date_reviewed.isoformat() '2005-04-07T13:19:17.601068+00:00' >>> potmsgset.isTranslationNewerThan( diff --git a/lib/lp/translations/model/poexportrequest.py b/lib/lp/translations/model/poexportrequest.py index f103dd1..a346930 100644 --- a/lib/lp/translations/model/poexportrequest.py +++ b/lib/lp/translations/model/poexportrequest.py @@ -71,11 +71,13 @@ class POExportRequestSet: ) potemplate_ids = ", ".join( - [quote(template) for template in potemplates] + [quote(template.id) for template in potemplates] ) # A null pofile stands for the template itself. We represent it in # SQL as -1, because that's how it's indexed in the request table. - pofile_ids = ", ".join([quote(pofile) for pofile in pofiles] + ["-1"]) + pofile_ids = ", ".join( + [quote(pofile.id) for pofile in pofiles] + ["-1"] + ) query_params = { "person": quote(person), diff --git a/lib/lp/translations/model/pofile.py b/lib/lp/translations/model/pofile.py index 42f51fd..1f76e09 100644 --- a/lib/lp/translations/model/pofile.py +++ b/lib/lp/translations/model/pofile.py @@ -28,6 +28,8 @@ from storm.expr import ( Union, ) from storm.info import ClassAlias +from storm.properties import Bool, DateTime, Int, Unicode +from storm.references import Reference from storm.store import EmptyResultSet, Store from zope.component import getAdapter, getUtility from zope.interface import implementer @@ -36,15 +38,9 @@ from zope.security.proxy import removeSecurityProxy from lp.app.interfaces.launchpad import ILaunchpadCelebrities from lp.registry.interfaces.person import validate_public_person from lp.services.database.constants import UTC_NOW -from lp.services.database.datetimecol import UtcDateTimeCol from lp.services.database.interfaces import IPrimaryStore, IStore -from lp.services.database.sqlbase import SQLBase, flush_database_updates, quote -from lp.services.database.sqlobject import ( - BoolCol, - ForeignKey, - IntCol, - StringCol, -) +from lp.services.database.sqlbase import flush_database_updates, quote +from lp.services.database.stormbase import StormBase from lp.services.mail.helpers import get_email_template from lp.services.propertycache import cachedproperty from lp.services.webapp.publisher import canonical_url @@ -160,7 +156,7 @@ class POFileMixIn(RosettaStats): TranslationTemplateItem.potemplate == pofile.potemplate, TranslationTemplateItem.sequence > 0, - tm_ids.language_id == pofile.languageID, + tm_ids.language_id == pofile.language_id, ), distinct=True, ) @@ -311,55 +307,76 @@ class POFileMixIn(RosettaStats): @implementer(IPOFile) -class POFile(SQLBase, POFileMixIn): - _table = "POFile" - - potemplate = ForeignKey( - foreignKey="POTemplate", dbName="potemplate", notNull=True - ) - language = ForeignKey( - foreignKey="Language", dbName="language", notNull=True - ) - description = StringCol(dbName="description", notNull=False, default=None) - topcomment = StringCol(dbName="topcomment", notNull=False, default=None) - header = StringCol(dbName="header", notNull=False, default=None) - fuzzyheader = BoolCol(dbName="fuzzyheader", notNull=True) - lasttranslator = ForeignKey( - dbName="lasttranslator", - foreignKey="Person", - storm_validator=validate_public_person, - notNull=False, +class POFile(StormBase, POFileMixIn): + __storm_table__ = "POFile" + + id = Int(primary=True) + potemplate_id = Int(name="potemplate", allow_none=False) + potemplate = Reference(potemplate_id, "POTemplate.id") + language_id = Int(name="language", allow_none=False) + language = Reference(language_id, "Language.id") + description = Unicode(name="description", allow_none=True, default=None) + topcomment = Unicode(name="topcomment", allow_none=True, default=None) + header = Unicode(name="header", allow_none=True, default=None) + fuzzyheader = Bool(name="fuzzyheader", allow_none=False) + lasttranslator_id = Int( + "lasttranslator", + validator=validate_public_person, + allow_none=True, default=None, ) + lasttranslator = Reference(lasttranslator_id, "Person.id") - date_changed = UtcDateTimeCol( - dbName="date_changed", notNull=True, default=UTC_NOW + date_changed = DateTime( + name="date_changed", + allow_none=False, + default=UTC_NOW, + tzinfo=timezone.utc, ) - currentcount = IntCol(dbName="currentcount", notNull=True, default=0) - updatescount = IntCol(dbName="updatescount", notNull=True, default=0) - rosettacount = IntCol(dbName="rosettacount", notNull=True, default=0) - unreviewed_count = IntCol( - dbName="unreviewed_count", notNull=True, default=0 + currentcount = Int(name="currentcount", allow_none=False, default=0) + updatescount = Int(name="updatescount", allow_none=False, default=0) + rosettacount = Int(name="rosettacount", allow_none=False, default=0) + unreviewed_count = Int( + name="unreviewed_count", allow_none=False, default=0 ) - lastparsed = UtcDateTimeCol( - dbName="lastparsed", notNull=False, default=None + lastparsed = DateTime( + name="lastparsed", allow_none=True, default=None, tzinfo=timezone.utc ) - owner = ForeignKey( - dbName="owner", - foreignKey="Person", - storm_validator=validate_public_person, - notNull=True, + owner_id = Int( + name="owner", validator=validate_public_person, allow_none=False + ) + owner = Reference(owner_id, "Person.id") + path = Unicode(name="path", allow_none=False) + datecreated = DateTime( + allow_none=False, default=UTC_NOW, tzinfo=timezone.utc ) - path = StringCol(dbName="path", notNull=True) - datecreated = UtcDateTimeCol(notNull=True, default=UTC_NOW) - from_sourcepackagename = ForeignKey( - foreignKey="SourcePackageName", - dbName="from_sourcepackagename", - notNull=False, - default=None, + from_sourcepackagename_id = Int( + name="from_sourcepackagename", allow_none=True, default=None ) + from_sourcepackagename = Reference( + from_sourcepackagename_id, "SourcePackageName.id" + ) + + def __init__( + self, + potemplate, + language, + fuzzyheader, + owner, + path, + topcomment=None, + header=None, + ): + super().__init__() + self.potemplate = potemplate + self.language = language + self.fuzzyheader = fuzzyheader + self.owner = owner + self.path = path + self.topcomment = topcomment + self.header = header @property def translation_messages(self): @@ -1617,7 +1634,7 @@ class POFileSet: from lp.translations.model.potemplate import POTemplate clauses = [ - TranslationTemplateItem.potemplate_id == POFile.potemplateID, + TranslationTemplateItem.potemplate_id == POFile.potemplate_id, POTMsgSet.id == TranslationTemplateItem.potmsgset_id, POTMsgSet.msgid_singular == POMsgID.id, POMsgID.msgid.is_in(POTMsgSet.credits_message_ids), @@ -1628,7 +1645,7 @@ class POFileSet: And( TranslationMessage.potmsgset_id == POTMsgSet.id, TranslationMessage.potemplate == None, - POFile.languageID == TranslationMessage.language_id, + POFile.language_id == TranslationMessage.language_id, Or( And( POTemplate.productseries == None, @@ -1642,7 +1659,7 @@ class POFileSet: ), (TranslationMessage), ) - clauses.append(POTemplate.id == POFile.potemplateID) + clauses.append(POTemplate.id == POFile.potemplate_id) clauses.append(Not(Exists(message_select))) result = IPrimaryStore(POFile).find((POFile, POTMsgSet), clauses) return result.order_by("POFile.id") @@ -1693,8 +1710,8 @@ class POFileSet: OtherPOFileJoin = Join( OtherPOFile, And( - OtherPOFile.languageID == POFile.languageID, - OtherPOFile.potemplateID == OtherPOT.id, + OtherPOFile.language_id == POFile.language_id, + OtherPOFile.potemplate_id == OtherPOT.id, ), ) diff --git a/lib/lp/translations/model/pofiletranslator.py b/lib/lp/translations/model/pofiletranslator.py index 260c5d8..3eff5cf 100644 --- a/lib/lp/translations/model/pofiletranslator.py +++ b/lib/lp/translations/model/pofiletranslator.py @@ -125,5 +125,5 @@ class POFileTranslatorSet: return Store.of(potemplate).find( POFileTranslator, POFileTranslator.pofile_id == POFile.id, - POFile.potemplateID == potemplate.id, + POFile.potemplate_id == potemplate.id, ) diff --git a/lib/lp/translations/model/potemplate.py b/lib/lp/translations/model/potemplate.py index 3c293e4..85c6f57 100644 --- a/lib/lp/translations/model/potemplate.py +++ b/lib/lp/translations/model/potemplate.py @@ -21,6 +21,7 @@ from psycopg2.extensions import TransactionRollbackError from storm.expr import SQL, And, Desc, Join, LeftJoin, Or from storm.info import ClassAlias from storm.properties import Int +from storm.references import ReferenceSet from storm.store import Store from zope.component import getAdapter, getUtility from zope.interface import implementer @@ -43,7 +44,6 @@ from lp.services.database.sqlobject import ( BoolCol, ForeignKey, IntCol, - SQLMultipleJoin, StringCol, ) from lp.services.helpers import shortlist @@ -169,7 +169,7 @@ def get_pofiles_for(potemplates, language): pofiles = Store.of(potemplates[0]).find( POFile, And( - POFile.potemplateID.is_in(template_ids), + POFile.potemplate_id.is_in(template_ids), POFile.language == language, ), ) @@ -251,7 +251,7 @@ class POTemplate(SQLBase, RosettaStats): ) # joins - pofiles = SQLMultipleJoin("POFile", joinColumn="potemplate") + pofiles = ReferenceSet("<primary key>", "POFile.potemplate_id") # In-memory cache: maps language_code to list of POFiles # translating this template to that language. @@ -447,7 +447,7 @@ class POTemplate(SQLBase, RosettaStats): Language, POFile.language == Language.id, POFile.currentcount + POFile.rosettacount > 0, - POFile.potemplateID == self.id, + POFile.potemplate_id == self.id, ) .config(distinct=True) .count() @@ -591,9 +591,9 @@ class POTemplate(SQLBase, RosettaStats): Store.of(self) .find( Language, - POFile.languageID == Language.id, + POFile.language_id == Language.id, Language.code != "en", - POFile.potemplateID == self.id, + POFile.potemplate_id == self.id, ) .config(distinct=True) ) @@ -616,8 +616,8 @@ class POTemplate(SQLBase, RosettaStats): Store.of(self) .find( POFile, - POFile.potemplateID == self.id, - POFile.languageID == Language.id, + POFile.potemplate_id == self.id, + POFile.language_id == Language.id, Language.code == language_code, ) .one() @@ -1880,7 +1880,7 @@ class TranslationTemplatesCollection(Collection): :return: A `TranslationTemplatesCollection` with an added inner join to `POFile`. """ - return self.joinInner(POFile, POTemplate.id == POFile.potemplateID) + return self.joinInner(POFile, POTemplate.id == POFile.potemplate_id) def joinOuterPOFile(self, language=None): """Outer-join `POFile` into the collection. @@ -1892,9 +1892,11 @@ class TranslationTemplatesCollection(Collection): return self.joinOuter( POFile, And( - POTemplate.id == POFile.potemplateID, - POFile.languageID == language.id, + POTemplate.id == POFile.potemplate_id, + POFile.language_id == language.id, ), ) else: - return self.joinOuter(POFile, POTemplate.id == POFile.potemplateID) + return self.joinOuter( + POFile, POTemplate.id == POFile.potemplate_id + ) diff --git a/lib/lp/translations/model/translationmessage.py b/lib/lp/translations/model/translationmessage.py index 0265f4d..0670aed 100644 --- a/lib/lp/translations/model/translationmessage.py +++ b/lib/lp/translations/model/translationmessage.py @@ -467,7 +467,7 @@ class TranslationMessage(StormBase, TranslationMessageMixIn): IStore(self) .find( POFile, - POFile.potemplateID + POFile.potemplate_id == SQL( """(SELECT potemplate FROM TranslationTemplateItem @@ -662,7 +662,7 @@ class TranslationMessageSet: pots = load_related( POTemplate, (removeSecurityProxy(pofile) for pofile in pofiles), - ["potemplateID"], + ["potemplate_id"], ) if need_potemplate_context: getUtility(IPOTemplateSet).preloadPOTemplateContexts(pots) @@ -727,7 +727,7 @@ class TranslationMessageSet: TranslationTemplateItem.potmsgset_id.is_in( message.potmsgset_id for message in messages ), - POFile.potemplateID == TranslationTemplateItem.potemplate_id, + POFile.potemplate_id == TranslationTemplateItem.potemplate_id, *pofile_constraints, ) .config(distinct=(TranslationTemplateItem.potmsgset_id,)) diff --git a/lib/lp/translations/model/translationsperson.py b/lib/lp/translations/model/translationsperson.py index d978f90..7107ded 100644 --- a/lib/lp/translations/model/translationsperson.py +++ b/lib/lp/translations/model/translationsperson.py @@ -150,7 +150,7 @@ class TranslationsPerson: Join( POTemplate, And( - POTemplate.id == POFile.potemplateID, + POTemplate.id == POFile.potemplate_id, POTemplate.iscurrent == True, ), ), @@ -238,7 +238,7 @@ class TranslationsPerson: conditions = And(conditions, not_reviewer) if languages is not None: - conditions = And(conditions, POFile.languageID.is_in(languages)) + conditions = And(conditions, POFile.language_id.is_in(languages)) return Store.of(self.person).using(*tables).find(POFile, conditions) @@ -379,7 +379,7 @@ class TranslationsPerson: POTemplateJoin = Join( POTemplate, And( - POTemplate.id == POFile.potemplateID, + POTemplate.id == POFile.potemplate_id, POTemplate.iscurrent == True, ), ) @@ -433,7 +433,7 @@ class TranslationsPerson: # Look up translation team. translatorjoin_conditions = And( Translator.translationgroup_id == TranslationGroup.id, - Translator.language_id == POFile.languageID, + Translator.language_id == POFile.language_id, ) if expect_reviewer_status: TranslatorJoin = Join(Translator, translatorjoin_conditions) diff --git a/lib/lp/translations/model/vpoexport.py b/lib/lp/translations/model/vpoexport.py index bca71df..db3c9d1 100644 --- a/lib/lp/translations/model/vpoexport.py +++ b/lib/lp/translations/model/vpoexport.py @@ -80,7 +80,7 @@ class VPOExportSet: # Order by POTemplate. Caching in the export scripts can be # much more effective when consecutive POFiles belong to the # same POTemplate, e.g. they'll have the same POTMsgSets. - sort_list = [POFile.potemplateID, POFile.languageID] + sort_list = [POFile.potemplate_id, POFile.language_id] return query.order_by(sort_list).config(distinct=True) def get_distroseries_pofiles_count( diff --git a/lib/lp/translations/scripts/fix_plural_forms.py b/lib/lp/translations/scripts/fix_plural_forms.py index 8cbe6ff..8bdebac 100644 --- a/lib/lp/translations/scripts/fix_plural_forms.py +++ b/lib/lp/translations/scripts/fix_plural_forms.py @@ -84,7 +84,7 @@ def fix_plurals_in_all_pofiles(ztm, logger): (max_pofile_id,) = cur.fetchall()[0] for pofile_id in range(1, max_pofile_id): try: - pofile = POFile.get(pofile_id) + pofile = IStore(POFile).get(POFile, pofile_id) fix_pofile_plurals(pofile, logger, ztm) except SQLObjectNotFound: pass diff --git a/lib/lp/translations/scripts/scrub_pofiletranslator.py b/lib/lp/translations/scripts/scrub_pofiletranslator.py index dccade1..686275f 100644 --- a/lib/lp/translations/scripts/scrub_pofiletranslator.py +++ b/lib/lp/translations/scripts/scrub_pofiletranslator.py @@ -39,10 +39,10 @@ def get_pofile_ids(): store = IStore(POFile) query = store.find( POFile.id, - POFile.potemplateID == POTemplate.id, + POFile.potemplate_id == POTemplate.id, POTemplate.iscurrent == True, ) - return query.order_by(POTemplate.name, POFile.languageID) + return query.order_by(POTemplate.name, POFile.language_id) def summarize_pofiles(pofile_ids): @@ -57,7 +57,7 @@ def summarize_pofiles(pofile_ids): """ store = IStore(POFile) rows = store.find( - (POFile.id, POFile.potemplateID, POFile.languageID), + (POFile.id, POFile.potemplate_id, POFile.language_id), POFile.id.is_in(pofile_ids), ) return {row[0]: row[1:] for row in rows} @@ -249,8 +249,8 @@ def preload_work_items(work_items): respective `POFile` objects. """ pofiles = load(POFile, [work_item.pofile_id for work_item in work_items]) - load_related(Language, pofiles, ["languageID"]) - templates = load_related(POTemplate, pofiles, ["potemplateID"]) + load_related(Language, pofiles, ["language_id"]) + templates = load_related(POTemplate, pofiles, ["potemplate_id"]) distroseries = load_related(DistroSeries, templates, ["distroseriesID"]) load_related(Distribution, distroseries, ["distributionID"]) productseries = load_related(ProductSeries, templates, ["productseriesID"]) diff --git a/lib/lp/translations/tests/test_autoapproval.py b/lib/lp/translations/tests/test_autoapproval.py index 6325f72..de59805 100644 --- a/lib/lp/translations/tests/test_autoapproval.py +++ b/lib/lp/translations/tests/test_autoapproval.py @@ -183,9 +183,7 @@ class TestGuessPOFileCustomLanguageCode( def _makePOFile(self, language_code): """Create a translation file.""" - file = self.template.newPOFile(language_code) - file.syncUpdate() - return file + return self.template.newPOFile(language_code) def _makeQueueEntry(self, language_code): """Create translation import queue entry.""" diff --git a/lib/lp/translations/tests/test_productserieslanguage.py b/lib/lp/translations/tests/test_productserieslanguage.py index 64468ee..f991325 100644 --- a/lib/lp/translations/tests/test_productserieslanguage.py +++ b/lib/lp/translations/tests/test_productserieslanguage.py @@ -6,6 +6,7 @@ from zope.interface.verify import verifyObject from zope.security.proxy import removeSecurityProxy from lp.app.enums import ServiceUsage +from lp.services.database.interfaces import IStore from lp.services.worlddata.interfaces.language import ILanguageSet from lp.testing import TestCaseWithFactory from lp.testing.layers import ZopelessDatabaseLayer @@ -124,7 +125,7 @@ class TestProductSeriesLanguageStatsCalculation(TestCaseWithFactory): naked_pofile.rosettacount = new naked_pofile.unreviewed_count = unreviewed naked_pofile.date_changed = date_changed - naked_pofile.sync() + IStore(naked_pofile).flush() def setUp(self): # Create a productseries that uses translations.
_______________________________________________ Mailing list: https://launchpad.net/~launchpad-reviewers Post to : launchpad-reviewers@lists.launchpad.net Unsubscribe : https://launchpad.net/~launchpad-reviewers More help : https://help.launchpad.net/ListHelp