Merge ~cjwatson/launchpad:stormify-translationtemplateitem into launchpad:master
- Git
- lp:~cjwatson/launchpad
- stormify-translationtemplateitem
- Merge into master
Proposed by
Colin Watson
Status: | Merged |
---|---|
Approved by: | Colin Watson |
Approved revision: | e3430e13c8462e30e530c8f993c9f9bd3efc33f6 |
Merge reported by: | Otto Co-Pilot |
Merged at revision: | not available |
Proposed branch: | ~cjwatson/launchpad:stormify-translationtemplateitem |
Merge into: | launchpad:master |
Diff against target: |
331 lines (+59/-51) 9 files modified
lib/lp/scripts/garbo.py (+1/-1) lib/lp/scripts/tests/test_garbo.py (+2/-2) lib/lp/translations/model/pofile.py (+17/-17) lib/lp/translations/model/potemplate.py (+6/-6) lib/lp/translations/model/translationmessage.py (+4/-4) lib/lp/translations/model/translationtemplateitem.py (+19/-11) lib/lp/translations/scripts/migrate_current_flag.py (+2/-2) lib/lp/translations/scripts/scrub_pofiletranslator.py (+2/-2) lib/lp/translations/utilities/translationsplitter.py (+6/-6) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Simone Pelosi | Approve | ||
Review via email: mp+446326@code.launchpad.net |
Commit message
Convert TranslationTemp
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/lib/lp/scripts/garbo.py b/lib/lp/scripts/garbo.py |
2 | index 86adeaa..57dc83a 100644 |
3 | --- a/lib/lp/scripts/garbo.py |
4 | +++ b/lib/lp/scripts/garbo.py |
5 | @@ -1618,7 +1618,7 @@ class UnusedPOTMsgSetPruner(TunableLoop): |
6 | store = IPrimaryStore(POTMsgSet) |
7 | related_ttis = store.find( |
8 | TranslationTemplateItem, |
9 | - In(TranslationTemplateItem.potmsgsetID, msgset_ids_to_remove), |
10 | + In(TranslationTemplateItem.potmsgset_id, msgset_ids_to_remove), |
11 | ) |
12 | related_ttis.remove() |
13 | # Remove related TranslationMessages. |
14 | diff --git a/lib/lp/scripts/tests/test_garbo.py b/lib/lp/scripts/tests/test_garbo.py |
15 | index 3e92ec0..71d302f 100644 |
16 | --- a/lib/lp/scripts/tests/test_garbo.py |
17 | +++ b/lib/lp/scripts/tests/test_garbo.py |
18 | @@ -1399,7 +1399,7 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory): |
19 | test_ids = list(potmsgset_pofile) |
20 | obsolete_msgsets = store.find( |
21 | POTMsgSet, |
22 | - In(TranslationTemplateItem.potmsgsetID, test_ids), |
23 | + In(TranslationTemplateItem.potmsgset_id, test_ids), |
24 | TranslationTemplateItem.sequence == 0, |
25 | ) |
26 | self.assertEqual(4, obsolete_msgsets.count()) |
27 | @@ -1420,7 +1420,7 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory): |
28 | pruner(2) |
29 | self.assertEqual(0, obsolete_msgsets.count()) |
30 | preserved_msgsets = store.find( |
31 | - POTMsgSet, In(TranslationTemplateItem.potmsgsetID, test_ids) |
32 | + POTMsgSet, In(TranslationTemplateItem.potmsgset_id, test_ids) |
33 | ) |
34 | self.assertEqual(1, preserved_msgsets.count()) |
35 | |
36 | diff --git a/lib/lp/translations/model/pofile.py b/lib/lp/translations/model/pofile.py |
37 | index 8d09c17..6539f65 100644 |
38 | --- a/lib/lp/translations/model/pofile.py |
39 | +++ b/lib/lp/translations/model/pofile.py |
40 | @@ -155,7 +155,7 @@ class POFileMixIn(RosettaStats): |
41 | Join( |
42 | TranslationTemplateItem, |
43 | tm_ids.potmsgsetID |
44 | - == TranslationTemplateItem.potmsgsetID, |
45 | + == TranslationTemplateItem.potmsgset_id, |
46 | ), |
47 | ), |
48 | where=And( |
49 | @@ -181,7 +181,7 @@ class POFileMixIn(RosettaStats): |
50 | Join( |
51 | TranslationTemplateItem, |
52 | TranslationMessage.potmsgset |
53 | - == TranslationTemplateItem.potmsgsetID, |
54 | + == TranslationTemplateItem.potmsgset_id, |
55 | ), |
56 | ), |
57 | where=And( |
58 | @@ -389,7 +389,7 @@ class POFile(SQLBase, POFileMixIn): |
59 | TranslationMessage.potemplateID, self.potemplate.id |
60 | ) |
61 | clauses = [ |
62 | - TranslationTemplateItem.potmsgsetID |
63 | + TranslationTemplateItem.potmsgset_id |
64 | == TranslationMessage.potmsgsetID, |
65 | TranslationTemplateItem.potemplate == self.potemplate, |
66 | TranslationMessage.language == self.language, |
67 | @@ -535,7 +535,7 @@ class POFile(SQLBase, POFileMixIn): |
68 | clauses = [ |
69 | TranslationTemplateItem.potemplate == self.potemplate, |
70 | ( |
71 | - TranslationTemplateItem.potmsgsetID |
72 | + TranslationTemplateItem.potmsgset_id |
73 | == TranslationMessage.potmsgsetID |
74 | ), |
75 | TranslationMessage.language == self.language, |
76 | @@ -612,7 +612,7 @@ class POFile(SQLBase, POFileMixIn): |
77 | """See `IPOFile`.""" |
78 | clauses, clause_tables = self._getTranslatedMessagesQuery() |
79 | query = And( |
80 | - TranslationTemplateItem.potmsgsetID == POTMsgSet.id, *clauses |
81 | + TranslationTemplateItem.potmsgset_id == POTMsgSet.id, *clauses |
82 | ) |
83 | clause_tables.insert(0, POTMsgSet) |
84 | return self._getOrderedPOTMsgSets(clause_tables, query) |
85 | @@ -631,17 +631,17 @@ class POFile(SQLBase, POFileMixIn): |
86 | # staging we get more than a 10x speed improvement: from |
87 | # 8s to 0.7s). We also need to put it before any other |
88 | # clauses to be actually useful. |
89 | - TranslationTemplateItem.potmsgsetID |
90 | - == TranslationTemplateItem.potmsgsetID, |
91 | - POTMsgSet.id == TranslationTemplateItem.potmsgsetID, |
92 | + TranslationTemplateItem.potmsgset_id |
93 | + == TranslationTemplateItem.potmsgset_id, |
94 | + POTMsgSet.id == TranslationTemplateItem.potmsgset_id, |
95 | *translated_clauses, |
96 | ), |
97 | ) |
98 | clauses = [ |
99 | - TranslationTemplateItem.potemplateID == self.potemplate.id, |
100 | - TranslationTemplateItem.potmsgsetID == POTMsgSet.id, |
101 | + TranslationTemplateItem.potemplate_id == self.potemplate.id, |
102 | + TranslationTemplateItem.potmsgset_id == POTMsgSet.id, |
103 | TranslationTemplateItem.sequence > 0, |
104 | - Not(TranslationTemplateItem.potmsgsetID.is_in(translated_query)), |
105 | + Not(TranslationTemplateItem.potmsgset_id.is_in(translated_query)), |
106 | ] |
107 | return self._getOrderedPOTMsgSets( |
108 | [POTMsgSet, TranslationTemplateItem], And(*clauses) |
109 | @@ -663,7 +663,7 @@ class POFile(SQLBase, POFileMixIn): |
110 | ) |
111 | clauses.extend( |
112 | [ |
113 | - TranslationTemplateItem.potmsgsetID == POTMsgSet.id, |
114 | + TranslationTemplateItem.potmsgset_id == POTMsgSet.id, |
115 | Not(getattr(TranslationMessage, flag_name)), |
116 | msgstr_clause, |
117 | ] |
118 | @@ -718,8 +718,8 @@ class POFile(SQLBase, POFileMixIn): |
119 | distinct=True, |
120 | ) |
121 | ), |
122 | - POTMsgSet.id == TranslationTemplateItem.potmsgsetID, |
123 | - TranslationTemplateItem.potemplateID == self.potemplate.id, |
124 | + POTMsgSet.id == TranslationTemplateItem.potmsgset_id, |
125 | + TranslationTemplateItem.potemplate_id == self.potemplate.id, |
126 | ) |
127 | return self._getOrderedPOTMsgSets( |
128 | [POTMsgSet, TranslationTemplateItem], query |
129 | @@ -739,7 +739,7 @@ class POFile(SQLBase, POFileMixIn): |
130 | ) |
131 | clauses.extend( |
132 | [ |
133 | - TranslationTemplateItem.potmsgsetID == POTMsgSet.id, |
134 | + TranslationTemplateItem.potmsgset_id == POTMsgSet.id, |
135 | Not(getattr(TranslationMessage, other_side_flag_name)), |
136 | ] |
137 | ) |
138 | @@ -1626,8 +1626,8 @@ class POFileSet: |
139 | from lp.translations.model.potemplate import POTemplate |
140 | |
141 | clauses = [ |
142 | - TranslationTemplateItem.potemplateID == POFile.potemplateID, |
143 | - POTMsgSet.id == TranslationTemplateItem.potmsgsetID, |
144 | + TranslationTemplateItem.potemplate_id == POFile.potemplateID, |
145 | + POTMsgSet.id == TranslationTemplateItem.potmsgset_id, |
146 | POTMsgSet.msgid_singular == POMsgID.id, |
147 | POMsgID.msgid.is_in(POTMsgSet.credits_message_ids), |
148 | ] |
149 | diff --git a/lib/lp/translations/model/potemplate.py b/lib/lp/translations/model/potemplate.py |
150 | index e5a986f..3c293e4 100644 |
151 | --- a/lib/lp/translations/model/potemplate.py |
152 | +++ b/lib/lp/translations/model/potemplate.py |
153 | @@ -488,8 +488,8 @@ class POTemplate(SQLBase, RosettaStats): |
154 | """Return SQL clauses for finding POTMsgSets which belong |
155 | to this POTemplate.""" |
156 | clauses = [ |
157 | - TranslationTemplateItem.potemplateID == self.id, |
158 | - TranslationTemplateItem.potmsgsetID == POTMsgSet.id, |
159 | + TranslationTemplateItem.potemplate_id == self.id, |
160 | + TranslationTemplateItem.potmsgset_id == POTMsgSet.id, |
161 | ] |
162 | return clauses |
163 | |
164 | @@ -697,17 +697,17 @@ class POTemplate(SQLBase, RosettaStats): |
165 | POTMsgSet, look through sharing templates as well. |
166 | """ |
167 | clauses = [ |
168 | - TranslationTemplateItem.potmsgsetID == POTMsgSet.id, |
169 | + TranslationTemplateItem.potmsgset_id == POTMsgSet.id, |
170 | POTMsgSet.msgid_singular == msgid_singular, |
171 | POTMsgSet.msgid_plural == msgid_plural, |
172 | POTMsgSet.context == context, |
173 | ] |
174 | if sharing_templates: |
175 | clauses.append( |
176 | - TranslationTemplateItem.potemplateID.is_in(self._sharing_ids) |
177 | + TranslationTemplateItem.potemplate_id.is_in(self._sharing_ids) |
178 | ) |
179 | else: |
180 | - clauses.append(TranslationTemplateItem.potemplateID == self.id) |
181 | + clauses.append(TranslationTemplateItem.potemplate_id == self.id) |
182 | |
183 | # If there are multiple messages, make the one from the |
184 | # current POTemplate be returned first. |
185 | @@ -1137,7 +1137,7 @@ class POTemplate(SQLBase, RosettaStats): |
186 | rows = source.find( |
187 | (TranslationTemplateItem, POTMsgSet, Singular, Plural), |
188 | TranslationTemplateItem.potemplate == self, |
189 | - POTMsgSet.id == TranslationTemplateItem.potmsgsetID, |
190 | + POTMsgSet.id == TranslationTemplateItem.potmsgset_id, |
191 | ) |
192 | |
193 | rows = rows.order_by(TranslationTemplateItem.sequence) |
194 | diff --git a/lib/lp/translations/model/translationmessage.py b/lib/lp/translations/model/translationmessage.py |
195 | index 044cc6a..25403fb 100644 |
196 | --- a/lib/lp/translations/model/translationmessage.py |
197 | +++ b/lib/lp/translations/model/translationmessage.py |
198 | @@ -680,17 +680,17 @@ class TranslationMessageSet: |
199 | IStore(POFile) |
200 | .find( |
201 | ( |
202 | - TranslationTemplateItem.potmsgsetID, |
203 | + TranslationTemplateItem.potmsgset_id, |
204 | POFile.id, |
205 | TranslationTemplateItem.sequence, |
206 | ), |
207 | - TranslationTemplateItem.potmsgsetID.is_in( |
208 | + TranslationTemplateItem.potmsgset_id.is_in( |
209 | message.potmsgsetID for message in messages |
210 | ), |
211 | - POFile.potemplateID == TranslationTemplateItem.potemplateID, |
212 | + POFile.potemplateID == TranslationTemplateItem.potemplate_id, |
213 | *pofile_constraints, |
214 | ) |
215 | - .config(distinct=(TranslationTemplateItem.potmsgsetID,)) |
216 | + .config(distinct=(TranslationTemplateItem.potmsgset_id,)) |
217 | ) |
218 | potmsgset_map = { |
219 | potmsgset_id: (pofile_id, sequence) |
220 | diff --git a/lib/lp/translations/model/translationtemplateitem.py b/lib/lp/translations/model/translationtemplateitem.py |
221 | index 7198a3e..c79aff6 100644 |
222 | --- a/lib/lp/translations/model/translationtemplateitem.py |
223 | +++ b/lib/lp/translations/model/translationtemplateitem.py |
224 | @@ -5,25 +5,33 @@ __all__ = [ |
225 | "TranslationTemplateItem", |
226 | ] |
227 | |
228 | +from storm.locals import Int, Reference, Store |
229 | from zope.interface import implementer |
230 | |
231 | -from lp.services.database.sqlbase import SQLBase |
232 | -from lp.services.database.sqlobject import ForeignKey, IntCol |
233 | +from lp.services.database.stormbase import StormBase |
234 | from lp.translations.interfaces.translationtemplateitem import ( |
235 | ITranslationTemplateItem, |
236 | ) |
237 | |
238 | |
239 | @implementer(ITranslationTemplateItem) |
240 | -class TranslationTemplateItem(SQLBase): |
241 | +class TranslationTemplateItem(StormBase): |
242 | """See `ITranslationTemplateItem`.""" |
243 | |
244 | - _table = "TranslationTemplateItem" |
245 | + __storm_table__ = "TranslationTemplateItem" |
246 | |
247 | - potemplate = ForeignKey( |
248 | - foreignKey="POTemplate", dbName="potemplate", notNull=True |
249 | - ) |
250 | - sequence = IntCol(dbName="sequence", notNull=True) |
251 | - potmsgset = ForeignKey( |
252 | - foreignKey="POTMsgSet", dbName="potmsgset", notNull=True |
253 | - ) |
254 | + id = Int(primary=True) |
255 | + potemplate_id = Int(name="potemplate", allow_none=False) |
256 | + potemplate = Reference(potemplate_id, "POTemplate.id") |
257 | + sequence = Int(name="sequence", allow_none=False) |
258 | + potmsgset_id = Int(name="potmsgset", allow_none=False) |
259 | + potmsgset = Reference(potmsgset_id, "POTMsgSet.id") |
260 | + |
261 | + def __init__(self, potemplate, sequence, potmsgset): |
262 | + super().__init__() |
263 | + self.potemplate = potemplate |
264 | + self.sequence = sequence |
265 | + self.potmsgset = potmsgset |
266 | + |
267 | + def destroySelf(self): |
268 | + Store.of(self).remove(self) |
269 | diff --git a/lib/lp/translations/scripts/migrate_current_flag.py b/lib/lp/translations/scripts/migrate_current_flag.py |
270 | index 9b5bb46..0b09102 100644 |
271 | --- a/lib/lp/translations/scripts/migrate_current_flag.py |
272 | +++ b/lib/lp/translations/scripts/migrate_current_flag.py |
273 | @@ -148,9 +148,9 @@ class MigrateCurrentFlagProcess: |
274 | TranslationMessage.is_current_upstream == False, |
275 | ( |
276 | TranslationMessage.potmsgsetID |
277 | - == TranslationTemplateItem.potmsgsetID |
278 | + == TranslationTemplateItem.potmsgset_id |
279 | ), |
280 | - TranslationTemplateItem.potemplateID == POTemplate.id, |
281 | + TranslationTemplateItem.potemplate_id == POTemplate.id, |
282 | POTemplate.productseriesID == ProductSeries.id, |
283 | ProductSeries.productID == product.id, |
284 | ).config(distinct=True) |
285 | diff --git a/lib/lp/translations/scripts/scrub_pofiletranslator.py b/lib/lp/translations/scripts/scrub_pofiletranslator.py |
286 | index fbf8add..7aa0cb1 100644 |
287 | --- a/lib/lp/translations/scripts/scrub_pofiletranslator.py |
288 | +++ b/lib/lp/translations/scripts/scrub_pofiletranslator.py |
289 | @@ -68,8 +68,8 @@ def get_potmsgset_ids(potemplate_id): |
290 | store = IStore(POTemplate) |
291 | return set( |
292 | store.find( |
293 | - TranslationTemplateItem.potmsgsetID, |
294 | - TranslationTemplateItem.potemplateID == potemplate_id, |
295 | + TranslationTemplateItem.potmsgset_id, |
296 | + TranslationTemplateItem.potemplate_id == potemplate_id, |
297 | TranslationTemplateItem.sequence > 0, |
298 | ) |
299 | ) |
300 | diff --git a/lib/lp/translations/utilities/translationsplitter.py b/lib/lp/translations/utilities/translationsplitter.py |
301 | index 5dcb5cc..d4503b9 100644 |
302 | --- a/lib/lp/translations/utilities/translationsplitter.py |
303 | +++ b/lib/lp/translations/utilities/translationsplitter.py |
304 | @@ -103,13 +103,13 @@ class TranslationSplitter(TranslationSplitterBase): |
305 | UbuntuTemplate = ClassAlias(POTemplate, "UbuntuTemplate") |
306 | return store.find( |
307 | (UpstreamItem, UbuntuItem), |
308 | - UpstreamItem.potmsgsetID == UbuntuItem.potmsgsetID, |
309 | - UbuntuItem.potemplateID == UbuntuTemplate.id, |
310 | + UpstreamItem.potmsgset_id == UbuntuItem.potmsgset_id, |
311 | + UbuntuItem.potemplate_id == UbuntuTemplate.id, |
312 | UbuntuTemplate.sourcepackagenameID |
313 | == self.sourcepackage.sourcepackagename.id, |
314 | UbuntuTemplate.distroseriesID |
315 | == self.sourcepackage.distroseries.id, |
316 | - UpstreamItem.potemplateID == UpstreamTemplate.id, |
317 | + UpstreamItem.potemplate_id == UpstreamTemplate.id, |
318 | UpstreamTemplate.productseriesID == self.productseries.id, |
319 | ) |
320 | |
321 | @@ -151,7 +151,7 @@ class TranslationTemplateSplitter(TranslationSplitterBase): |
322 | OtherItem = ClassAlias(TranslationTemplateItem, "OtherItem") |
323 | return Store.of(self.potemplate).find( |
324 | (OtherItem, ThisItem), |
325 | - ThisItem.potemplateID == self.potemplate.id, |
326 | - OtherItem.potmsgsetID == ThisItem.potmsgsetID, |
327 | - Not(OtherItem.potemplateID.is_in(sharing_ids)), |
328 | + ThisItem.potemplate_id == self.potemplate.id, |
329 | + OtherItem.potmsgset_id == ThisItem.potmsgset_id, |
330 | + Not(OtherItem.potemplate_id.is_in(sharing_ids)), |
331 | ) |
LGTM!