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
=== modified file 'lib/lp/translations/configure.zcml'
--- lib/lp/translations/configure.zcml 2011-05-04 04:10:58 +0000
+++ lib/lp/translations/configure.zcml 2011-08-01 14:34:13 +0000
@@ -153,7 +153,7 @@
153 <subscriber153 <subscriber
154 for="lp.registry.interfaces.packaging.IPackaging154 for="lp.registry.interfaces.packaging.IPackaging
155 lazr.lifecycle.interfaces.IObjectEvent"155 lazr.lifecycle.interfaces.IObjectEvent"
156 handler="lp.registry.model.packagingjob.schedule_job" />156 handler=".model.translationsharingjob.schedule_packaging_job" />
157 <facet157 <facet
158 facet="translations">158 facet="translations">
159159
160160
=== renamed file 'lib/lp/registry/interfaces/packagingjob.py' => 'lib/lp/translations/interfaces/translationsharingjob.py'
--- lib/lp/registry/interfaces/packagingjob.py 2011-02-25 17:19:21 +0000
+++ lib/lp/translations/interfaces/translationsharingjob.py 2011-08-01 14:34:13 +0000
@@ -11,7 +11,7 @@
11from lp.services.job.interfaces.job import IJob11from lp.services.job.interfaces.job import IJob
1212
1313
14class IPackagingJob(IJob):14class ITranslationSharingJob(IJob):
1515
16 productseries = Attribute(_("The productseries of the Packaging."))16 productseries = Attribute(_("The productseries of the Packaging."))
1717
1818
=== modified file 'lib/lp/translations/model/translationpackagingjob.py'
--- lib/lp/translations/model/translationpackagingjob.py 2011-07-18 20:46:27 +0000
+++ lib/lp/translations/model/translationpackagingjob.py 2011-08-01 14:34:13 +0000
@@ -31,10 +31,10 @@
31from lp.translations.interfaces.translationpackagingjob import (31from lp.translations.interfaces.translationpackagingjob import (
32 ITranslationPackagingJobSource,32 ITranslationPackagingJobSource,
33 )33 )
34from lp.registry.model.packagingjob import (34from lp.translations.model.translationsharingjob import (
35 PackagingJob,35 TranslationSharingJob,
36 PackagingJobDerived,36 TranslationSharingJobDerived,
37 PackagingJobType,37 TranslationSharingJobType,
38 )38 )
39from lp.translations.translationmerger import (39from lp.translations.translationmerger import (
40 TransactionManager,40 TransactionManager,
@@ -43,7 +43,7 @@
43from lp.translations.utilities.translationsplitter import TranslationSplitter43from lp.translations.utilities.translationsplitter import TranslationSplitter
4444
4545
46class TranslationPackagingJob(PackagingJobDerived, BaseRunnableJob):46class TranslationPackagingJob(TranslationSharingJobDerived, BaseRunnableJob):
47 """Iterate through all Translation job types."""47 """Iterate through all Translation job types."""
4848
49 classProvides(ITranslationPackagingJobSource)49 classProvides(ITranslationPackagingJobSource)
@@ -52,7 +52,7 @@
5252
53 @staticmethod53 @staticmethod
54 def _register_subclass(cls):54 def _register_subclass(cls):
55 PackagingJobDerived._register_subclass(cls)55 TranslationSharingJobDerived._register_subclass(cls)
56 job_type = getattr(cls, 'class_job_type', None)56 job_type = getattr(cls, 'class_job_type', None)
57 if job_type is not None:57 if job_type is not None:
58 cls._translation_packaging_job_types.append(job_type)58 cls._translation_packaging_job_types.append(job_type)
@@ -71,7 +71,7 @@
71 @classmethod71 @classmethod
72 def iterReady(cls):72 def iterReady(cls):
73 """See `IJobSource`."""73 """See `IJobSource`."""
74 clause = PackagingJob.job_type.is_in(74 clause = TranslationSharingJob.job_type.is_in(
75 cls._translation_packaging_job_types)75 cls._translation_packaging_job_types)
76 return super(TranslationPackagingJob, cls).iterReady([clause])76 return super(TranslationPackagingJob, cls).iterReady([clause])
7777
@@ -81,7 +81,7 @@
8181
82 implements(IRunnableJob)82 implements(IRunnableJob)
8383
84 class_job_type = PackagingJobType.TRANSLATION_MERGE84 class_job_type = TranslationSharingJobType.PACKAGING_MERGE
8585
86 create_on_event = IObjectCreatedEvent86 create_on_event = IObjectCreatedEvent
8787
@@ -102,11 +102,11 @@
102102
103103
104class TranslationSplitJob(TranslationPackagingJob):104class TranslationSplitJob(TranslationPackagingJob):
105 """Job for merging translations between a product and sourcepackage."""105 """Job for splitting translations between a product and sourcepackage."""
106106
107 implements(IRunnableJob)107 implements(IRunnableJob)
108108
109 class_job_type = PackagingJobType.TRANSLATION_SPLIT109 class_job_type = TranslationSharingJobType.PACKAGING_SPLIT
110110
111 create_on_event = IObjectDeletedEvent111 create_on_event = IObjectDeletedEvent
112112
113113
=== renamed file 'lib/lp/registry/model/packagingjob.py' => 'lib/lp/translations/model/translationsharingjob.py'
--- lib/lp/registry/model/packagingjob.py 2011-07-18 20:46:27 +0000
+++ lib/lp/translations/model/translationsharingjob.py 2011-08-01 14:34:13 +0000
@@ -6,9 +6,9 @@
6__metaclass__ = type6__metaclass__ = type
77
8__all__ = [8__all__ = [
9 'PackagingJob',9 'TranslationSharingJob',
10 'PackagingJobType',10 'TranslationSharingJobType',
11 'PackagingJobDerived',11 'TranslationSharingJobDerived',
12 ]12 ]
1313
14from lazr.delegates import delegates14from lazr.delegates import delegates
@@ -25,7 +25,6 @@
25from canonical.launchpad.interfaces.lpstorm import (25from canonical.launchpad.interfaces.lpstorm import (
26 IStore,26 IStore,
27 )27 )
28from lp.registry.interfaces.packagingjob import IPackagingJob
29from lp.registry.model.distroseries import DistroSeries28from lp.registry.model.distroseries import DistroSeries
30from lp.registry.model.productseries import ProductSeries29from lp.registry.model.productseries import ProductSeries
31from lp.registry.model.sourcepackagename import SourcePackageName30from lp.registry.model.sourcepackagename import SourcePackageName
@@ -35,25 +34,28 @@
35 JobStatus,34 JobStatus,
36 )35 )
37from lp.services.job.model.job import Job36from lp.services.job.model.job import Job
3837from lp.translations.interfaces.translationsharingjob import (
3938 ITranslationSharingJob,
40class PackagingJobType(DBEnumeratedType):39 )
41 """Types of Packaging Job."""40
4241
43 TRANSLATION_MERGE = DBItem(0, """42class TranslationSharingJobType(DBEnumeratedType):
44 Merge translations betweeen productseries and sourcepackage.43 """Types of translation sharing Job."""
4544
46 Merge translations betweeen productseries and sourcepackage.45 PACKAGING_MERGE = DBItem(0, """
47 """)46 Merge translations betweeen productseries and sourcepackage.
4847
49 TRANSLATION_SPLIT = DBItem(1, """48 Merge translations betweeen productseries and sourcepackage.
50 Split translations between productseries and sourcepackage.49 """)
5150
52 Split translations between productseries and sourcepackage.51 PACKAGING_SPLIT = DBItem(1, """
53 """)52 Split translations between productseries and sourcepackage.
5453
5554 Split translations between productseries and sourcepackage.
56class PackagingJob(StormBase):55 """)
56
57
58class TranslationSharingJob(StormBase):
57 """Base class for jobs related to a packaging."""59 """Base class for jobs related to a packaging."""
5860
59 __storm_table__ = 'PackagingJob'61 __storm_table__ = 'PackagingJob'
@@ -66,7 +68,7 @@
6668
67 delegates(IJob, 'job')69 delegates(IJob, 'job')
6870
69 job_type = EnumCol(enum=PackagingJobType, notNull=True)71 job_type = EnumCol(enum=TranslationSharingJobType, notNull=True)
7072
71 productseries_id = Int('productseries')73 productseries_id = Int('productseries')
7274
@@ -103,12 +105,12 @@
103 cls._register_subclass(cls)105 cls._register_subclass(cls)
104106
105107
106class PackagingJobDerived:108class TranslationSharingJobDerived:
107 """Base class for specialized Packaging Job types."""109 """Base class for specialized TranslationTemplate Job types."""
108110
109 __metaclass__ = RegisteredSubclass111 __metaclass__ = RegisteredSubclass
110112
111 delegates(IPackagingJob, 'job')113 delegates(ITranslationSharingJob, 'job')
112114
113 _subclass = {}115 _subclass = {}
114 _event_types = {}116 _event_types = {}
@@ -136,26 +138,26 @@
136138
137 def __init__(self, job):139 def __init__(self, job):
138 assert job.job_type == self.class_job_type, (140 assert job.job_type == self.class_job_type, (
139 "Attempting to create a %s using a %s PackagingJob" %141 "Attempting to create a %s using a %s TranslationSharingJob" %
140 (self.__class__.__name__, job.job_type))142 (self.__class__.__name__, job.job_type))
141 self.job = job143 self.job = job
142144
143 @classmethod145 @classmethod
144 def create(cls, productseries, distroseries, sourcepackagename):146 def create(cls, productseries, distroseries, sourcepackagename):
145 """"Create a TranslationMergeJob backed by a PackageJob.147 """"Create a TranslationPackagingJob backed by TranslationSharingJob.
146148
147 :param productseries: The ProductSeries side of the Packaging.149 :param productseries: The ProductSeries side of the Packaging.
148 :param distroseries: The distroseries of the Packaging sourcepackage.150 :param distroseries: The distroseries of the Packaging sourcepackage.
149 :param sourcepackagename: The name of the Packaging sourcepackage.151 :param sourcepackagename: The name of the Packaging sourcepackage.
150 """152 """
151 context = PackagingJob(153 context = TranslationSharingJob(
152 Job(), cls.class_job_type, productseries,154 Job(), cls.class_job_type, productseries,
153 distroseries, sourcepackagename)155 distroseries, sourcepackagename)
154 return cls(context)156 return cls(context)
155157
156 @classmethod158 @classmethod
157 def scheduleJob(cls, packaging, event):159 def schedulePackagingJob(cls, packaging, event):
158 """Event subscriber to create a PackagingJob on events.160 """Event subscriber to create a TranslationSharingJob on events.
159161
160 :param packaging: The `Packaging` to create a `TranslationMergeJob`162 :param packaging: The `Packaging` to create a `TranslationMergeJob`
161 for.163 for.
@@ -171,13 +173,13 @@
171 def iterReady(cls, extra_clauses):173 def iterReady(cls, extra_clauses):
172 """See `IJobSource`.174 """See `IJobSource`.
173175
174 This version will emit any ready job based on PackagingJob.176 This version will emit any ready job based on TranslationSharingJob.
175 :param extra_clauses: Extra clauses to reduce the selections.177 :param extra_clauses: Extra clauses to reduce the selections.
176 """178 """
177 store = IStore(PackagingJob)179 store = IStore(TranslationSharingJob)
178 jobs = store.find(180 jobs = store.find(
179 (PackagingJob),181 (TranslationSharingJob),
180 PackagingJob.job == Job.id,182 TranslationSharingJob.job == Job.id,
181 Job.id.is_in(Job.ready_jobs),183 Job.id.is_in(Job.ready_jobs),
182 *extra_clauses)184 *extra_clauses)
183 return (cls._subclass[job.job_type](job) for job in jobs)185 return (cls._subclass[job.job_type](job) for job in jobs)
@@ -185,16 +187,18 @@
185 @classmethod187 @classmethod
186 def getNextJobStatus(cls, packaging):188 def getNextJobStatus(cls, packaging):
187 """Return the status of the next job to run."""189 """Return the status of the next job to run."""
188 store = IStore(PackagingJob)190 store = IStore(TranslationSharingJob)
189 result = store.find(191 result = store.find(
190 Job, Job.id == PackagingJob.job_id,192 Job, Job.id == TranslationSharingJob.job_id,
191 PackagingJob.distroseries_id == packaging.distroseries.id,193 (TranslationSharingJob.distroseries_id ==
192 PackagingJob.sourcepackagename_id ==194 packaging.distroseries.id),
195 TranslationSharingJob.sourcepackagename_id ==
193 packaging.sourcepackagename.id,196 packaging.sourcepackagename.id,
194 PackagingJob.productseries_id == packaging.productseries.id,197 (TranslationSharingJob.productseries_id ==
195 PackagingJob.job_type == cls.class_job_type,198 packaging.productseries.id),
199 TranslationSharingJob.job_type == cls.class_job_type,
196 Job._status.is_in([JobStatus.WAITING, JobStatus.RUNNING]))200 Job._status.is_in([JobStatus.WAITING, JobStatus.RUNNING]))
197 result.order_by(PackagingJob.id)201 result.order_by(TranslationSharingJob.id)
198 job = result.first()202 job = result.first()
199 if job is None:203 if job is None:
200 return None204 return None
@@ -202,4 +206,4 @@
202206
203207
204#make accessible to zcml208#make accessible to zcml
205schedule_job = PackagingJobDerived.scheduleJob209schedule_packaging_job = TranslationSharingJobDerived.schedulePackagingJob
206210
=== modified file 'lib/lp/translations/tests/test_translationpackagingjob.py'
--- lib/lp/translations/tests/test_translationpackagingjob.py 2011-04-11 16:00:53 +0000
+++ lib/lp/translations/tests/test_translationpackagingjob.py 2011-08-01 14:34:13 +0000
@@ -14,7 +14,10 @@
14 LaunchpadZopelessLayer,14 LaunchpadZopelessLayer,
15 )15 )
16from lp.registry.interfaces.packaging import IPackagingUtil16from lp.registry.interfaces.packaging import IPackagingUtil
17from lp.registry.model.packagingjob import PackagingJob, PackagingJobDerived17from lp.translations.model.translationsharingjob import (
18 TranslationSharingJob,
19 TranslationSharingJobDerived,
20 )
18from lp.services.job.interfaces.job import (21from lp.services.job.interfaces.job import (
19 IRunnableJob,22 IRunnableJob,
20 JobStatus,23 JobStatus,
@@ -56,7 +59,7 @@
56 potemplate=package_potemplate, language=upstream_pofile.language)59 potemplate=package_potemplate, language=upstream_pofile.language)
57 package_potmsgset = factory.makePOTMsgSet(60 package_potmsgset = factory.makePOTMsgSet(
58 package_pofile.potemplate, singular)61 package_pofile.potemplate, singular)
59 package = factory.makeCurrentTranslationMessage(62 factory.makeCurrentTranslationMessage(
60 pofile=package_pofile, potmsgset=package_potmsgset,63 pofile=package_pofile, potmsgset=package_potmsgset,
61 translations=upstream.translations)64 translations=upstream.translations)
62 productseries = upstream_pofile.potemplate.productseries65 productseries = upstream_pofile.potemplate.productseries
@@ -105,11 +108,12 @@
105 self.job_type = job_class.class_job_type108 self.job_type = job_class.class_job_type
106109
107 def find(self):110 def find(self):
108 return list(PackagingJobDerived.iterReady([111 return list(TranslationSharingJobDerived.iterReady([
109 PackagingJob.productseries_id == self.productseries.id,112 TranslationSharingJob.productseries_id == self.productseries.id,
110 PackagingJob.sourcepackagename_id == self.sourcepackagename.id,113 (TranslationSharingJob.sourcepackagename_id ==
111 PackagingJob.distroseries_id == self.distroseries.id,114 self.sourcepackagename.id),
112 PackagingJob.job_type == self.job_type,115 TranslationSharingJob.distroseries_id == self.distroseries.id,
116 TranslationSharingJob.job_type == self.job_type,
113 ]))117 ]))
114118
115119
@@ -177,7 +181,7 @@
177 def test_getNextJobStatus(self):181 def test_getNextJobStatus(self):
178 """Should find next packaging job."""182 """Should find next packaging job."""
179 #suppress job creation.183 #suppress job creation.
180 with EventRecorder() as recorder:184 with EventRecorder():
181 packaging = self.factory.makePackagingLink()185 packaging = self.factory.makePackagingLink()
182 self.assertIs(None, TranslationMergeJob.getNextJobStatus(packaging))186 self.assertIs(None, TranslationMergeJob.getNextJobStatus(packaging))
183 TranslationMergeJob.forPackaging(packaging)187 TranslationMergeJob.forPackaging(packaging)
@@ -188,15 +192,13 @@
188 def test_getNextJobStatus_wrong_packaging(self):192 def test_getNextJobStatus_wrong_packaging(self):
189 """Jobs on wrong packaging should be ignored."""193 """Jobs on wrong packaging should be ignored."""
190 #suppress job creation.194 #suppress job creation.
191 with EventRecorder() as recorder:195 with EventRecorder():
192 packaging = self.factory.makePackagingLink()196 packaging = self.factory.makePackagingLink()
193 self.factory.makePackagingLink(197 self.factory.makePackagingLink(
194 productseries=packaging.productseries)198 productseries=packaging.productseries)
195 self.assertIs(None, TranslationMergeJob.getNextJobStatus(packaging))199 self.assertIs(None, TranslationMergeJob.getNextJobStatus(packaging))
196 self.factory.makePackagingLink()200 self.factory.makePackagingLink()
197 other_packaging = self.factory.makePackagingLink(201 self.factory.makePackagingLink(
198 distroseries=packaging.distroseries)
199 other_packaging = self.factory.makePackagingLink(
200 distroseries=packaging.distroseries)202 distroseries=packaging.distroseries)
201 self.assertIs(None, TranslationMergeJob.getNextJobStatus(packaging))203 self.assertIs(None, TranslationMergeJob.getNextJobStatus(packaging))
202 TranslationMergeJob.create(204 TranslationMergeJob.create(
@@ -208,16 +210,16 @@
208 def test_getNextJobStatus_wrong_type(self):210 def test_getNextJobStatus_wrong_type(self):
209 """Only TranslationMergeJobs should result."""211 """Only TranslationMergeJobs should result."""
210 #suppress job creation.212 #suppress job creation.
211 with EventRecorder() as recorder:213 with EventRecorder():
212 packaging = self.factory.makePackagingLink()214 packaging = self.factory.makePackagingLink()
213 job = TranslationSplitJob.forPackaging(packaging)215 TranslationSplitJob.forPackaging(packaging)
214 self.assertIs(216 self.assertIs(
215 None, TranslationMergeJob.getNextJobStatus(packaging))217 None, TranslationMergeJob.getNextJobStatus(packaging))
216218
217 def test_getNextJobStatus_status(self):219 def test_getNextJobStatus_status(self):
218 """Only RUNNING and WAITING jobs should influence status."""220 """Only RUNNING and WAITING jobs should influence status."""
219 #suppress job creation.221 #suppress job creation.
220 with EventRecorder() as recorder:222 with EventRecorder():
221 packaging = self.factory.makePackagingLink()223 packaging = self.factory.makePackagingLink()
222 job = TranslationMergeJob.forPackaging(packaging)224 job = TranslationMergeJob.forPackaging(packaging)
223 job.start()225 job.start()
@@ -234,11 +236,11 @@
234236
235 def test_getNextJobStatus_order(self):237 def test_getNextJobStatus_order(self):
236 """Status should order by id."""238 """Status should order by id."""
237 with EventRecorder() as recorder:239 with EventRecorder():
238 packaging = self.factory.makePackagingLink()240 packaging = self.factory.makePackagingLink()
239 job = TranslationMergeJob.forPackaging(packaging)241 job = TranslationMergeJob.forPackaging(packaging)
240 job.start()242 job.start()
241 job2 = TranslationMergeJob.forPackaging(packaging)243 TranslationMergeJob.forPackaging(packaging)
242 self.assertEqual(JobStatus.RUNNING,244 self.assertEqual(JobStatus.RUNNING,
243 TranslationMergeJob.getNextJobStatus(packaging))245 TranslationMergeJob.getNextJobStatus(packaging))
244246