~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.7 by Karl Fogel
Add the copyright header block to more 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).
5849.2.4 by Michael Hudson
stuff
5
5849.2.16 by Michael Hudson
one more
6
"""Look for and dispatch code import jobs as needed."""
5849.2.4 by Michael Hudson
stuff
7
5849.2.17 by Michael Hudson
the usual
8
# pylint: disable-msg=W0403
5849.2.4 by Michael Hudson
stuff
9
import _pythonpath
10
5849.2.18 by michael.hudson at canonical
review comments
11
from xmlrpclib import ServerProxy
12
8426.6.1 by Michael Hudson
bzr ls --versioned --recursive --kind=file | xargs sed -i -e 's,from canonical.codehosting,from lp.codehosting,'
13
from lp.codehosting.codeimport.dispatcher import CodeImportDispatcher
5849.2.4 by Michael Hudson
stuff
14
from canonical.config import config
8356.1.1 by Leonard Richardson
Partial move.
15
from lp.services.scripts.base import LaunchpadScript
5849.2.4 by Michael Hudson
stuff
16
from canonical.launchpad.webapp.errorlog import globalErrorUtility
17
18
6224.1.1 by Michael Hudson
Move database code from the dispatcher to ICodeImportJobSet.getJobForMachine.
19
class CodeImportDispatcherScript(LaunchpadScript):
20
10330.2.4 by Michael Hudson
ok, this actually works
21
    def add_my_options(self):
22
        self.parser.add_option(
23
            "--max-jobs", dest="max_jobs", type=int,
24
            default=config.codeimportdispatcher.max_jobs_per_machine,
25
            help="The maximum number of jobs to run on this machine.")
26
6224.1.6 by Michael Hudson
fix cronscripts/code-import-dispatcher.py and make scripts/code-import-worker-db.py executable
27
    def run(self, use_web_security=False, implicit_begin=True,
28
            isolation=None):
6224.1.1 by Michael Hudson
Move database code from the dispatcher to ICodeImportJobSet.getJobForMachine.
29
        """See `LaunchpadScript.run`.
30
31
        We override to avoid all of the setting up all of the component
32
        architecture and connecting to the database.
33
        """
34
        self.main()
5849.2.4 by Michael Hudson
stuff
35
36
    def main(self):
37
        globalErrorUtility.configure('codeimportdispatcher')
38
10330.2.4 by Michael Hudson
ok, this actually works
39
        dispatcher = CodeImportDispatcher(self.logger, self.options.max_jobs)
10356.1.4 by Michael Hudson
docstrings, and the important bit :-)
40
        dispatcher.findAndDispatchJobs(
5849.2.18 by michael.hudson at canonical
review comments
41
            ServerProxy(config.codeimportdispatcher.codeimportscheduler_url))
5849.2.4 by Michael Hudson
stuff
42
43
44
if __name__ == '__main__':
6224.1.1 by Michael Hudson
Move database code from the dispatcher to ICodeImportJobSet.getJobForMachine.
45
    script = CodeImportDispatcherScript("codeimportdispatcher")
5849.2.4 by Michael Hudson
stuff
46
    script.lock_and_run()
47