~launchpad-pqm/launchpad/devel

9678.4.1 by Max Bowsher
[r=barry][ui=none] Update Makefile PYTHON_VERSION variables and most script #! lines to python2.5.
1
#!/usr/bin/python2.5
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
25
8426.6.1 by Michael Hudson
bzr ls --versioned --recursive --kind=file | xargs sed -i -e 's,from canonical.codehosting,from lp.codehosting,'
26
from lp.codehosting.codeimport.workermonitor import (
6092.1.4 by Michael Hudson
tests pass, remarkably enough
27
    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/.
28
from lp.services.scripts.base import LaunchpadScript
6092.1.5 by Michael Hudson
oops reporting and logging in codeimportworker
29
from canonical.twistedsupport.loggingsupport import set_up_oops_reporting
30
31
32
class CodeImportWorker(LaunchpadScript):
33
34
    def __init__(self, name, dbuser=None, test_args=None):
35
        LaunchpadScript.__init__(self, name, dbuser, test_args)
7483.2.67 by Jonathan Lange
Fix up the Twisted log tearDown behaviour, adding a new option
36
        set_up_oops_reporting(name, mangle_stdout=True)
6092.1.4 by Michael Hudson
tests pass, remarkably enough
37
38
    def main(self):
6233.3.3 by Michael Hudson
review comments
39
        # 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
40
        # architecture overrides $GNUPGHOME to something stupid.
41
        os.environ['GNUPGHOME'] = ''
6092.1.5 by Michael Hudson
oops reporting and logging in codeimportworker
42
        reactor.callWhenRunning(self._run_reactor)
6092.1.4 by Michael Hudson
tests pass, remarkably enough
43
        reactor.run()
44
6092.1.5 by Michael Hudson
oops reporting and logging in codeimportworker
45
    def _run_reactor(self):
46
        defer.maybeDeferred(self._main).addErrback(
47
            log.err).addCallback(
48
            lambda ignored: reactor.stop())
49
50
    def _main(self):
51
        arg, = self.args
52
        return CodeImportWorkerMonitor(int(arg), self.logger).run()
6092.1.4 by Michael Hudson
tests pass, remarkably enough
53
54
if __name__ == '__main__':
6197.1.1 by michael.hudson at canonical
codeimportworker db user with appropriate permissions
55
    script = CodeImportWorker('codeimportworker', dbuser='codeimportworker')
6092.1.5 by Michael Hudson
oops reporting and logging in codeimportworker
56
    script.run()