~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/model/initializedistroseriesjob.py

[r=bac][bug=835024] New error_description property on
        InitializeDistroSeriesJob.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
    "InitializeDistroSeriesJob",
8
8
]
9
9
 
 
10
import simplejson
10
11
from zope.interface import (
11
12
    classProvides,
12
13
    implements,
31
32
    DistributionJobDerived,
32
33
    )
33
34
from lp.soyuz.model.packageset import Packageset
34
 
from lp.soyuz.scripts.initialize_distroseries import InitializeDistroSeries
 
35
from lp.soyuz.scripts.initialize_distroseries import (
 
36
    InitializationError,
 
37
    InitializeDistroSeries,
 
38
    )
35
39
 
36
40
 
37
41
class InitializeDistroSeriesJob(DistributionJobDerived):
41
45
    class_job_type = DistributionJobType.INITIALIZE_SERIES
42
46
    classProvides(IInitializeDistroSeriesJobSource)
43
47
 
 
48
    user_error_types = (InitializationError,)
 
49
 
44
50
    @classmethod
45
51
    def create(cls, child, parents, arches=(), packagesets=(),
46
52
               rebuild=False, overlays=(), overlay_pockets=(),
179
185
    def rebuild(self):
180
186
        return self.metadata['rebuild']
181
187
 
 
188
    @property
 
189
    def error_description(self):
 
190
        return self.metadata.get("error_description")
 
191
 
182
192
    def run(self):
183
193
        """See `IRunnableJob`."""
184
194
        ids = InitializeDistroSeries(
188
198
        ids.check()
189
199
        ids.initialize()
190
200
 
 
201
    def notifyUserError(self, error):
 
202
        """Calls up and slso saves the error text in this job's metadata.
 
203
 
 
204
        See `BaseRunnableJob`.
 
205
        """
 
206
        # This method is called when error is an instance of
 
207
        # self.user_error_types.
 
208
        super(InitializeDistroSeriesJob, self).notifyUserError(error)
 
209
        metadata = dict(self.metadata, error_description=unicode(error))
 
210
        self.context._json_data = simplejson.dumps(metadata).decode("utf-8")
 
211
 
191
212
    def getOopsVars(self):
192
213
        """See `IRunnableJob`."""
193
214
        vars = super(InitializeDistroSeriesJob, self).getOopsVars()