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 |
|
8447.4.18
by Michael Hudson
all tests pass, i think |
41 |
def _init_db(self, implicit_begin, isolation): |
8447.4.24
by Michael Hudson
final (?) self review |
42 |
# This script doesn't access the database.
|
8447.4.18
by Michael Hudson
all tests pass, i think |
43 |
pass
|
44 |
||
6092.1.4
by Michael Hudson
tests pass, remarkably enough |
45 |
def main(self): |
8447.4.24
by Michael Hudson
final (?) self review |
46 |
arg, = self.args |
47 |
job_id = int(arg) |
|
6233.3.3
by Michael Hudson
review comments |
48 |
# 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 |
49 |
# architecture overrides $GNUPGHOME to something stupid.
|
50 |
os.environ['GNUPGHOME'] = '' |
|
8447.4.24
by Michael Hudson
final (?) self review |
51 |
reactor.callWhenRunning(self._do_import, job_id) |
6092.1.4
by Michael Hudson
tests pass, remarkably enough |
52 |
reactor.run() |
53 |
||
8447.4.24
by Michael Hudson
final (?) self review |
54 |
def _do_import(self, job_id): |
55 |
defer.maybeDeferred(self._main, job_id).addErrback( |
|
6092.1.5
by Michael Hudson
oops reporting and logging in codeimportworker |
56 |
log.err).addCallback( |
57 |
lambda ignored: reactor.stop()) |
|
58 |
||
8447.4.24
by Michael Hudson
final (?) self review |
59 |
def _main(self, job_id): |
8447.4.18
by Michael Hudson
all tests pass, i think |
60 |
worker = CodeImportWorkerMonitor( |
8447.4.24
by Michael Hudson
final (?) self review |
61 |
job_id, self.logger, |
8447.4.18
by Michael Hudson
all tests pass, i think |
62 |
xmlrpc.Proxy(config.codeimportdispatcher.codeimportscheduler_url)) |
63 |
return worker.run() |
|
6092.1.4
by Michael Hudson
tests pass, remarkably enough |
64 |
|
65 |
if __name__ == '__main__': |
|
8447.4.18
by Michael Hudson
all tests pass, i think |
66 |
script = CodeImportWorker('codeimportworker') |
6092.1.5
by Michael Hudson
oops reporting and logging in codeimportworker |
67 |
script.run() |