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).
|
|
5 |
||
6978.2.10
by Abel Deuring
cronscript to parse HWDB submissions added. |
6 |
# pylint: disable-msg=W0403
|
7 |
||
8 |
"""
|
|
9 |
Cron job that parses pending HWDB submissions.
|
|
6978.2.12
by Abel Deuring
added a docstring for the cronscript |
10 |
|
11 |
||
12 |
Options:
|
|
13 |
-m, --max-submissions: (optional) The maximum number of submissions
|
|
14 |
which will be processed.
|
|
15 |
||
16 |
This script iterates over the HWDB submissions with the status
|
|
17 |
SUBMITTED, beginning with the oldest submissions, populate the
|
|
18 |
HWDB tables with the data from these submissions.
|
|
19 |
||
20 |
Properly processed submissions are set to the status PROCESSED;
|
|
21 |
submissions that cannot be processed are set to the status INVALID.
|
|
6978.2.10
by Abel Deuring
cronscript to parse HWDB submissions added. |
22 |
"""
|
23 |
||
24 |
import _pythonpath |
|
25 |
||
14612.2.8
by William Grant
cronscripts |
26 |
from lp.hardwaredb.scripts.hwdbsubmissions import process_pending_submissions |
8356.1.1
by Leonard Richardson
Partial move. |
27 |
from lp.services.scripts.base import LaunchpadCronScript |
6978.2.10
by Abel Deuring
cronscript to parse HWDB submissions added. |
28 |
|
29 |
||
30 |
class HWDBSubmissionProcessor(LaunchpadCronScript): |
|
31 |
||
32 |
def add_my_options(self): |
|
33 |
"""See `LaunchpadScript`."""
|
|
34 |
self.parser.add_option( |
|
35 |
'-m', '--max-submissions', |
|
36 |
help='Limit the number of submissions which will be processed.') |
|
13843.6.1
by Abel Deuring
optionally suppress warnings from the HWDB script; new script reporcess bad HWDB submisions. |
37 |
self.parser.add_option( |
38 |
'-w', '--warnings', action="store_true", default=False, |
|
39 |
help='Include warnings.') |
|
6978.2.10
by Abel Deuring
cronscript to parse HWDB submissions added. |
40 |
|
41 |
def main(self): |
|
42 |
max_submissions = self.options.max_submissions |
|
43 |
if max_submissions is not None: |
|
44 |
try: |
|
45 |
max_submissions = int(self.options.max_submissions) |
|
46 |
except ValueError: |
|
47 |
self.logger.error( |
|
48 |
'Invalid value for --max_submissions specified: %r.' |
|
49 |
% max_submissions) |
|
50 |
return
|
|
51 |
if max_submissions <= 0: |
|
52 |
self.logger.error( |
|
53 |
'--max_submissions must be a positive integer.') |
|
54 |
return
|
|
55 |
||
13843.6.1
by Abel Deuring
optionally suppress warnings from the HWDB script; new script reporcess bad HWDB submisions. |
56 |
process_pending_submissions( |
13843.6.6
by Henning Eggers
Fix options.warnings |
57 |
self.txn, self.logger, max_submissions, self.options.warnings) |
6978.2.10
by Abel Deuring
cronscript to parse HWDB submissions added. |
58 |
|
59 |
if __name__ == '__main__': |
|
60 |
script = HWDBSubmissionProcessor( |
|
61 |
'hwdbsubmissions', dbuser='hwdb-submission-processor') |
|
62 |
script.lock_and_run() |