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 |
||
8356.1.1
by Leonard Richardson
Partial move. |
26 |
from lp.services.scripts.base import LaunchpadCronScript |
10234.3.3
by Curtis Hovey
Migrated hardward database to lp. Updated test_doc to run the hwddb test. |
27 |
from lp.hardwaredb.scripts.hwdbsubmissions import ( |
6978.2.10
by Abel Deuring
cronscript to parse HWDB submissions added. |
28 |
process_pending_submissions) |
29 |
||
30 |
||
31 |
class HWDBSubmissionProcessor(LaunchpadCronScript): |
|
32 |
||
33 |
def add_my_options(self): |
|
34 |
"""See `LaunchpadScript`."""
|
|
35 |
self.parser.add_option( |
|
36 |
'-m', '--max-submissions', |
|
37 |
help='Limit the number of submissions which will be processed.') |
|
38 |
||
39 |
def main(self): |
|
40 |
max_submissions = self.options.max_submissions |
|
41 |
if max_submissions is not None: |
|
42 |
try: |
|
43 |
max_submissions = int(self.options.max_submissions) |
|
44 |
except ValueError: |
|
45 |
self.logger.error( |
|
46 |
'Invalid value for --max_submissions specified: %r.' |
|
47 |
% max_submissions) |
|
48 |
return
|
|
49 |
if max_submissions <= 0: |
|
50 |
self.logger.error( |
|
51 |
'--max_submissions must be a positive integer.') |
|
52 |
return
|
|
53 |
||
54 |
process_pending_submissions(self.txn, self.logger, max_submissions) |
|
55 |
||
56 |
if __name__ == '__main__': |
|
57 |
script = HWDBSubmissionProcessor( |
|
58 |
'hwdbsubmissions', dbuser='hwdb-submission-processor') |
|
59 |
script.lock_and_run() |