~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/translations/model/translationpackagingjob.py

pocomment becomes the last member of the Condemned 36.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
__all__ = [
11
11
    'TranslationMergeJob',
12
12
    'TranslationSplitJob',
 
13
    'TranslationTemplateChangeJob',
13
14
    ]
14
15
 
15
16
import logging
17
18
from lazr.lifecycle.interfaces import (
18
19
    IObjectCreatedEvent,
19
20
    IObjectDeletedEvent,
 
21
    IObjectModifiedEvent,
20
22
    )
21
23
import transaction
22
24
from zope.interface import (
40
42
    TransactionManager,
41
43
    TranslationMerger,
42
44
    )
43
 
from lp.translations.utilities.translationsplitter import TranslationSplitter
 
45
from lp.translations.utilities.translationsplitter import (
 
46
    TranslationSplitter,
 
47
    TranslationTemplateSplitter,
 
48
    )
44
49
 
45
50
 
46
51
class TranslationPackagingJob(TranslationSharingJobDerived, BaseRunnableJob):
117
122
            'Splitting %s and %s', self.productseries.displayname,
118
123
            self.sourcepackage.displayname)
119
124
        TranslationSplitter(self.productseries, self.sourcepackage).split()
 
125
 
 
126
 
 
127
class TranslationTemplateChangeJob(TranslationPackagingJob):
 
128
    """Job for merging/splitting translations when template is changed."""
 
129
 
 
130
    implements(IRunnableJob)
 
131
 
 
132
    class_job_type = TranslationSharingJobType.TEMPLATE_CHANGE
 
133
 
 
134
    create_on_event = IObjectModifiedEvent
 
135
 
 
136
    @classmethod
 
137
    def forPOTemplate(cls, potemplate):
 
138
        """Create a TranslationTemplateChangeJob for a POTemplate.
 
139
 
 
140
        :param potemplate: The `POTemplate` to create the job for.
 
141
        :return: A `TranslationTemplateChangeJob`.
 
142
        """
 
143
        return cls.create(potemplate=potemplate)
 
144
 
 
145
    def run(self):
 
146
        """See `IRunnableJob`."""
 
147
        logger = logging.getLogger()
 
148
        logger.info("Sanitizing translations for '%s'" % (
 
149
                self.potemplate.displayname))
 
150
        TranslationTemplateSplitter(self.potemplate).split()
 
151
        tm = TransactionManager(transaction.manager, False)
 
152
        TranslationMerger.mergeModifiedTemplates(self.potemplate, tm)