← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:stormify-processor into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:stormify-processor into launchpad:master.

Commit message:
Convert Processor to Storm

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/450566
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:stormify-processor into launchpad:master.
diff --git a/lib/lp/buildmaster/model/processor.py b/lib/lp/buildmaster/model/processor.py
index 15a3871..c6e91bc 100644
--- a/lib/lp/buildmaster/model/processor.py
+++ b/lib/lp/buildmaster/model/processor.py
@@ -6,7 +6,7 @@ __all__ = [
     "ProcessorSet",
 ]
 
-from storm.locals import Bool
+from storm.locals import Bool, Int, Unicode
 from zope.interface import implementer
 
 from lp.buildmaster.interfaces.processor import (
@@ -14,18 +14,20 @@ from lp.buildmaster.interfaces.processor import (
     IProcessorSet,
     ProcessorNotFound,
 )
+from lp.services.database.constants import DEFAULT
 from lp.services.database.interfaces import IStore
-from lp.services.database.sqlbase import SQLBase
-from lp.services.database.sqlobject import StringCol
+from lp.services.database.stormbase import StormBase
 
 
 @implementer(IProcessor)
-class Processor(SQLBase):
-    _table = "Processor"
+class Processor(StormBase):
+    __storm_table__ = "Processor"
 
-    name = StringCol(dbName="name", notNull=True)
-    title = StringCol(dbName="title", notNull=True)
-    description = StringCol(dbName="description", notNull=True)
+    id = Int(primary=True)
+
+    name = Unicode(name="name", allow_none=False)
+    title = Unicode(name="title", allow_none=False)
+    description = Unicode(name="description", allow_none=False)
     restricted = Bool(allow_none=False, default=False)
 
     # When setting this to true you may want to add missing
@@ -41,6 +43,25 @@ class Processor(SQLBase):
     # changed on an existing processor.
     supports_nonvirtualized = Bool(allow_none=False, default=True)
 
+    def __init__(
+        self,
+        name,
+        title,
+        description,
+        restricted=DEFAULT,
+        build_by_default=DEFAULT,
+        supports_virtualized=DEFAULT,
+        supports_nonvirtualized=DEFAULT,
+    ):
+        super().__init__()
+        self.name = name
+        self.title = title
+        self.description = description
+        self.restricted = restricted
+        self.build_by_default = build_by_default
+        self.supports_virtualized = supports_virtualized
+        self.supports_nonvirtualized = supports_nonvirtualized
+
     def __repr__(self):
         return "<Processor %r>" % self.title
 
@@ -73,7 +94,7 @@ class ProcessorSet:
         supports_nonvirtualized=True,
     ):
         """See `IProcessorSet`."""
-        return Processor(
+        processor = Processor(
             name=name,
             title=title,
             description=description,
@@ -82,3 +103,4 @@ class ProcessorSet:
             supports_virtualized=supports_virtualized,
             supports_nonvirtualized=supports_nonvirtualized,
         )
+        return IStore(Processor).add(processor)
diff --git a/lib/lp/buildmaster/stories/builder-views.rst b/lib/lp/buildmaster/stories/builder-views.rst
index ad45813..7ff220b 100644
--- a/lib/lp/buildmaster/stories/builder-views.rst
+++ b/lib/lp/buildmaster/stories/builder-views.rst
@@ -273,9 +273,10 @@ architectures.
     >>> cprov = getUtility(IPersonSet).getByName("cprov")
 
     >>> from lp.buildmaster.model.processor import Processor
-    >>> i386 = Processor.selectOneBy(name="386")
-    >>> amd64 = Processor.selectOneBy(name="amd64")
-    >>> hppa = Processor.selectOneBy(name="hppa")
+    >>> from lp.services.database.interfaces import IStore
+    >>> i386 = IStore(Processor).find(Processor, name="386").one()
+    >>> amd64 = IStore(Processor).find(Processor, name="amd64").one()
+    >>> hppa = IStore(Processor).find(Processor, name="hppa").one()
 
     >>> ignored = factory.makeBuilder(
     ...     name="hamburger", processors=[i386], virtualized=True
diff --git a/lib/lp/buildmaster/vocabularies.py b/lib/lp/buildmaster/vocabularies.py
index d6a439c..31acd16 100644
--- a/lib/lp/buildmaster/vocabularies.py
+++ b/lib/lp/buildmaster/vocabularies.py
@@ -18,13 +18,13 @@ from lp.buildmaster.model.processor import Processor
 from lp.services.database.interfaces import IStore
 from lp.services.database.stormexpr import Concatenate
 from lp.services.propertycache import cachedproperty
-from lp.services.webapp.vocabulary import NamedSQLObjectVocabulary
+from lp.services.webapp.vocabulary import NamedStormVocabulary
 
 
-class ProcessorVocabulary(NamedSQLObjectVocabulary):
+class ProcessorVocabulary(NamedStormVocabulary):
     displayname = "Select a processor"
     _table = Processor
-    _orderBy = "name"
+    _order_by = "name"
 
 
 @implementer(IVocabularyTokenized)
diff --git a/lib/lp/services/webapp/vocabulary.py b/lib/lp/services/webapp/vocabulary.py
index 294dd8c..535588c 100644
--- a/lib/lp/services/webapp/vocabulary.py
+++ b/lib/lp/services/webapp/vocabulary.py
@@ -440,7 +440,7 @@ class StormVocabularyBase(FilteredVocabularyBase):
     should derive from StormVocabularyBase.
     """
 
-    _order_by = None
+    _order_by = None  # type: Optional[str]
     _clauses = []
 
     def __init__(self, context=None):
diff --git a/lib/lp/soyuz/doc/soyuz-set-of-uploads.rst b/lib/lp/soyuz/doc/soyuz-set-of-uploads.rst
index 0355122..2cda351 100644
--- a/lib/lp/soyuz/doc/soyuz-set-of-uploads.rst
+++ b/lib/lp/soyuz/doc/soyuz-set-of-uploads.rst
@@ -563,8 +563,8 @@ In order to verify if the binary ancestry lookup algorithm works we
 will need to build a new DistroArchSeries for powerpc in
 ubuntutest/breezy.
 
-    >>> from lp.buildmaster.model.processor import Processor
-    >>> powerpc = Processor(
+    >>> from lp.buildmaster.interfaces.processor import IProcessorSet
+    >>> powerpc = getUtility(IProcessorSet).new(
     ...     name="powerpc", title="PowerPC G3/G4", description="G3/G4"
     ... )
     >>> powerpc_dar = breezy.newArch("powerpc", powerpc, True, breezy.owner)