~launchpad-pqm/launchpad/devel

7628.1.2 by Aaron Bentley
Merge proposal diff generation work-in-progress
1
#!/usr/bin/python2.4
8687.15.7 by Karl Fogel
Add the copyright header block to more files.
2
#
3
# Copyright 2009 Canonical Ltd.  This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
5
7628.1.2 by Aaron Bentley
Merge proposal diff generation work-in-progress
6
# pylint: disable-msg=W0403
7
7628.1.6 by Aaron Bentley
Rename ReviewDiffJob to MergeProposalCreatedJob
8
"""Handle new BranchMergeProposals.
7628.1.2 by Aaron Bentley
Merge proposal diff generation work-in-progress
9
7628.1.6 by Aaron Bentley
Rename ReviewDiffJob to MergeProposalCreatedJob
10
This script generates a diff for the merge proposal if needed, then notifies
11
all interested parties about the merge proposal.
7628.1.2 by Aaron Bentley
Merge proposal diff generation work-in-progress
12
"""
13
14
__metaclass__ = type
15
16
import _pythonpath
17
from zope.component import getUtility
18
19
from canonical.config import config
8426.6.1 by Michael Hudson
bzr ls --versioned --recursive --kind=file | xargs sed -i -e 's,from canonical.codehosting,from lp.codehosting,'
20
from lp.codehosting.vfs import get_scanner_server
8356.1.19 by Leonard Richardson
Moved the job runner into lp.services.job.
21
from lp.services.job.runner import JobRunner
8138.1.2 by Jonathan Lange
Run migrater over lp.code. Many tests broken and imports failing.
22
from lp.code.interfaces.branchmergeproposal import (
7628.1.6 by Aaron Bentley
Rename ReviewDiffJob to MergeProposalCreatedJob
23
    IMergeProposalCreatedJobSource,)
8356.1.1 by Leonard Richardson
Partial move.
24
from lp.services.scripts.base import LaunchpadCronScript
7628.1.2 by Aaron Bentley
Merge proposal diff generation work-in-progress
25
from canonical.launchpad.webapp.errorlog import globalErrorUtility
26
27
7628.1.6 by Aaron Bentley
Rename ReviewDiffJob to MergeProposalCreatedJob
28
class RunMergeProposalCreatedJobs(LaunchpadCronScript):
29
    """Run merge proposal creation jobs."""
7628.1.2 by Aaron Bentley
Merge proposal diff generation work-in-progress
30
31
    def main(self):
7628.1.11 by Aaron Bentley
Various cleanups
32
        globalErrorUtility.configure('mpcreationjobs')
7628.1.6 by Aaron Bentley
Rename ReviewDiffJob to MergeProposalCreatedJob
33
        job_source = getUtility(IMergeProposalCreatedJobSource)
34
        runner = JobRunner.fromReady(job_source)
7628.1.2 by Aaron Bentley
Merge proposal diff generation work-in-progress
35
        server = get_scanner_server()
36
        server.setUp()
37
        try:
38
            runner.runAll()
39
        finally:
40
            server.tearDown()
7675.10.1 by Tim Penhey
LOSA requested logger finished time.
41
        self.logger.info(
42
            'Ran %d MergeProposalCreatedJobs.', len(runner.completed_jobs))
7628.1.2 by Aaron Bentley
Merge proposal diff generation work-in-progress
43
44
45
if __name__ == '__main__':
7628.1.6 by Aaron Bentley
Rename ReviewDiffJob to MergeProposalCreatedJob
46
    script = RunMergeProposalCreatedJobs(
7675.12.1 by Tim Penhey
Create explicit db users for every script.
47
        'mpcreationjobs', config.mpcreationjobs.dbuser)
7628.1.2 by Aaron Bentley
Merge proposal diff generation work-in-progress
48
    script.lock_and_run()