~launchpad-pqm/launchpad/devel

13843.6.2 by Abel Deuring
script file added
1
#!/usr/bin/python -S
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
6
# pylint: disable-msg=W0403
7
8
"""
9
Cron job that parses pending HWDB submissions.
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.
22
"""
23
24
import _pythonpath
25
26
from lp.services.scripts.base import LaunchpadScript
27
from lp.hardwaredb.scripts.hwdbsubmissions import (
28
    reprocess_invalid_submissions)
29
30
31
class HWDBSubmissionProcessor(LaunchpadScript):
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
        self.parser.add_option(
39
            '-w', '--warnings', action="store_true", default=False,
40
            help='Include warnings.')
41
        self.parser.add_option(
42
            '-s', '--start',
43
            help=('Process HWSubmission records having an id greater or '
44
                  'equal than this value.'))
45
46
    def main(self):
47
        max_submissions = self.options.max_submissions
48
        if max_submissions is not None:
49
            try:
50
                max_submissions = int(self.options.max_submissions)
51
            except ValueError:
52
                self.logger.error(
53
                    'Invalid value for --max_submissions specified: %r.'
54
                    % max_submissions)
55
                return
56
            if max_submissions <= 0:
57
                self.logger.error(
58
                    '--max_submissions must be a positive integer.')
59
                return
60
        if self.options.start is None:
61
            self.logger.error('Option --start not specified.')
62
            return
63
        try:
64
            start = int(self.options.start)
65
        except ValueError:
66
            self.logger.error('Option --start must have an integer value.')
13843.6.6 by Henning Eggers
Fix options.warnings
67
            return
68
        if start < 0:
69
            self.logger.error('--start must be a positive integer.')
70
            return
13843.6.2 by Abel Deuring
script file added
71
72
        reprocess_invalid_submissions(
13843.6.6 by Henning Eggers
Fix options.warnings
73
            start, self.txn, self.logger,
74
            max_submissions, self.options.warnings)
13843.6.2 by Abel Deuring
script file added
75
76
if __name__ == '__main__':
77
    script = HWDBSubmissionProcessor(
78
        'hwdbsubmissions', dbuser='hwdb-submission-processor')
79
    script.lock_and_run()