launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #30296
[Merge] ~cjwatson/launchpad:stormify-packaging into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:stormify-packaging into launchpad:master.
Commit message:
Convert Packaging to Storm
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/447534
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:stormify-packaging into launchpad:master.
diff --git a/lib/lp/registry/model/distribution.py b/lib/lp/registry/model/distribution.py
index cf764f9..c2efa92 100644
--- a/lib/lp/registry/model/distribution.py
+++ b/lib/lp/registry/model/distribution.py
@@ -1610,7 +1610,7 @@ class Distribution(
1,
tables=[Packaging],
where=(
- Packaging.sourcepackagenameID == SourcePackageName.id
+ Packaging.sourcepackagename_id == SourcePackageName.id
),
)
)
diff --git a/lib/lp/registry/model/distributionsourcepackage.py b/lib/lp/registry/model/distributionsourcepackage.py
index 42a452d..1aacc71 100644
--- a/lib/lp/registry/model/distributionsourcepackage.py
+++ b/lib/lp/registry/model/distributionsourcepackage.py
@@ -365,7 +365,7 @@ class DistributionSourcePackage(
store = Store.of(self.sourcepackagename)
condition = And(
Packaging.sourcepackagename == self.sourcepackagename,
- Packaging.distroseriesID == DistroSeries.id,
+ Packaging.distroseries_id == DistroSeries.id,
DistroSeries.distribution == self.distribution,
)
result = store.find(Packaging, condition)
diff --git a/lib/lp/registry/model/distroseries.py b/lib/lp/registry/model/distroseries.py
index bcb4a27..cd596f2 100644
--- a/lib/lp/registry/model/distroseries.py
+++ b/lib/lp/registry/model/distroseries.py
@@ -1094,7 +1094,7 @@ class DistroSeries(
Not(
SourcePackageName.id.is_in(
Select(
- Packaging.sourcepackagenameID,
+ Packaging.sourcepackagename_id,
where=(Packaging.distroseries == self),
distinct=True,
)
@@ -1110,7 +1110,7 @@ class DistroSeries(
.find(
SourcePackageName,
Packaging.sourcepackagename == SourcePackageName.id,
- Is(Packaging.productseriesID, None),
+ Is(Packaging.productseries_id, None),
POTemplate.sourcepackagename == SourcePackageName.id,
POTemplate.distroseries == self,
)
diff --git a/lib/lp/registry/model/packaging.py b/lib/lp/registry/model/packaging.py
index 047b0e5..13555a9 100644
--- a/lib/lp/registry/model/packaging.py
+++ b/lib/lp/registry/model/packaging.py
@@ -3,7 +3,10 @@
__all__ = ["Packaging", "PackagingUtil"]
+from datetime import timezone
+
from lazr.lifecycle.event import ObjectCreatedEvent, ObjectDeletedEvent
+from storm.locals import DateTime, Int, Reference
from zope.component import getUtility
from zope.event import notify
from zope.interface import implementer
@@ -16,39 +19,36 @@ from lp.registry.interfaces.packaging import (
PackagingType,
)
from lp.registry.interfaces.person import validate_public_person
-from lp.services.database.constants import DEFAULT, UTC_NOW
-from lp.services.database.datetimecol import UtcDateTimeCol
+from lp.services.database.constants import UTC_NOW
from lp.services.database.enumcol import DBEnum
-from lp.services.database.sqlbase import SQLBase
-from lp.services.database.sqlobject import ForeignKey
+from lp.services.database.interfaces import IStore
+from lp.services.database.stormbase import StormBase
@implementer(IPackaging)
-class Packaging(SQLBase):
+class Packaging(StormBase):
"""A Packaging relating a SourcePackage and a Product."""
- _table = "Packaging"
+ __storm_table__ = "Packaging"
- productseries = ForeignKey(
- foreignKey="ProductSeries", dbName="productseries", notNull=True
- )
- sourcepackagename = ForeignKey(
- foreignKey="SourcePackageName",
- dbName="sourcepackagename",
- notNull=True,
- )
- distroseries = ForeignKey(
- foreignKey="DistroSeries", dbName="distroseries", notNull=True
- )
+ id = Int(primary=True)
+ productseries_id = Int(name="productseries", allow_none=False)
+ productseries = Reference(productseries_id, "ProductSeries.id")
+ sourcepackagename_id = Int(name="sourcepackagename", allow_none=False)
+ sourcepackagename = Reference(sourcepackagename_id, "SourcePackageName.id")
+ distroseries_id = Int(name="distroseries", allow_none=False)
+ distroseries = Reference(distroseries_id, "DistroSeries.id")
packaging = DBEnum(name="packaging", allow_none=False, enum=PackagingType)
- datecreated = UtcDateTimeCol(notNull=True, default=UTC_NOW)
- owner = ForeignKey(
- dbName="owner",
- foreignKey="Person",
- storm_validator=validate_public_person,
- notNull=False,
- default=DEFAULT,
+ datecreated = DateTime(
+ allow_none=False, default=UTC_NOW, tzinfo=timezone.utc
+ )
+ owner_id = Int(
+ name="owner",
+ validator=validate_public_person,
+ allow_none=True,
+ default=None,
)
+ owner = Reference(owner_id, "Person.id")
@property
def sourcepackage(self):
@@ -59,13 +59,25 @@ class Packaging(SQLBase):
sourcepackagename=self.sourcepackagename,
)
- def __init__(self, **kwargs):
- super().__init__(**kwargs)
+ def __init__(
+ self,
+ productseries,
+ sourcepackagename,
+ distroseries,
+ packaging,
+ owner=None,
+ ):
+ super().__init__()
+ self.productseries = productseries
+ self.sourcepackagename = sourcepackagename
+ self.distroseries = distroseries
+ self.packaging = packaging
+ self.owner = owner
notify(ObjectCreatedEvent(self))
def destroySelf(self):
notify(ObjectDeletedEvent(self))
- super().destroySelf()
+ IStore(self).remove(self)
@implementer(IPackagingUtil)
@@ -98,13 +110,15 @@ class PackagingUtil:
"Only Public project series can be packaged, not %s."
% info_type.title
)
- return Packaging(
+ packaging = Packaging(
productseries=productseries,
sourcepackagename=sourcepackagename,
distroseries=distroseries,
packaging=packaging,
owner=owner,
)
+ IStore(packaging).flush()
+ return packaging
def get(self, productseries, sourcepackagename, distroseries):
criteria = {
@@ -113,7 +127,7 @@ class PackagingUtil:
}
if productseries is not None:
criteria["productseries"] = productseries
- return Packaging.selectOneBy(**criteria)
+ return IStore(Packaging).find(Packaging, **criteria).one()
def deletePackaging(self, productseries, sourcepackagename, distroseries):
"""See `IPackaging`."""
diff --git a/lib/lp/registry/model/product.py b/lib/lp/registry/model/product.py
index 6ab546e..e0edcdb 100644
--- a/lib/lp/registry/model/product.py
+++ b/lib/lp/registry/model/product.py
@@ -1096,16 +1096,27 @@ class Product(
def sourcepackages(self):
from lp.registry.model.sourcepackage import SourcePackage
- clause = """ProductSeries.id=Packaging.productseries AND
- ProductSeries.product = %s
- """ % sqlvalues(
- self.id
- )
- clauseTables = ["ProductSeries"]
- ret = Packaging.select(
- clause,
- clauseTables,
- prejoins=["sourcepackagename", "distroseries.distribution"],
+ ret = DecoratedResultSet(
+ IStore(Packaging)
+ .using(
+ Packaging,
+ Join(
+ ProductSeries, Packaging.productseries == ProductSeries.id
+ ),
+ Join(
+ SourcePackageName,
+ Packaging.sourcepackagename == SourcePackageName.id,
+ ),
+ Join(DistroSeries, Packaging.distroseries == DistroSeries.id),
+ Join(
+ Distribution, DistroSeries.distribution == Distribution.id
+ ),
+ )
+ .find(
+ (Packaging, SourcePackageName, DistroSeries, Distribution),
+ ProductSeries.product == self,
+ ),
+ result_decorator=operator.itemgetter(0),
)
sps = [
SourcePackage(
diff --git a/lib/lp/registry/model/productseries.py b/lib/lp/registry/model/productseries.py
index 0bd1479..3c75348 100644
--- a/lib/lp/registry/model/productseries.py
+++ b/lib/lp/registry/model/productseries.py
@@ -14,11 +14,10 @@ from operator import itemgetter
from lazr.delegates import delegate_to
from storm.expr import Max, Sum
-from storm.locals import And, Desc
+from storm.locals import And, Desc, ReferenceSet
from storm.store import Store
from zope.component import getUtility
from zope.interface import implementer
-from zope.security.proxy import removeSecurityProxy
from lp.app.enums import service_uses_launchpad
from lp.app.errors import NotFoundError
@@ -57,7 +56,6 @@ from lp.services.database.interfaces import IStore
from lp.services.database.sqlbase import SQLBase
from lp.services.database.sqlobject import (
ForeignKey,
- SQLMultipleJoin,
SQLObjectNotFound,
StringCol,
)
@@ -162,8 +160,8 @@ class ProductSeries(
releasefileglob = StringCol(default=None)
releaseverstyle = StringCol(default=None)
- packagings = SQLMultipleJoin(
- "Packaging", joinColumn="productseries", orderBy=["-id"]
+ packagings = ReferenceSet(
+ "id", "Packaging.productseries_id", order_by=Desc("Packaging.id")
)
@property
@@ -449,7 +447,7 @@ class ProductSeries(
packaging=PackagingType.PRIME,
owner=owner,
)
- removeSecurityProxy(pkg).sync() # convert UTC_NOW to actual datetime
+ IStore(pkg).flush() # convert UTC_NOW to actual datetime
return pkg
def getPackagingInDistribution(self, distribution):
diff --git a/lib/lp/registry/tests/test_packaging.py b/lib/lp/registry/tests/test_packaging.py
index 5f1f337..2ba7526 100644
--- a/lib/lp/registry/tests/test_packaging.py
+++ b/lib/lp/registry/tests/test_packaging.py
@@ -34,8 +34,18 @@ class TestPackaging(TestCaseWithFactory):
def test_init_notifies(self):
"""Creating a Packaging should generate an event."""
+ productseries = self.factory.makeProduct().development_focus
+ sourcepackagename = self.factory.makeSourcePackageName()
+ distroseries = self.factory.makeDistroSeries()
+ owner = self.factory.makePerson()
with EventRecorder() as recorder:
- packaging = Packaging()
+ packaging = Packaging(
+ productseries=productseries,
+ sourcepackagename=sourcepackagename,
+ distroseries=distroseries,
+ packaging=PackagingType.PRIME,
+ owner=owner,
+ )
(event,) = recorder.events
self.assertIsInstance(event, ObjectCreatedEvent)
self.assertIs(packaging, event.object)
diff --git a/lib/lp/translations/browser/potemplate.py b/lib/lp/translations/browser/potemplate.py
index 92e3cec..12a684f 100644
--- a/lib/lp/translations/browser/potemplate.py
+++ b/lib/lp/translations/browser/potemplate.py
@@ -1031,7 +1031,7 @@ class BaseSeriesTemplatesView(LaunchpadView):
),
)
.joinOuter(
- ProductSeries, ProductSeries.id == Packaging.productseriesID
+ ProductSeries, ProductSeries.id == Packaging.productseries_id
)
.joinOuter(
Product,