2756
by Canonical.com Patch Queue Manager
Queue-Accepted processor and some upload tweaks to fit it. r=stevea |
1 |
#!/usr/bin/env python
|
2 |
"""Queue/Accepted processor
|
|
3 |
||
4 |
Given a distribution to run on, obtains all the queue items for the
|
|
5 |
distribution and then gets on and deals with any accepted items, preparing them
|
|
6 |
for publishing as appropriate.
|
|
7 |
"""
|
|
8 |
||
9 |
import _pythonpath |
|
10 |
||
11 |
import os |
|
12 |
import sys |
|
13 |
||
14 |
from optparse import OptionParser |
|
15 |
||
16 |
from zope.component import getUtility |
|
17 |
||
18 |
from canonical.lp import initZopeless |
|
19 |
from canonical.config import config |
|
20 |
from canonical.launchpad.scripts import ( |
|
21 |
execute_zcml_for_scripts, logger, logger_options) |
|
22 |
from canonical.launchpad.interfaces import IDistributionSet |
|
23 |
||
24 |
from contrib.glock import GlobalLock |
|
25 |
from canonical.lp.dbschema import DistroReleaseQueueStatus |
|
26 |
||
27 |
def main(): |
|
28 |
# Parse command-line arguments
|
|
29 |
parser = OptionParser() |
|
30 |
logger_options(parser) |
|
31 |
||
32 |
parser.add_option("-N", "--dry-run", action="store_true", |
|
33 |
dest="dryrun", metavar="DRY_RUN", default=False, |
|
34 |
help="Whether to treat this as a dry-run or not.") |
|
35 |
global options |
|
36 |
(options, args) = parser.parse_args() |
|
37 |
||
38 |
global log |
|
39 |
log = logger(options, "process-accepted") |
|
40 |
||
41 |
if len(args) != 1: |
|
42 |
log.error("Need to be given exactly one non-option argument. " |
|
43 |
"Namely the distribution to process.") |
|
44 |
return 1 |
|
45 |
||
46 |
distro_name = args[0] |
|
47 |
||
48 |
log.debug("Acquiring lock") |
|
49 |
lock = GlobalLock('/var/lock/launchpad-process-accepted.lock') |
|
50 |
lock.acquire(blocking=True) |
|
51 |
||
52 |
log.debug("Initialising connection.") |
|
53 |
global ztm |
|
54 |
ztm = initZopeless(dbuser=config.uploadqueue.dbuser) |
|
55 |
||
56 |
execute_zcml_for_scripts() |
|
57 |
||
58 |
try: |
|
59 |
log.debug("Finding distribution %s." % distro_name) |
|
60 |
distro = getUtility(IDistributionSet).getByName(distro_name) |
|
61 |
for release in distro.releases: |
|
62 |
log.debug("Processing queue for %s" % release.name) |
|
63 |
queue_items = release.getQueueItems( |
|
64 |
DistroReleaseQueueStatus.ACCEPTED) |
|
65 |
for queue_item in queue_items: |
|
66 |
try: |
|
67 |
queue_item.realiseUpload(log) |
|
68 |
ztm.commit() |
|
69 |
except: # Re-raised after logging. |
|
70 |
log.error("Failure processing queue_item %d" % ( |
|
71 |
queue_item.id)) |
|
72 |
raise
|
|
73 |
||
74 |
finally: |
|
75 |
log.debug("Rolling back any remaining transactions.") |
|
76 |
ztm.abort() |
|
77 |
log.debug("Releasing lock") |
|
78 |
lock.release() |
|
79 |
||
80 |
return 0 |
|
81 |
||
82 |
if __name__ == '__main__': |
|
83 |
sys.exit(main()) |
|
84 |