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
60
61
62
|
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""PackageDiff cronscript class."""
__metaclass__ = type
__all__ = [
'ProcessPendingPackageDiffs',
]
from zope.component import getUtility
from lp.services.scripts.base import (
LaunchpadCronScript,
LaunchpadScriptFailure,
)
from lp.soyuz.interfaces.packagediff import IPackageDiffSet
class ProcessPendingPackageDiffs(LaunchpadCronScript):
def add_my_options(self):
# 50 diffs seems to be more them enough to process all uploaded
# source packages for 1 hour (average upload rate) for ubuntu
# primary archive, security and PPAs in general.
self.parser.add_option(
"-l", "--limit", type="int", default=50,
help="Maximum number of requests to be processed in this run.")
self.parser.add_option(
"-n", "--dry-run",
dest="dryrun", action="store_true", default=False,
help="Whether or not to commit the transaction.")
def main(self):
"""Process pending `PackageDiff` records.
Collect up to the maximum number of pending `PackageDiff` records
available and process them.
Processed diffs results are commited individually.
"""
if self.args:
raise LaunchpadScriptFailure("Unhandled arguments %r" % self.args)
packagediff_set = getUtility(IPackageDiffSet)
pending_diffs = packagediff_set.getPendingDiffs(
limit=self.options.limit)
self.logger.debug(
'Considering %s diff requests' % pending_diffs.count())
# Iterate over all pending packagediffs.
for packagediff in pending_diffs:
self.logger.debug(
'Performing package diff for %s from %s' % (
packagediff.from_source.name, packagediff.title))
packagediff.performDiff()
if not self.options.dryrun:
self.logger.debug('Commiting the transaction.')
self.txn.commit()
|