1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#!/usr/bin/python2.4
#
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
# pylint: disable-msg=W0403
"""
Cron job that parses pending HWDB submissions.
Options:
-m, --max-submissions: (optional) The maximum number of submissions
which will be processed.
This script iterates over the HWDB submissions with the status
SUBMITTED, beginning with the oldest submissions, populate the
HWDB tables with the data from these submissions.
Properly processed submissions are set to the status PROCESSED;
submissions that cannot be processed are set to the status INVALID.
"""
import _pythonpath
from lp.services.scripts.base import LaunchpadCronScript
from canonical.launchpad.scripts.hwdbsubmissions import (
process_pending_submissions)
class HWDBSubmissionProcessor(LaunchpadCronScript):
def add_my_options(self):
"""See `LaunchpadScript`."""
self.parser.add_option(
'-m', '--max-submissions',
help='Limit the number of submissions which will be processed.')
def main(self):
max_submissions = self.options.max_submissions
if max_submissions is not None:
try:
max_submissions = int(self.options.max_submissions)
except ValueError:
self.logger.error(
'Invalid value for --max_submissions specified: %r.'
% max_submissions)
return
if max_submissions <= 0:
self.logger.error(
'--max_submissions must be a positive integer.')
return
process_pending_submissions(self.txn, self.logger, max_submissions)
if __name__ == '__main__':
script = HWDBSubmissionProcessor(
'hwdbsubmissions', dbuser='hwdb-submission-processor')
script.lock_and_run()
|