14
from optparse import OptionParser
16
15
from canonical.config import config
17
from canonical.database.sqlbase import ISOLATION_LEVEL_READ_COMMITTED
18
from canonical.launchpad.scripts import execute_zcml_for_scripts
19
from canonical.lp import initZopeless
21
from canonical.launchpad.scripts import logger, logger_options
16
from lp.services.scripts.base import LaunchpadScript, LaunchpadScriptFailure
22
17
from lp.soyuz.scripts.queue import (
23
18
CommandRunner, CommandRunnerError, name_queue_map)
27
parser = OptionParser()
28
logger_options(parser)
30
parser.add_option("-Q", "--queue",
31
dest="queue_name", metavar="QUEUE", default="new",
32
help="Which queue to consider")
34
parser.add_option("-d", "--distribution",
35
dest="distribution_name", metavar="DISTRO", default=None,
36
help="Which distro to look in")
38
parser.add_option("-s", "--suite",
39
dest="suite_name", metavar="DISTRORELEASE",
41
help=("Which distrorelease to look in, defaults "
42
"to distribution 'currentseries'."))
44
parser.add_option("-N", "--dry-run", action="store_true",
45
dest="dryrun", metavar="DRY_RUN", default=False,
46
help="Whether to treat this as a dry-run or not.")
48
parser.add_option("-M", "--no-mail", action="store_true",
49
dest="nomail", metavar="NO_MAIL", default=False,
50
help="Whether to send announce email or not.")
52
parser.add_option("-e", "--exact-match", action="store_true",
53
dest="exact_match", metavar="EXACTMATCH",
55
help="Whether treat filter as a exact match or not.")
57
parser.add_option("-i", "--ignore-errors", action="store_true",
58
dest="ignore_errors", metavar="IGNOREERRORS",
60
help="Ignore errors when performing a list of commands.")
62
parser.add_option("-f", "--file", metavar="FILE", default=None,
63
help="file containing a sequence of command lines.")
65
parser.add_option("-c", "--component", dest="component_name",
66
metavar="COMPONENT", default=None,
67
help="When overriding, move package to COMPONENT")
69
parser.add_option("-x", "--section", dest="section_name",
70
metavar="SECTION", default=None,
71
help="When overriding, move package to SECTION")
73
parser.add_option("-p", "--priority", dest="priority_name",
74
metavar="PRIORITY", default=None,
75
help="When overriding, move package to PRIORITY")
77
options, args = parser.parse_args()
78
log = logger(options, "ftpmaster.queue")
80
if options.queue_name not in name_queue_map:
81
print 'Unable to map queue name "%s"' % options.queue_name
84
no_mail = options.dryrun or options.nomail
85
queue = name_queue_map[options.queue_name]
88
args_list = [args.strip().split() for args in
89
open(options.file).readlines()]
93
cmd_runner = CommandRunner(
94
queue, options.distribution_name, options.suite_name,
95
no_mail, options.component_name, options.section_name,
96
options.priority_name, log=log)
98
print ("Initializing connection to queue %s" % options.queue_name)
100
execute_zcml_for_scripts()
101
ztm = initZopeless(dbuser=config.uploadqueue.dbuser,
102
isolation=ISOLATION_LEVEL_READ_COMMITTED)
104
for single_args in args_list:
106
cmd_runner.execute(single_args, options.exact_match)
107
except CommandRunnerError, info:
109
if options.ignore_errors:
112
print 'Aborting current transaction'
21
class QueueScript(LaunchpadScript):
23
usage = 'Usage: %prog [options] <command>'
25
def add_my_options(self):
26
self.parser.add_option(
28
dest="queue_name", metavar="QUEUE", default="new",
29
help="Which queue to consider")
31
self.parser.add_option(
32
"-d", "--distribution",
33
dest="distribution_name", metavar="DISTRO", default=None,
34
help="Which distro to look in")
36
self.parser.add_option(
38
dest="suite_name", metavar="DISTRORELEASE", default=None,
39
help=("Which distrorelease to look in, defaults "
40
"to distribution 'currentseries'."))
42
self.parser.add_option(
43
"-N", "--dry-run", action="store_true",
44
dest="dryrun", metavar="DRY_RUN", default=False,
45
help="Whether to treat this as a dry-run or not.")
47
self.parser.add_option(
48
"-M", "--no-mail", action="store_true",
49
dest="nomail", metavar="NO_MAIL", default=False,
50
help="Whether to send announce email or not.")
52
self.parser.add_option(
53
"-e", "--exact-match", action="store_true",
54
dest="exact_match", metavar="EXACTMATCH", default=False,
55
help="Whether treat filter as a exact match or not.")
57
self.parser.add_option(
58
"-i", "--ignore-errors", action="store_true",
59
dest="ignore_errors", metavar="IGNOREERRORS", default=False,
60
help="Ignore errors when performing a list of commands.")
62
self.parser.add_option(
63
"-f", "--file", metavar="FILE", default=None,
64
help="file containing a sequence of command lines.")
66
self.parser.add_option(
67
"-c", "--component", dest="component_name",
68
metavar="COMPONENT", default=None,
69
help="When overriding, move package to COMPONENT")
71
self.parser.add_option(
72
"-x", "--section", dest="section_name",
73
metavar="SECTION", default=None,
74
help="When overriding, move package to SECTION")
76
self.parser.add_option(
77
"-p", "--priority", dest="priority_name",
78
metavar="PRIORITY", default=None,
79
help="When overriding, move package to PRIORITY")
82
if self.options.queue_name not in name_queue_map:
84
'Unable to map queue name "%s"' % self.options.queue_name)
86
no_mail = self.options.dryrun or self.options.nomail
87
queue = name_queue_map[self.options.queue_name]
90
args_list = [self.args.strip().split() for args in
91
open(self.options.file).readlines()]
115
if not options.dryrun:
93
args_list = [self.args]
95
cmd_runner = CommandRunner(
96
queue, self.options.distribution_name, self.options.suite_name,
97
no_mail, self.options.component_name, self.options.section_name,
98
self.options.priority_name, log=self.logger)
100
print "Initializing connection to queue %s" % self.options.queue_name
102
for single_args in args_list:
104
cmd_runner.execute(single_args, self.options.exact_match)
105
except CommandRunnerError, info:
107
if self.options.ignore_errors:
110
raise LaunchpadScriptFailure(
111
'Error encountered -- aborting current transaction')
118
print "DRY RUN requested, not committing."
113
if not self.options.dryrun:
116
print "DRY RUN requested, not committing."
123
118
if __name__ == '__main__':
119
QueueScript('queue', config.uploadqueue.dbuser).run()