~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/code/model/branchmergeproposaljob.py

Fix lint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2009, 2010 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
 
61
61
 
62
62
from canonical.config import config
63
63
from canonical.database.enumcol import EnumCol
 
64
from lp.services.messages.model.message import (
 
65
    MessageJob,
 
66
    MessageJobAction,
 
67
    )
 
68
from lp.services.messages.interfaces.message import IMessageJob
64
69
from canonical.launchpad.webapp import errorlog
65
70
from canonical.launchpad.webapp.interaction import setupInteraction
66
71
from canonical.launchpad.webapp.interfaces import (
70
75
    MAIN_STORE,
71
76
    MASTER_FLAVOR,
72
77
    )
73
 
from lp.code.adapters.branch import BranchMergeProposalDelta
74
78
from lp.code.enums import BranchType
75
 
from lp.code.errors import (
76
 
    BranchHasPendingWrites,
77
 
    UpdatePreviewDiffNotReady,
78
 
    )
79
79
from lp.code.interfaces.branchmergeproposal import (
80
80
    IBranchMergeProposalJob,
81
81
    IBranchMergeProposalJobSource,
105
105
    get_rw_server,
106
106
    )
107
107
from lp.registry.interfaces.person import IPersonSet
108
 
from lp.services.database.stormbase import StormBase
109
108
from lp.services.job.interfaces.job import JobStatus
110
109
from lp.services.job.model.job import Job
111
110
from lp.services.job.runner import (
113
112
    BaseRunnableJobSource,
114
113
    )
115
114
from lp.services.mail.sendmail import format_address_for_person
116
 
from lp.services.messages.interfaces.message import IMessageJob
117
 
from lp.services.messages.model.message import (
118
 
    MessageJob,
119
 
    MessageJobAction,
120
 
    )
 
115
from lp.services.database.stormbase import StormBase
121
116
 
122
117
 
123
118
class BranchMergeProposalJobType(DBEnumeratedType):
332
327
             self.branch_merge_proposal.target_branch.bzr_identity))
333
328
 
334
329
 
 
330
class UpdatePreviewDiffNotReady(Exception):
 
331
    """Raised if the the preview diff is not ready to run."""
 
332
 
 
333
 
335
334
class UpdatePreviewDiffJob(BranchMergeProposalJobDerived):
336
335
    """A job to update the preview diff for a branch merge proposal.
337
336
 
346
345
 
347
346
    user_error_types = (UpdatePreviewDiffNotReady, )
348
347
 
349
 
    retry_error_types = (BranchHasPendingWrites, )
350
 
 
351
 
    max_retries = 20
352
 
 
353
348
    def checkReady(self):
354
349
        """Is this job ready to run?"""
355
350
        bmp = self.branch_merge_proposal
360
355
            raise UpdatePreviewDiffNotReady(
361
356
                'The target branch has no revisions.')
362
357
        if bmp.source_branch.pending_writes:
363
 
            raise BranchHasPendingWrites(
 
358
            raise UpdatePreviewDiffNotReady(
364
359
                'The source branch has pending writes.')
365
360
 
366
361
    @staticmethod
381
376
        self.checkReady()
382
377
        preview = PreviewDiff.fromBranchMergeProposal(
383
378
            self.branch_merge_proposal)
384
 
        with BranchMergeProposalDelta.monitor(
385
 
            self.branch_merge_proposal):
386
 
            self.branch_merge_proposal.preview_diff = preview
 
379
        self.branch_merge_proposal.preview_diff = preview
387
380
 
388
381
    def getOperationDescription(self):
389
382
        return ('generating the diff for a merge proposal')
818
811
            if IUpdatePreviewDiffJob.providedBy(derived_job):
819
812
                try:
820
813
                    derived_job.checkReady()
821
 
                except (UpdatePreviewDiffNotReady, BranchHasPendingWrites):
 
814
                except UpdatePreviewDiffNotReady:
822
815
                    # If the job was created under 15 minutes ago wait a bit.
823
816
                    minutes = (
824
817
                        config.codehosting.update_preview_diff_ready_timeout)