~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
6092.1.4 by Michael Hudson
tests pass, remarkably enough
23
from twisted.internet import defer, reactor
24
from twisted.python import log
8447.4.18 by Michael Hudson
all tests pass, i think
25
from twisted.web import xmlrpc
26
14605.1.1 by Curtis Hovey
Moved canonical.config to lp.services.
27
from lp.services.config import config
6092.1.4 by Michael Hudson
tests pass, remarkably enough
28
8426.6.1 by Michael Hudson
bzr ls --versioned --recursive --kind=file | xargs sed -i -e 's,from canonical.codehosting,from lp.codehosting,'
29
from lp.codehosting.codeimport.workermonitor import (
6092.1.4 by Michael Hudson
tests pass, remarkably enough
30
    CodeImportWorkerMonitor)
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/.
31
from lp.services.scripts.base import LaunchpadScript
10548.1.1 by Jonathan Lange
Move twistedsupport to lp.services
32
from lp.services.twistedsupport.loggingsupport import set_up_oops_reporting
6092.1.5 by Michael Hudson
oops reporting and logging in codeimportworker
33
34
35
class CodeImportWorker(LaunchpadScript):
36
37
    def __init__(self, name, dbuser=None, test_args=None):
38
        LaunchpadScript.__init__(self, name, dbuser, test_args)
14446.1.8 by Julian Edwards
fix some logging; TestBranchPuller still failing
39
        # The logfile changes its name according to the code in
40
        # CodeImportDispatcher, so we pull it from the command line
41
        # options.
42
        set_up_oops_reporting(
43
            self.name, 'codeimportworker', logfile=self.options.log_file)
6092.1.4 by Michael Hudson
tests pass, remarkably enough
44
13756.3.11 by Jelmer Vernooij
Pass along access policy.
45
    def add_my_options(self):
46
        """See `LaunchpadScript`."""
13756.3.12 by Jelmer Vernooij
Document new options.
47
        self.parser.add_option(
48
            "--access-policy", type="choice", metavar="ACCESS_POLICY",
13756.3.11 by Jelmer Vernooij
Pass along access policy.
49
            choices=["anything", "default"], default=None)
50
12415.1.5 by William Grant
Purge implicit_begin/implicitBegin; ignored since Storm.
51
    def _init_db(self, isolation):
8447.4.24 by Michael Hudson
final (?) self review
52
        # This script doesn't access the database.
8447.4.18 by Michael Hudson
all tests pass, i think
53
        pass
54
6092.1.4 by Michael Hudson
tests pass, remarkably enough
55
    def main(self):
8447.4.24 by Michael Hudson
final (?) self review
56
        arg, = self.args
57
        job_id = int(arg)
6233.3.3 by Michael Hudson
review comments
58
        # 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
59
        # architecture overrides $GNUPGHOME to something stupid.
60
        os.environ['GNUPGHOME'] = ''
8447.4.24 by Michael Hudson
final (?) self review
61
        reactor.callWhenRunning(self._do_import, job_id)
6092.1.4 by Michael Hudson
tests pass, remarkably enough
62
        reactor.run()
63
8447.4.24 by Michael Hudson
final (?) self review
64
    def _do_import(self, job_id):
65
        defer.maybeDeferred(self._main, job_id).addErrback(
6092.1.5 by Michael Hudson
oops reporting and logging in codeimportworker
66
            log.err).addCallback(
67
            lambda ignored: reactor.stop())
68
8447.4.24 by Michael Hudson
final (?) self review
69
    def _main(self, job_id):
8447.4.18 by Michael Hudson
all tests pass, i think
70
        worker = CodeImportWorkerMonitor(
8447.4.24 by Michael Hudson
final (?) self review
71
            job_id, self.logger,
13756.3.22 by Jelmer Vernooij
Fix arguments to CodeImportWorkerMonitor.
72
            xmlrpc.Proxy(config.codeimportdispatcher.codeimportscheduler_url),
73
            self.options.access_policy)
8447.4.18 by Michael Hudson
all tests pass, i think
74
        return worker.run()
6092.1.4 by Michael Hudson
tests pass, remarkably enough
75
76
if __name__ == '__main__':
8447.4.18 by Michael Hudson
all tests pass, i think
77
    script = CodeImportWorker('codeimportworker')
6092.1.5 by Michael Hudson
oops reporting and logging in codeimportworker
78
    script.run()