1
# Copyright 2011 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Job for merging translations."""
15
from zope.component import getUtility
17
from storm.locals import (
22
from zope.interface import (
27
from canonical.launchpad.webapp.interfaces import (
32
from lp.services.database.stormbase import StormBase
33
from lp.services.job.interfaces.job import IRunnableJob
34
from lp.services.job.model.job import Job
35
from lp.services.job.runner import BaseRunnableJob
36
from lp.translations.interfaces.pofilestatsjob import IPOFileStatsJobSource
37
from lp.translations.model.pofile import POFile
40
class POFileStatsJob(StormBase, BaseRunnableJob):
41
"""The details for a POFile status update job."""
43
__storm_table__ = 'POFileStatsJob'
45
# Instances of this class are runnable jobs.
46
implements(IRunnableJob)
48
# Oddly, BaseRunnableJob inherits from BaseRunnableJobSource so this class
49
# is both the factory for jobs (the "implements", above) and the source
50
# for runnable jobs (not the constructor of the job source, the class
51
# provides the IJobSource interface itself).
52
classProvides(IPOFileStatsJobSource)
54
# The Job table contains core job details.
55
job_id = Int('job', primary=True)
56
job = Reference(job_id, Job.id)
58
# This is the POFile which needs its statistics updated.
59
pofile_id = Int('pofile')
60
pofile = Reference(pofile_id, POFile.id)
62
def __init__(self, pofile):
65
super(POFileStatsJob, self).__init__()
67
def getOperationDescription(self):
68
"""See `IRunnableJob`."""
69
return 'updating POFile statistics'
72
"""See `IRunnableJob`."""
73
logger = logging.getLogger()
74
logger.info('Updating statistics for %s' % self.pofile.title)
75
self.pofile.updateStatistics()
79
"""See `IJobSource`."""
80
store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR)
81
return store.find((POFileStatsJob),
82
And(POFileStatsJob.job == Job.id,
83
Job.id.is_in(Job.ready_jobs)))
87
"""Schedule a job to update a POFile's stats."""
88
return POFileStatsJob(pofile)