Merge lp:~danilo/launchpad/bug-814580-pre-cleanup into lp:launchpad

Proposed by Данило Шеган
Status: Merged
Approved by: Данило Шеган
Approved revision: no longer in the source branch.
Merged at revision: 13577
Proposed branch: lp:~danilo/launchpad/bug-814580-pre-cleanup
Merge into: lp:launchpad
Diff against target: 377 lines (+79/-73)
5 files modified
lib/lp/translations/configure.zcml (+1/-1)
lib/lp/translations/interfaces/translationsharingjob.py (+1/-1)
lib/lp/translations/model/translationpackagingjob.py (+10/-10)
lib/lp/translations/model/translationsharingjob.py (+48/-44)
lib/lp/translations/tests/test_translationpackagingjob.py (+19/-17)
To merge this branch: bzr merge lp:~danilo/launchpad/bug-814580-pre-cleanup
Reviewer Review Type Date Requested Status
Henning Eggers (community) Approve
Review via email: mp+69980@code.launchpad.net

Commit message

[r=henninge][bug=814580][incr] Rename PackagingJob to TranslationSharingJob to better reflect the purpose of the job and to prepare for introducing per-template sharing splitting/merging jobs.

Description of the change

= Bug 814580: pre-cleanup =

This renames the PackagingJob to TranslationSharingJob since we will be reusing it for more than just packaging actions.

I haven't fixed the lint issues since they are not introduced here, but I'll be happy to do that before landing.

== Tests ==

bin/test -cvvt translationpackaging

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/translations/interfaces/translationsharingjob.py
  lib/lp/translations/model/translationsharingjob.py
  lib/lp/translations/model/translationpackagingjob.py
  lib/lp/translations/tests/test_translationpackagingjob.py
  lib/lp/translations/configure.zcml

./lib/lp/translations/tests/test_translationpackagingjob.py
      62: local variable 'package' is assigned to but never used
     184: local variable 'recorder' is assigned to but never used
     195: local variable 'recorder' is assigned to but never used
     203: local variable 'other_packaging' is assigned to but never used
     217: local variable 'job' is assigned to but never used
     215: local variable 'recorder' is assigned to but never used
     224: local variable 'recorder' is assigned to but never used
     241: local variable 'recorder' is assigned to but never used
     245: local variable 'job2' is assigned to but never used

To post a comment you must log in.
Revision history for this message
Henning Eggers (henninge) wrote :

