Merge lp:~deryck/launchpad/specification-sharing-policy-garbo into lp:launchpad

Proposed by Deryck Hodge on 2012-09-12
Status: Merged
Approved by: Deryck Hodge on 2012-09-13
Approved revision: no longer in the source branch.
Merged at revision: 15964
Proposed branch: lp:~deryck/launchpad/specification-sharing-policy-garbo
Merge into: lp:launchpad
Prerequisite: lp:~deryck/launchpad/specification-sharing-policy-unused
Diff against target: 103 lines (+53/-1)
2 files modified
lib/lp/scripts/garbo.py (+33/-1)
lib/lp/scripts/tests/test_garbo.py (+20/-0)
To merge this branch: bzr merge lp:~deryck/launchpad/specification-sharing-policy-garbo
Reviewer Review Type Date Requested Status
Aaron Bentley (community) 2012-09-12 Approve on 2012-09-12
Review via email: mp+124026@code.launchpad.net

This proposal supersedes a proposal from 2012-09-12.

Commit Message

Add garbo job to set Product.specification_sharing_policy to 1, which is Public. This is part of transitioning our schema to support specification sharing.

Description of the Change

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.

To post a comment you must log in.
Aaron Bentley (abentley) wrote :

Look good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/scripts/garbo.py'
2--- lib/lp/scripts/garbo.py 2012-09-03 06:41:06 +0000
3+++ lib/lp/scripts/garbo.py 2012-09-12 18:33:23 +0000
4@@ -27,7 +27,11 @@
5 import iso8601
6 from psycopg2 import IntegrityError
7 import pytz
8-from storm.expr import In
9+from storm.expr import (
10+ In,
11+ Select,
12+ Update,
13+ )
14 from storm.locals import (
15 Max,
16 Min,
17@@ -906,6 +910,33 @@
18 self._update_oldest()
19
20
21+class SpecificationSharingPolicyDefault(TunableLoop):
22+ """Set all Product.specification_sharing_policy to Public."""
23+
24+ maximum_chunk_size = 1000
25+
26+ def __init__(self, log, abort_time=None):
27+ super(SpecificationSharingPolicyDefault, self).__init__(
28+ log, abort_time)
29+ self.rows_updated = None
30+ self.store = IMasterStore(Product)
31+
32+ def isDone(self):
33+ """See `TunableLoop`."""
34+ return self.rows_updated == 0
35+
36+ def __call__(self, chunk_size):
37+ """See `TunableLoop`."""
38+ subselect = Select(
39+ Product.id, Product.specification_sharing_policy == None,
40+ limit=chunk_size)
41+ result = self.store.execute(
42+ Update({Product.specification_sharing_policy: 1},
43+ Product.id.is_in(subselect)))
44+ transaction.commit()
45+ self.rows_updated = result.rowcount
46+
47+
48 class SuggestiveTemplatesCacheUpdater(TunableLoop):
49 """Refresh the SuggestivePOTemplate cache.
50
51@@ -1300,6 +1331,7 @@
52 OldTimeLimitedTokenDeleter,
53 RevisionAuthorEmailLinker,
54 ScrubPOFileTranslator,
55+ SpecificationSharingPolicyDefault,
56 SuggestiveTemplatesCacheUpdater,
57 POTranslationPruner,
58 UnlinkedAccountPruner,
59
60=== modified file 'lib/lp/scripts/tests/test_garbo.py'
61--- lib/lp/scripts/tests/test_garbo.py 2012-09-03 06:41:06 +0000
62+++ lib/lp/scripts/tests/test_garbo.py 2012-09-12 18:33:23 +0000
63@@ -19,6 +19,7 @@
64 In,
65 Min,
66 Not,
67+ Update,
68 SQL,
69 )
70 from storm.locals import (
71@@ -58,6 +59,8 @@
72 )
73 from lp.registry.interfaces.accesspolicy import IAccessPolicySource
74 from lp.registry.interfaces.person import IPersonSet
75+from lp.registry.interfaces.product import IProductSet
76+from lp.registry.model.product import Product
77 from lp.scripts.garbo import (
78 AntiqueSessionPruner,
79 BulkPruner,
80@@ -1057,6 +1060,23 @@
81 [InformationType.PRIVATESECURITY, InformationType.PROPRIETARY],
82 self.getAccessPolicyTypes(product))
83
84+ def test_SpecificationSharingPolicyDefault(self):
85+ switch_dbuser('testadmin')
86+ # Set all existing projects to something other than None or 1.
87+ store = IMasterStore(Product)
88+ store.execute(Update(
89+ {Product.specification_sharing_policy: 2}))
90+ store.flush()
91+ # Make a new product without a specification_sharing_policy.
92+ product = self.factory.makeProduct()
93+ removeSecurityProxy(product).specification_sharing_policy = None
94+ store.flush()
95+ self.assertEqual(1, store.find(Product,
96+ Product.specification_sharing_policy == None).count())
97+ self.runDaily()
98+ self.assertEqual(0, store.find(Product,
99+ Product.specification_sharing_policy == None).count())
100+
101
102 class TestGarboTasks(TestCaseWithFactory):
103 layer = LaunchpadZopelessLayer