Merge lp:~jpds/launchpad/stormify-distribution-bits into lp:launchpad

Proposed by Jonathan Davies
Status: Merged
Merged at revision: 10676
Proposed branch: lp:~jpds/launchpad/stormify-distribution-bits
Merge into: lp:launchpad
Diff against target: 161 lines (+53/-32)
1 file modified
lib/lp/registry/model/distribution.py (+53/-32)
To merge this branch: bzr merge lp:~jpds/launchpad/stormify-distribution-bits
Reviewer Review Type Date Requested Status
Abel Deuring (community) Approve
Canonical Launchpad Engineering code Pending
Review via email: mp+23060@code.launchpad.net

Commit message

Converted various bits of SQLBase code in Distribution over to Storm.

Description of the change

= Summary =

Converted various bits of SQLBase code in Distribution over to Storm.

= Pre-imp call =

I talked to Curtis about this who +1'ed the idea.

To post a comment you must log in.
Revision history for this message
Abel Deuring (adeuring) wrote :

Hi Jonathan,

nice work!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/model/distribution.py'
2--- lib/lp/registry/model/distribution.py 2010-04-06 21:42:28 +0000
3+++ lib/lp/registry/model/distribution.py 2010-04-09 00:42:34 +0000
4@@ -242,16 +242,16 @@
5 @cachedproperty
6 def main_archive(self):
7 """See `IDistribution`."""
8- return Archive.selectOneBy(distribution=self,
9- purpose=ArchivePurpose.PRIMARY)
10+ return Store.of(self).find(Archive, distribution=self,
11+ purpose=ArchivePurpose.PRIMARY).one()
12
13 @cachedproperty
14 def all_distro_archives(self):
15 """See `IDistribution`."""
16- return Archive.select("""
17- Distribution = %s AND
18- Purpose IN %s""" % sqlvalues(self.id, MAIN_ARCHIVE_PURPOSES)
19- )
20+ return Store.of(self).find(
21+ Archive,
22+ Archive.distribution == self,
23+ Archive.purpose.is_in(MAIN_ARCHIVE_PURPOSES))
24
25 @cachedproperty
26 def all_distro_archive_ids(self):
27@@ -272,35 +272,50 @@
28 @property
29 def archive_mirrors(self):
30 """See `IDistribution`."""
31- return DistributionMirror.selectBy(
32- distribution=self, content=MirrorContent.ARCHIVE, enabled=True,
33- status=MirrorStatus.OFFICIAL, official_candidate=True)
34+ return Store.of(self).find(
35+ DistributionMirror,
36+ distribution=self,
37+ content=MirrorContent.ARCHIVE,
38+ enabled=True,
39+ status=MirrorStatus.OFFICIAL,
40+ official_candidate=True)
41
42 @property
43 def cdimage_mirrors(self):
44 """See `IDistribution`."""
45- return DistributionMirror.selectBy(
46- distribution=self, content=MirrorContent.RELEASE, enabled=True,
47- status=MirrorStatus.OFFICIAL, official_candidate=True)
48+ return Store.of(self).find(
49+ DistributionMirror,
50+ distribution=self,
51+ content=MirrorContent.RELEASE,
52+ enabled=True,
53+ status=MirrorStatus.OFFICIAL,
54+ official_candidate=True)
55
56 @property
57 def disabled_mirrors(self):
58 """See `IDistribution`."""
59- return DistributionMirror.selectBy(
60- distribution=self, status=MirrorStatus.OFFICIAL,
61- official_candidate=True, enabled=False)
62+ return Store.of(self).find(
63+ DistributionMirror,
64+ distribution=self,
65+ enabled=False,
66+ status=MirrorStatus.OFFICIAL,
67+ official_candidate=True)
68
69 @property
70 def unofficial_mirrors(self):
71 """See `IDistribution`."""
72- return DistributionMirror.selectBy(
73- distribution=self, status=MirrorStatus.UNOFFICIAL)
74+ return Store.of(self).find(
75+ DistributionMirror,
76+ distribution=self,
77+ status=MirrorStatus.UNOFFICIAL)
78
79 @property
80 def pending_review_mirrors(self):
81 """See `IDistribution`."""
82- return DistributionMirror.selectBy(
83- distribution=self, status=MirrorStatus.PENDING_REVIEW,
84+ return Store.of(self).find(
85+ DistributionMirror,
86+ distribution=self,
87+ status=MirrorStatus.PENDING_REVIEW,
88 official_candidate=True)
89
90 @property
91@@ -337,7 +352,9 @@
92 @cachedproperty('_cached_series')
93 def series(self):
94 """See `IDistribution`."""
95- ret = DistroSeries.selectBy(distribution=self)
96+ ret = Store.of(self).find(
97+ DistroSeries,
98+ distribution=self)
99 return sorted(ret, key=lambda a: Version(a.version), reverse=True)
100
101 @property
102@@ -400,18 +417,19 @@
103
104 def getMirrorByName(self, name):
105 """See `IDistribution`."""
106- return DistributionMirror.selectOneBy(distribution=self, name=name)
107+ return Store.of(self).find(
108+ DistributionMirror,
109+ distribution=self,
110+ name=name).one()
111
112 def getCountryMirror(self, country, mirror_type):
113 """See `IDistribution`."""
114- store = Store.of(self)
115- results = store.find(
116+ return Store.of(self).find(
117 DistributionMirror,
118- DistributionMirror.distribution == self,
119- DistributionMirror.country == country,
120- DistributionMirror.content == mirror_type,
121- DistributionMirror.country_dns_mirror == True)
122- return results.one()
123+ distribution=self,
124+ country=country,
125+ content=mirror_type,
126+ country_dns_mirror=True).one()
127
128 def newMirror(self, owner, speed, country, content, displayname=None,
129 description=None, http_base_url=None,
130@@ -441,7 +459,7 @@
131
132 orig_name = name
133 count = 1
134- while DistributionMirror.selectOneBy(name=name) is not None:
135+ while self.getMirrorByName(name=name) is not None:
136 count += 1
137 name = '%s%s' % (orig_name, count)
138
139@@ -509,7 +527,8 @@
140
141 def getDevelopmentSeries(self):
142 """See `IDistribution`."""
143- return DistroSeries.selectBy(
144+ return Store.of(self).find(
145+ DistroSeries,
146 distribution=self,
147 status=SeriesStatus.DEVELOPMENT)
148
149@@ -1218,8 +1237,10 @@
150 # already too long and complicated.
151 def getAllPPAs(self):
152 """See `IDistribution`"""
153- return Archive.selectBy(
154- purpose=ArchivePurpose.PPA, distribution=self, orderBy=['id'])
155+ return Store.of(self).find(
156+ Archive,
157+ distribution=self,
158+ purpose=ArchivePurpose.PPA).order_by('id')
159
160 def searchPPAs(self, text=None, show_inactive=False, user=None):
161 """See `IDistribution`."""