~launchpad-pqm/launchpad/devel

10637.3.1 by Guilherme Salgado
Use the default python version instead of a hard-coded version
1
#!/usr/bin/python -S
8687.15.22 by Karl Fogel
Add the copyright header block to the remaining .py 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).
6092.1.4 by Michael Hudson
tests pass, remarkably enough
5
6092.1.7 by Michael Hudson
mostly lint
6
"""When passed a CodeImportJob id on the command line, process that job.
7
8
The actual work of processing a job is done by the code-import-worker.py
9
script which this process runs as a child process and updates the database on
10
its progress and result.
11
12
This script is usually run by the code-import-dispatcher cronscript.
13
"""
6092.1.4 by Michael Hudson
tests pass, remarkably enough
14
15
__metaclass__ = type
16
17
18
# pylint: disable-msg=W0403
19
import _pythonpath
20
6233.3.2 by Michael Hudson
changes to the config from trying things out on staging
21
import os
22
14612.2.7 by William Grant
scripts
23
from twisted.internet import (
24
    defer,
25
    reactor,
26
    )
6092.1.4 by Michael Hudson
tests pass, remarkably enough
27
from twisted.python import log
8447.4.18 by Michael Hudson
all tests pass, i think
28
from twisted.web import xmlrpc
29
14612.2.7 by William Grant
scripts
30
from lp.codehosting.codeimport.workermonitor import CodeImportWorkerMonitor
14605.1.1 by Curtis Hovey
Moved canonical.config to lp.services.
31
from lp.services.config import config
8356.1.9 by Leonard Richardson
Renamed the base script module in scripts/, which module_rename.py didn't touch because it wasn't under lib/.
32
from lp.services.scripts.base import LaunchpadScript
10548.1.1 by Jonathan Lange
Move twistedsupport to lp.services
33
from lp.services.twistedsupport.loggingsupport import set_up_oops_reporting
6092.1.5 by Michael Hudson
oops reporting and logging in codeimportworker
34
35
36
class CodeImportWorker(LaunchpadScript):
37
38
    def __init__(self, name, dbuser=None, test_args=None):
39
        LaunchpadScript.__init__(self, name, dbuser, test_args)
14446.1.8 by Julian Edwards
fix some logging; TestBranchPuller still failing
40
        # The logfile changes its name according to the code in
41
        # CodeImportDispatcher, so we pull it from the command line
42
        # options.
43
        set_up_oops_reporting(
44
            self.name, 'codeimportworker', logfile=self.options.log_file)
6092.1.4 by Michael Hudson
tests pass, remarkably enough
45
13756.3.11 by Jelmer Vernooij
Pass along access policy.
46
    def add_my_options(self):
47
        """See `LaunchpadScript`."""
13756.3.12 by Jelmer Vernooij
Document new options.
48
        self.parser.add_option(
49
            "--access-policy", type="choice", metavar="ACCESS_POLICY",
13756.3.11 by Jelmer Vernooij
Pass along access policy.
50
            choices=["anything", "default"], default=None)
51
12415.1.5 by William Grant
Purge implicit_begin/implicitBegin; ignored since Storm.
52
    def _init_db(self, isolation):
8447.4.24 by Michael Hudson
final (?) self review
53
        # This script doesn't access the database.
8447.4.18 by Michael Hudson
all tests pass, i think
54
        pass
55
6092.1.4 by Michael Hudson
tests pass, remarkably enough
56
    def main(self):
8447.4.24 by Michael Hudson
final (?) self review
57
        arg, = self.args
58
        job_id = int(arg)
6233.3.3 by Michael Hudson
review comments
59
        # XXX: MichaelHudson 2008-05-07 bug=227586: Setting up the component
6233.3.2 by Michael Hudson
changes to the config from trying things out on staging
60
        # architecture overrides $GNUPGHOME to something stupid.
61
        os.environ['GNUPGHOME'] = ''
8447.4.24 by Michael Hudson
final (?) self review
62
        reactor.callWhenRunning(self._do_import, job_id)
6092.1.4 by Michael Hudson
tests pass, remarkably enough
63
        reactor.run()
64
8447.4.24 by Michael Hudson
final (?) self review
65
    def _do_import(self, job_id):
66
        defer.maybeDeferred(self._main, job_id).addErrback(
6092.1.5 by Michael Hudson
oops reporting and logging in codeimportworker
67
            log.err).addCallback(
68
            lambda ignored: reactor.stop())
69
8447.4.24 by Michael Hudson
final (?) self review
70
    def _main(self, job_id):
8447.4.18 by Michael Hudson
all tests pass, i think
71
        worker = CodeImportWorkerMonitor(
8447.4.24 by Michael Hudson
final (?) self review
72
            job_id, self.logger,
13756.3.22 by Jelmer Vernooij
Fix arguments to CodeImportWorkerMonitor.
73
            xmlrpc.Proxy(config.codeimportdispatcher.codeimportscheduler_url),
74
            self.options.access_policy)
8447.4.18 by Michael Hudson
all tests pass, i think
75
        return worker.run()
6092.1.4 by Michael Hudson
tests pass, remarkably enough
76
77
if __name__ == '__main__':
8447.4.18 by Michael Hudson
all tests pass, i think
78
    script = CodeImportWorker('codeimportworker')
6092.1.5 by Michael Hudson
oops reporting and logging in codeimportworker
79
    script.run()