~launchpad-pqm/launchpad/devel

10637.3.1 by Guilherme Salgado
Use the default python version instead of a hard-coded version
1
#!/usr/bin/python -S
8687.15.23 by Karl Fogel
Add the copyright header block to more files.
2
#
3
# Copyright 2009 Canonical Ltd.  This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
5
6
"""Queue management script
7
2865.2.33 by Celso Providelo
Adopted same queue script name to avoid conflicts and imported _pythonpath.
8
Tool for handling and visualisation of upload queue records.
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
9
"""
10
2865.2.33 by Celso Providelo
Adopted same queue script name to avoid conflicts and imported _pythonpath.
11
import _pythonpath
12
13970.7.17 by William Grant
Even queue is now a LaunchpadScript.
13
import transaction
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
14
14605.1.1 by Curtis Hovey
Moved canonical.config to lp.services.
15
from lp.services.config import config
14612.2.7 by William Grant
scripts
16
from lp.services.scripts.base import (
17
    LaunchpadScript,
18
    LaunchpadScriptFailure,
19
    )
8294.6.5 by Julian Edwards
Fix a bunch of circular imports, but there's still one I can't find.
20
from lp.soyuz.scripts.queue import (
14612.2.7 by William Grant
scripts
21
    CommandRunner,
22
    CommandRunnerError,
23
    name_queue_map,
24
    )
3048.5.11 by Celso Providelo
More fixes in queue, better options handler.
25
26
13970.7.17 by William Grant
Even queue is now a LaunchpadScript.
27
class QueueScript(LaunchpadScript):
28
29
    usage = 'Usage: %prog [options] <command>'
30
31
    def add_my_options(self):
32
        self.parser.add_option(
33
            "-Q", "--queue",
34
            dest="queue_name", metavar="QUEUE", default="new",
35
            help="Which queue to consider")
36
37
        self.parser.add_option(
38
            "-d", "--distribution",
39
            dest="distribution_name", metavar="DISTRO", default=None,
40
            help="Which distro to look in")
41
42
        self.parser.add_option(
43
            "-s", "--suite",
44
            dest="suite_name", metavar="DISTRORELEASE", default=None,
45
            help=("Which distrorelease to look in, defaults "
46
                  "to distribution 'currentseries'."))
47
48
        self.parser.add_option(
49
            "-N", "--dry-run", action="store_true",
50
            dest="dryrun", metavar="DRY_RUN", default=False,
51
            help="Whether to treat this as a dry-run or not.")
52
53
        self.parser.add_option(
54
            "-M", "--no-mail", action="store_true",
55
            dest="nomail", metavar="NO_MAIL", default=False,
56
            help="Whether to send announce email or not.")
57
58
        self.parser.add_option(
59
            "-e", "--exact-match", action="store_true",
60
            dest="exact_match", metavar="EXACTMATCH", default=False,
61
            help="Whether treat filter as a exact match or not.")
62
63
        self.parser.add_option(
64
            "-i", "--ignore-errors", action="store_true",
65
            dest="ignore_errors", metavar="IGNOREERRORS", default=False,
66
            help="Ignore errors when performing a list of commands.")
67
68
        self.parser.add_option(
69
            "-f", "--file", metavar="FILE", default=None,
70
            help="file containing a sequence of command lines.")
71
72
        self.parser.add_option(
73
            "-c", "--component", dest="component_name",
74
            metavar="COMPONENT", default=None,
75
            help="When overriding, move package to COMPONENT")
76
77
        self.parser.add_option(
78
            "-x", "--section", dest="section_name",
79
            metavar="SECTION", default=None,
80
            help="When overriding, move package to SECTION")
81
82
        self.parser.add_option(
83
            "-p", "--priority", dest="priority_name",
84
            metavar="PRIORITY", default=None,
85
            help="When overriding, move package to PRIORITY")
86
87
    def main(self):
88
        if self.options.queue_name not in name_queue_map:
89
            self.parser.error(
90
                'Unable to map queue name "%s"' % self.options.queue_name)
91
92
        no_mail = self.options.dryrun or self.options.nomail
93
        queue = name_queue_map[self.options.queue_name]
94
95
        if self.options.file:
96
            args_list = [self.args.strip().split() for args in
97
                         open(self.options.file).readlines()]
2865.2.52 by Celso Providelo
Fix some IDistroReleaseQueue properties, added test for them, fix queue tool to support single binary override, added 'report' option to queue tool to show the queues status for a given distro/distrorelase pair.
98
        else:
13970.7.17 by William Grant
Even queue is now a LaunchpadScript.
99
            args_list = [self.args]
100
101
        cmd_runner = CommandRunner(
102
            queue, self.options.distribution_name, self.options.suite_name,
103
            no_mail, self.options.component_name, self.options.section_name,
104
            self.options.priority_name, log=self.logger)
105
13970.7.22 by William Grant
Revive a message in queue, to appease test and be a bit more informative.
106
        print "Initializing connection to queue %s" % self.options.queue_name
107
13970.7.17 by William Grant
Even queue is now a LaunchpadScript.
108
        for single_args in args_list:
109
            try:
110
                cmd_runner.execute(single_args, self.options.exact_match)
111
            except CommandRunnerError, info:
112
                print (info)
113
                if self.options.ignore_errors:
114
                    continue
115
                transaction.abort()
116
                raise LaunchpadScriptFailure(
117
                    'Error encountered -- aborting current transaction')
3048.5.11 by Celso Providelo
More fixes in queue, better options handler.
118
            else:
13970.7.17 by William Grant
Even queue is now a LaunchpadScript.
119
                if not self.options.dryrun:
120
                    transaction.commit()
121
                else:
122
                    print "DRY RUN requested, not committing."
3048.5.10 by Celso Providelo
Improving ftpmaster queue tool
123
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
124
if __name__ == '__main__':
13970.7.17 by William Grant
Even queue is now a LaunchpadScript.
125
    QueueScript('queue', config.uploadqueue.dbuser).run()