Great to see you are working on this! Thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/translations/configure.zcml'
2--- lib/lp/translations/configure.zcml 2011-05-04 04:10:58 +0000
3+++ lib/lp/translations/configure.zcml 2011-08-01 14:34:13 +0000
4@@ -153,7 +153,7 @@
5 <subscriber
6 for="lp.registry.interfaces.packaging.IPackaging
7 lazr.lifecycle.interfaces.IObjectEvent"
8- handler="lp.registry.model.packagingjob.schedule_job" />
9+ handler=".model.translationsharingjob.schedule_packaging_job" />
10 <facet
11 facet="translations">
12
13
14=== renamed file 'lib/lp/registry/interfaces/packagingjob.py' => 'lib/lp/translations/interfaces/translationsharingjob.py'
15--- lib/lp/registry/interfaces/packagingjob.py 2011-02-25 17:19:21 +0000
16+++ lib/lp/translations/interfaces/translationsharingjob.py 2011-08-01 14:34:13 +0000
17@@ -11,7 +11,7 @@
18 from lp.services.job.interfaces.job import IJob
19
20
21-class IPackagingJob(IJob):
22+class ITranslationSharingJob(IJob):
23
24 productseries = Attribute(_("The productseries of the Packaging."))
25
26
27=== modified file 'lib/lp/translations/model/translationpackagingjob.py'
28--- lib/lp/translations/model/translationpackagingjob.py 2011-07-18 20:46:27 +0000
29+++ lib/lp/translations/model/translationpackagingjob.py 2011-08-01 14:34:13 +0000
30@@ -31,10 +31,10 @@
31 from lp.translations.interfaces.translationpackagingjob import (
32 ITranslationPackagingJobSource,
33 )
34-from lp.registry.model.packagingjob import (
35- PackagingJob,
36- PackagingJobDerived,
37- PackagingJobType,
38+from lp.translations.model.translationsharingjob import (
39+ TranslationSharingJob,
40+ TranslationSharingJobDerived,
41+ TranslationSharingJobType,
42 )
43 from lp.translations.translationmerger import (
44 TransactionManager,
45@@ -43,7 +43,7 @@
46 from lp.translations.utilities.translationsplitter import TranslationSplitter
47
48
49-class TranslationPackagingJob(PackagingJobDerived, BaseRunnableJob):
50+class TranslationPackagingJob(TranslationSharingJobDerived, BaseRunnableJob):
51 """Iterate through all Translation job types."""
52
53 classProvides(ITranslationPackagingJobSource)
54@@ -52,7 +52,7 @@
55
56 @staticmethod
57 def _register_subclass(cls):
58- PackagingJobDerived._register_subclass(cls)
59+ TranslationSharingJobDerived._register_subclass(cls)
60 job_type = getattr(cls, 'class_job_type', None)
61 if job_type is not None:
62 cls._translation_packaging_job_types.append(job_type)
63@@ -71,7 +71,7 @@
64 @classmethod
65 def iterReady(cls):
66 """See `IJobSource`."""
67- clause = PackagingJob.job_type.is_in(
68+ clause = TranslationSharingJob.job_type.is_in(
69 cls._translation_packaging_job_types)
70 return super(TranslationPackagingJob, cls).iterReady([clause])
71
72@@ -81,7 +81,7 @@
73
74 implements(IRunnableJob)
75
76- class_job_type = PackagingJobType.TRANSLATION_MERGE
77+ class_job_type = TranslationSharingJobType.PACKAGING_MERGE
78
79 create_on_event = IObjectCreatedEvent
80
81@@ -102,11 +102,11 @@
82
83
84 class TranslationSplitJob(TranslationPackagingJob):
85- """Job for merging translations between a product and sourcepackage."""
86+ """Job for splitting translations between a product and sourcepackage."""
87
88 implements(IRunnableJob)
89
90- class_job_type = PackagingJobType.TRANSLATION_SPLIT
91+ class_job_type = TranslationSharingJobType.PACKAGING_SPLIT
92
93 create_on_event = IObjectDeletedEvent
94
95
96=== renamed file 'lib/lp/registry/model/packagingjob.py' => 'lib/lp/translations/model/translationsharingjob.py'
97--- lib/lp/registry/model/packagingjob.py 2011-07-18 20:46:27 +0000
98+++ lib/lp/translations/model/translationsharingjob.py 2011-08-01 14:34:13 +0000
99@@ -6,9 +6,9 @@
100 __metaclass__ = type
101
102 __all__ = [
103- 'PackagingJob',
104- 'PackagingJobType',
105- 'PackagingJobDerived',
106+ 'TranslationSharingJob',
107+ 'TranslationSharingJobType',
108+ 'TranslationSharingJobDerived',
109 ]
110
111 from lazr.delegates import delegates
112@@ -25,7 +25,6 @@
113 from canonical.launchpad.interfaces.lpstorm import (
114 IStore,
115 )
116-from lp.registry.interfaces.packagingjob import IPackagingJob
117 from lp.registry.model.distroseries import DistroSeries
118 from lp.registry.model.productseries import ProductSeries
119 from lp.registry.model.sourcepackagename import SourcePackageName
120@@ -35,25 +34,28 @@
121 JobStatus,
122 )
123 from lp.services.job.model.job import Job
124-
125-
126-class PackagingJobType(DBEnumeratedType):
127- """Types of Packaging Job."""
128-
129- TRANSLATION_MERGE = DBItem(0, """
130- Merge translations betweeen productseries and sourcepackage.
131-
132- Merge translations betweeen productseries and sourcepackage.
133- """)
134-
135- TRANSLATION_SPLIT = DBItem(1, """
136- Split translations between productseries and sourcepackage.
137-
138- Split translations between productseries and sourcepackage.
139- """)
140-
141-
142-class PackagingJob(StormBase):
143+from lp.translations.interfaces.translationsharingjob import (
144+ ITranslationSharingJob,
145+ )
146+
147+
148+class TranslationSharingJobType(DBEnumeratedType):
149+ """Types of translation sharing Job."""
150+
151+ PACKAGING_MERGE = DBItem(0, """
152+ Merge translations betweeen productseries and sourcepackage.
153+
154+ Merge translations betweeen productseries and sourcepackage.
155+ """)
156+
157+ PACKAGING_SPLIT = DBItem(1, """
158+ Split translations between productseries and sourcepackage.
159+
160+ Split translations between productseries and sourcepackage.
161+ """)
162+
163+
164+class TranslationSharingJob(StormBase):
165 """Base class for jobs related to a packaging."""
166
167 __storm_table__ = 'PackagingJob'
168@@ -66,7 +68,7 @@
169
170 delegates(IJob, 'job')
171
172- job_type = EnumCol(enum=PackagingJobType, notNull=True)
173+ job_type = EnumCol(enum=TranslationSharingJobType, notNull=True)
174
175 productseries_id = Int('productseries')
176
177@@ -103,12 +105,12 @@
178 cls._register_subclass(cls)
179
180
181-class PackagingJobDerived:
182- """Base class for specialized Packaging Job types."""
183+class TranslationSharingJobDerived:
184+ """Base class for specialized TranslationTemplate Job types."""
185
186 __metaclass__ = RegisteredSubclass
187
188- delegates(IPackagingJob, 'job')
189+ delegates(ITranslationSharingJob, 'job')
190
191 _subclass = {}
192 _event_types = {}
193@@ -136,26 +138,26 @@
194
195 def __init__(self, job):
196 assert job.job_type == self.class_job_type, (
197- "Attempting to create a %s using a %s PackagingJob" %
198+ "Attempting to create a %s using a %s TranslationSharingJob" %
199 (self.__class__.__name__, job.job_type))
200 self.job = job
201
202 @classmethod
203 def create(cls, productseries, distroseries, sourcepackagename):
204- """"Create a TranslationMergeJob backed by a PackageJob.
205+ """"Create a TranslationPackagingJob backed by TranslationSharingJob.
206
207 :param productseries: The ProductSeries side of the Packaging.
208 :param distroseries: The distroseries of the Packaging sourcepackage.
209 :param sourcepackagename: The name of the Packaging sourcepackage.
210 """
211- context = PackagingJob(
212+ context = TranslationSharingJob(
213 Job(), cls.class_job_type, productseries,
214 distroseries, sourcepackagename)
215 return cls(context)
216
217 @classmethod
218- def scheduleJob(cls, packaging, event):
219- """Event subscriber to create a PackagingJob on events.
220+ def schedulePackagingJob(cls, packaging, event):
221+ """Event subscriber to create a TranslationSharingJob on events.
222
223 :param packaging: The `Packaging` to create a `TranslationMergeJob`
224 for.
225@@ -171,13 +173,13 @@
226 def iterReady(cls, extra_clauses):
227 """See `IJobSource`.
228
229- This version will emit any ready job based on PackagingJob.
230+ This version will emit any ready job based on TranslationSharingJob.
231 :param extra_clauses: Extra clauses to reduce the selections.
232 """
233- store = IStore(PackagingJob)
234+ store = IStore(TranslationSharingJob)
235 jobs = store.find(
236- (PackagingJob),
237- PackagingJob.job == Job.id,
238+ (TranslationSharingJob),
239+ TranslationSharingJob.job == Job.id,
240 Job.id.is_in(Job.ready_jobs),
241 *extra_clauses)
242 return (cls._subclass[job.job_type](job) for job in jobs)
243@@ -185,16 +187,18 @@
244 @classmethod
245 def getNextJobStatus(cls, packaging):
246 """Return the status of the next job to run."""
247- store = IStore(PackagingJob)
248+ store = IStore(TranslationSharingJob)
249 result = store.find(
250- Job, Job.id == PackagingJob.job_id,
251- PackagingJob.distroseries_id == packaging.distroseries.id,
252- PackagingJob.sourcepackagename_id ==
253+ Job, Job.id == TranslationSharingJob.job_id,
254+ (TranslationSharingJob.distroseries_id ==
255+ packaging.distroseries.id),
256+ TranslationSharingJob.sourcepackagename_id ==
257 packaging.sourcepackagename.id,
258- PackagingJob.productseries_id == packaging.productseries.id,
259- PackagingJob.job_type == cls.class_job_type,
260+ (TranslationSharingJob.productseries_id ==
261+ packaging.productseries.id),
262+ TranslationSharingJob.job_type == cls.class_job_type,
263 Job._status.is_in([JobStatus.WAITING, JobStatus.RUNNING]))
264- result.order_by(PackagingJob.id)
265+ result.order_by(TranslationSharingJob.id)
266 job = result.first()
267 if job is None:
268 return None
269@@ -202,4 +206,4 @@
270
271
272 #make accessible to zcml
273-schedule_job = PackagingJobDerived.scheduleJob
274+schedule_packaging_job = TranslationSharingJobDerived.schedulePackagingJob
275
276=== modified file 'lib/lp/translations/tests/test_translationpackagingjob.py'
277--- lib/lp/translations/tests/test_translationpackagingjob.py 2011-04-11 16:00:53 +0000
278+++ lib/lp/translations/tests/test_translationpackagingjob.py 2011-08-01 14:34:13 +0000
279@@ -14,7 +14,10 @@
280 LaunchpadZopelessLayer,
281 )
282 from lp.registry.interfaces.packaging import IPackagingUtil
283-from lp.registry.model.packagingjob import PackagingJob, PackagingJobDerived
284+from lp.translations.model.translationsharingjob import (
285+ TranslationSharingJob,
286+ TranslationSharingJobDerived,
287+ )
288 from lp.services.job.interfaces.job import (
289 IRunnableJob,
290 JobStatus,
291@@ -56,7 +59,7 @@
292 potemplate=package_potemplate, language=upstream_pofile.language)
293 package_potmsgset = factory.makePOTMsgSet(
294 package_pofile.potemplate, singular)
295- package = factory.makeCurrentTranslationMessage(
296+ factory.makeCurrentTranslationMessage(
297 pofile=package_pofile, potmsgset=package_potmsgset,
298 translations=upstream.translations)
299 productseries = upstream_pofile.potemplate.productseries
300@@ -105,11 +108,12 @@
301 self.job_type = job_class.class_job_type
302
303 def find(self):
304- return list(PackagingJobDerived.iterReady([
305- PackagingJob.productseries_id == self.productseries.id,
306- PackagingJob.sourcepackagename_id == self.sourcepackagename.id,
307- PackagingJob.distroseries_id == self.distroseries.id,
308- PackagingJob.job_type == self.job_type,
309+ return list(TranslationSharingJobDerived.iterReady([
310+ TranslationSharingJob.productseries_id == self.productseries.id,
311+ (TranslationSharingJob.sourcepackagename_id ==
312+ self.sourcepackagename.id),
313+ TranslationSharingJob.distroseries_id == self.distroseries.id,
314+ TranslationSharingJob.job_type == self.job_type,
315 ]))
316
317
318@@ -177,7 +181,7 @@
319 def test_getNextJobStatus(self):
320 """Should find next packaging job."""
321 #suppress job creation.
322- with EventRecorder() as recorder:
323+ with EventRecorder():
324 packaging = self.factory.makePackagingLink()
325 self.assertIs(None, TranslationMergeJob.getNextJobStatus(packaging))
326 TranslationMergeJob.forPackaging(packaging)
327@@ -188,15 +192,13 @@
328 def test_getNextJobStatus_wrong_packaging(self):
329 """Jobs on wrong packaging should be ignored."""
330 #suppress job creation.
331- with EventRecorder() as recorder:
332+ with EventRecorder():
333 packaging = self.factory.makePackagingLink()
334 self.factory.makePackagingLink(
335 productseries=packaging.productseries)
336 self.assertIs(None, TranslationMergeJob.getNextJobStatus(packaging))
337 self.factory.makePackagingLink()
338- other_packaging = self.factory.makePackagingLink(
339- distroseries=packaging.distroseries)
340- other_packaging = self.factory.makePackagingLink(
341+ self.factory.makePackagingLink(
342 distroseries=packaging.distroseries)
343 self.assertIs(None, TranslationMergeJob.getNextJobStatus(packaging))
344 TranslationMergeJob.create(
345@@ -208,16 +210,16 @@
346 def test_getNextJobStatus_wrong_type(self):
347 """Only TranslationMergeJobs should result."""
348 #suppress job creation.
349- with EventRecorder() as recorder:
350+ with EventRecorder():
351 packaging = self.factory.makePackagingLink()
352- job = TranslationSplitJob.forPackaging(packaging)
353+ TranslationSplitJob.forPackaging(packaging)
354 self.assertIs(
355 None, TranslationMergeJob.getNextJobStatus(packaging))
356
357 def test_getNextJobStatus_status(self):
358 """Only RUNNING and WAITING jobs should influence status."""
359 #suppress job creation.
360- with EventRecorder() as recorder:
361+ with EventRecorder():
362 packaging = self.factory.makePackagingLink()
363 job = TranslationMergeJob.forPackaging(packaging)
364 job.start()
365@@ -234,11 +236,11 @@
366
367 def test_getNextJobStatus_order(self):
368 """Status should order by id."""
369- with EventRecorder() as recorder:
370+ with EventRecorder():
371 packaging = self.factory.makePackagingLink()
372 job = TranslationMergeJob.forPackaging(packaging)
373 job.start()
374- job2 = TranslationMergeJob.forPackaging(packaging)
375+ TranslationMergeJob.forPackaging(packaging)
376 self.assertEqual(JobStatus.RUNNING,
377 TranslationMergeJob.getNextJobStatus(packaging))
378