14
14
which will be processed.
16
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.
17
INVALID. It processes only submissions with an ID greater or equal
18
than the number specified by the file given a option -s.
20
When the script terminates, it writes the ID of the last processed
21
submission into this file.
20
23
Properly processed submissions are set to the status PROCESSED;
21
submissions that cannot be processed are set to the status INVALID.
24
submissions that cannot be processed retain the status INVALID.
26
from lp.services.scripts.base import LaunchpadScript
29
from lp.services.scripts.base import LaunchpadCronScript
27
30
from lp.hardwaredb.scripts.hwdbsubmissions import (
28
31
reprocess_invalid_submissions)
31
class HWDBSubmissionProcessor(LaunchpadScript):
34
class HWDBSubmissionProcessor(LaunchpadCronScript):
33
36
def add_my_options(self):
34
37
"""See `LaunchpadScript`."""
39
42
'-w', '--warnings', action="store_true", default=False,
40
43
help='Include warnings.')
41
44
self.parser.add_option(
43
help=('Process HWSubmission records having an id greater or '
44
'equal than this value.'))
45
'-s', '--start-file', default=None,
46
help=('The name of a file storing the smallest ID of a\n'
47
'hardware database submission that should be processed.\n'
48
'This script must have read and write access to the file.'))
47
51
max_submissions = self.options.max_submissions
58
62
'--max_submissions must be a positive integer.')
60
if self.options.start is None:
61
self.logger.error('Option --start not specified.')
64
start = int(self.options.start)
65
if self.options.start_file is None:
66
self.logger.error('Option --start-file not specified.')
69
start_file = open(self.options.start_file, 'r+')
70
start_id = start_file.read().strip()
71
except IOError, error:
73
'Cannot access file %s: %s' % (
74
self.options.start_file, error))
77
start_id = int(start_id)
66
self.logger.error('Option --start must have an integer value.')
80
'%s must contain only an integer' % self.options.start_file)
69
self.logger.error('--start must be a positive integer.')
84
'%s must contain a positive integer'
85
% self.options.start_file)
72
reprocess_invalid_submissions(
73
start, self.txn, self.logger,
88
next_start = reprocess_invalid_submissions(
89
start_id, self.txn, self.logger,
74
90
max_submissions, self.options.warnings)
93
start_file.write('%i' % next_start)
76
96
if __name__ == '__main__':
77
97
script = HWDBSubmissionProcessor(
78
98
'hwdbsubmissions', dbuser='hwdb-submission-processor')