7675.845.17
by Edwin Grubbs
Working as two separate cron scripts. |
1 |
#!/usr/bin/python -S
|
2 |
#
|
|
3 |
# Copyright 2009, 2010 Canonical Ltd. This software is licensed under the
|
|
4 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
5 |
||
6 |
"""Handle jobs for a specified job source class."""
|
|
7 |
||
8 |
__metaclass__ = type |
|
9 |
||
7675.845.20
by Edwin Grubbs
Formatted imports and delinted. |
10 |
import sys |
11 |
||
7675.845.17
by Edwin Grubbs
Working as two separate cron scripts. |
12 |
import _pythonpath |
13 |
from twisted.python import log |
|
14 |
||
15 |
from canonical.config import config |
|
7675.845.20
by Edwin Grubbs
Formatted imports and delinted. |
16 |
from lp.services.job import runner |
7675.845.22
by Edwin Grubbs
Suggestions from reviewer. |
17 |
from lp.services.job.runner import JobCronScript |
7675.845.17
by Edwin Grubbs
Working as two separate cron scripts. |
18 |
|
19 |
||
20 |
class ProcessJobSource(JobCronScript): |
|
7675.845.23
by Edwin Grubbs
Addressed more review comments. |
21 |
"""Run jobs for a specified job source class."""
|
22 |
usage = ( |
|
23 |
"Usage: %prog [options] JOB_SOURCE\n\n" |
|
24 |
"For more help, run:\n" |
|
25 |
" cronscripts/process-job-source-groups.py --help") |
|
7675.845.17
by Edwin Grubbs
Working as two separate cron scripts. |
26 |
|
7675.845.26
by Edwin Grubbs
Simplified cron script. |
27 |
def __init__(self): |
28 |
super(ProcessJobSource, self).__init__() |
|
7675.845.17
by Edwin Grubbs
Working as two separate cron scripts. |
29 |
# The fromlist argument is necessary so that __import__()
|
30 |
# returns the bottom submodule instead of the top one.
|
|
7675.845.27
by Edwin Grubbs
Merged in db-devel. |
31 |
module = __import__(self.config_section.module, |
32 |
fromlist=[self.job_source_name]) |
|
33 |
self.source_interface = getattr(module, self.job_source_name) |
|
34 |
||
35 |
@property
|
|
36 |
def config_name(self): |
|
37 |
return self.job_source_name |
|
38 |
||
39 |
@property
|
|
7675.845.28
by Edwin Grubbs
Fixed tests after re-organizing command-line overrides of LaunchpadScript attributes. |
40 |
def name(self): |
7675.845.27
by Edwin Grubbs
Merged in db-devel. |
41 |
return 'process-job-source-%s' % self.job_source_name |
42 |
||
43 |
@property
|
|
7675.845.28
by Edwin Grubbs
Fixed tests after re-organizing command-line overrides of LaunchpadScript attributes. |
44 |
def runner_class(self): |
7675.845.27
by Edwin Grubbs
Merged in db-devel. |
45 |
runner_class_name = getattr( |
46 |
self.config_section, 'runner_class', 'JobRunner') |
|
7675.845.22
by Edwin Grubbs
Suggestions from reviewer. |
47 |
# Override attributes that are normally set in __init__().
|
7675.845.28
by Edwin Grubbs
Fixed tests after re-organizing command-line overrides of LaunchpadScript attributes. |
48 |
return getattr(runner, runner_class_name) |
7675.845.17
by Edwin Grubbs
Working as two separate cron scripts. |
49 |
|
7675.845.27
by Edwin Grubbs
Merged in db-devel. |
50 |
def handle_options(self): |
51 |
if len(self.args) != 1: |
|
52 |
self.parser.print_help() |
|
53 |
sys.exit(1) |
|
54 |
self.job_source_name = self.args[0] |
|
7675.845.28
by Edwin Grubbs
Fixed tests after re-organizing command-line overrides of LaunchpadScript attributes. |
55 |
super(ProcessJobSource, self).handle_options() |
7675.845.27
by Edwin Grubbs
Merged in db-devel. |
56 |
|
7675.845.17
by Edwin Grubbs
Working as two separate cron scripts. |
57 |
def main(self): |
58 |
if self.options.verbose: |
|
59 |
log.startLogging(sys.stdout) |
|
60 |
super(ProcessJobSource, self).main() |
|
61 |
||
62 |
||
63 |
if __name__ == '__main__': |
|
7675.845.22
by Edwin Grubbs
Suggestions from reviewer. |
64 |
script = ProcessJobSource() |
7675.845.17
by Edwin Grubbs
Working as two separate cron scripts. |
65 |
script.lock_and_run() |