~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
27
from canonical.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)
10935.1.1 by Curtis Hovey
Add the missing config section_name argument to the set_up_oops_reporting.
39
        set_up_oops_reporting('codeimportworker', name, mangle_stdout=True)
6092.1.4 by Michael Hudson
tests pass, remarkably enough
40
13756.3.11 by Jelmer Vernooij
Pass along access policy.
41
    def add_my_options(self):
42
        """See `LaunchpadScript`."""
13756.3.12 by Jelmer Vernooij
Document new options.
43
        self.parser.add_option(
44
            "--access-policy", type="choice", metavar="ACCESS_POLICY",
13756.3.11 by Jelmer Vernooij
Pass along access policy.
45
            choices=["anything", "default"], default=None)
46
12415.1.5 by William Grant
Purge implicit_begin/implicitBegin; ignored since Storm.
47
    def _init_db(self, isolation):
8447.4.24 by Michael Hudson
final (?) self review
48
        # This script doesn't access the database.
8447.4.18 by Michael Hudson
all tests pass, i think
49
        pass
50
6092.1.4 by Michael Hudson
tests pass, remarkably enough
51
    def main(self):
8447.4.24 by Michael Hudson
final (?) self review
52
        arg, = self.args
53
        job_id = int(arg)
6233.3.3 by Michael Hudson
review comments
54
        # 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
55
        # architecture overrides $GNUPGHOME to something stupid.
56
        os.environ['GNUPGHOME'] = ''
8447.4.24 by Michael Hudson
final (?) self review
57
        reactor.callWhenRunning(self._do_import, job_id)
6092.1.4 by Michael Hudson
tests pass, remarkably enough
58
        reactor.run()
59
8447.4.24 by Michael Hudson
final (?) self review
60
    def _do_import(self, job_id):
61
        defer.maybeDeferred(self._main, job_id).addErrback(
6092.1.5 by Michael Hudson
oops reporting and logging in codeimportworker
62
            log.err).addCallback(
63
            lambda ignored: reactor.stop())
64
8447.4.24 by Michael Hudson
final (?) self review
65
    def _main(self, job_id):
8447.4.18 by Michael Hudson
all tests pass, i think
66
        worker = CodeImportWorkerMonitor(
8447.4.24 by Michael Hudson
final (?) self review
67
            job_id, self.logger,
13756.3.22 by Jelmer Vernooij
Fix arguments to CodeImportWorkerMonitor.
68
            xmlrpc.Proxy(config.codeimportdispatcher.codeimportscheduler_url),
69
            self.options.access_policy)
8447.4.18 by Michael Hudson
all tests pass, i think
70
        return worker.run()
6092.1.4 by Michael Hudson
tests pass, remarkably enough
71
72
if __name__ == '__main__':
8447.4.18 by Michael Hudson
all tests pass, i think
73
    script = CodeImportWorker('codeimportworker')
6092.1.5 by Michael Hudson
oops reporting and logging in codeimportworker
74
    script.run()