launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #11872
[Merge] lp:~deryck/launchpad/specification-sharing-policy-garbo into lp:launchpad
Deryck Hodge has proposed merging lp:~deryck/launchpad/specification-sharing-policy-garbo into lp:launchpad with lp:~deryck/launchpad/specification-sharing-policy-unused as a prerequisite.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~deryck/launchpad/specification-sharing-policy-garbo/+merge/124026
This branch adds a garbo class to update all products to set specification_sharing_policy to 1, which is public. Public is the default for all projects. This is part of a transition in the schema to support specification sharing. After this and its prerequiste land, I'll put up a branch that will make use of all this.
--
https://code.launchpad.net/~deryck/launchpad/specification-sharing-policy-garbo/+merge/124026
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~deryck/launchpad/specification-sharing-policy-garbo into lp:launchpad.
=== modified file 'lib/lp/scripts/garbo.py'
--- lib/lp/scripts/garbo.py 2012-09-03 06:41:06 +0000
+++ lib/lp/scripts/garbo.py 2012-09-12 18:33:23 +0000
@@ -27,7 +27,11 @@
import iso8601
from psycopg2 import IntegrityError
import pytz
-from storm.expr import In
+from storm.expr import (
+ In,
+ Select,
+ Update,
+ )
from storm.locals import (
Max,
Min,
@@ -906,6 +910,33 @@
self._update_oldest()
+class SpecificationSharingPolicyDefault(TunableLoop):
+ """Set all Product.specification_sharing_policy to Public."""
+
+ maximum_chunk_size = 1000
+
+ def __init__(self, log, abort_time=None):
+ super(SpecificationSharingPolicyDefault, self).__init__(
+ log, abort_time)
+ self.rows_updated = None
+ self.store = IMasterStore(Product)
+
+ def isDone(self):
+ """See `TunableLoop`."""
+ return self.rows_updated == 0
+
+ def __call__(self, chunk_size):
+ """See `TunableLoop`."""
+ subselect = Select(
+ Product.id, Product.specification_sharing_policy == None,
+ limit=chunk_size)
+ result = self.store.execute(
+ Update({Product.specification_sharing_policy: 1},
+ Product.id.is_in(subselect)))
+ transaction.commit()
+ self.rows_updated = result.rowcount
+
+
class SuggestiveTemplatesCacheUpdater(TunableLoop):
"""Refresh the SuggestivePOTemplate cache.
@@ -1300,6 +1331,7 @@
OldTimeLimitedTokenDeleter,
RevisionAuthorEmailLinker,
ScrubPOFileTranslator,
+ SpecificationSharingPolicyDefault,
SuggestiveTemplatesCacheUpdater,
POTranslationPruner,
UnlinkedAccountPruner,
=== modified file 'lib/lp/scripts/tests/test_garbo.py'
--- lib/lp/scripts/tests/test_garbo.py 2012-09-03 06:41:06 +0000
+++ lib/lp/scripts/tests/test_garbo.py 2012-09-12 18:33:23 +0000
@@ -19,6 +19,7 @@
In,
Min,
Not,
+ Update,
SQL,
)
from storm.locals import (
@@ -58,6 +59,8 @@
)
from lp.registry.interfaces.accesspolicy import IAccessPolicySource
from lp.registry.interfaces.person import IPersonSet
+from lp.registry.interfaces.product import IProductSet
+from lp.registry.model.product import Product
from lp.scripts.garbo import (
AntiqueSessionPruner,
BulkPruner,
@@ -1057,6 +1060,23 @@
[InformationType.PRIVATESECURITY, InformationType.PROPRIETARY],
self.getAccessPolicyTypes(product))
+ def test_SpecificationSharingPolicyDefault(self):
+ switch_dbuser('testadmin')
+ # Set all existing projects to something other than None or 1.
+ store = IMasterStore(Product)
+ store.execute(Update(
+ {Product.specification_sharing_policy: 2}))
+ store.flush()
+ # Make a new product without a specification_sharing_policy.
+ product = self.factory.makeProduct()
+ removeSecurityProxy(product).specification_sharing_policy = None
+ store.flush()
+ self.assertEqual(1, store.find(Product,
+ Product.specification_sharing_policy == None).count())
+ self.runDaily()
+ self.assertEqual(0, store.find(Product,
+ Product.specification_sharing_policy == None).count())
+
class TestGarboTasks(TestCaseWithFactory):
layer = LaunchpadZopelessLayer
Follow ups