~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
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
13
import sys
14
from optparse import OptionParser
15
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
16
from canonical.config import config
5842.1.1 by James Henstridge
Rename the transaction isolation level constants to match the psycopg2
17
from canonical.database.sqlbase import ISOLATION_LEVEL_READ_COMMITTED
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
18
from canonical.launchpad.scripts import execute_zcml_for_scripts
5842.1.1 by James Henstridge
Rename the transaction isolation level constants to match the psycopg2
19
from canonical.lp import initZopeless
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
20
4898.1.1 by Julian Edwards
Change the ftpmaster queue tool to use PackageUpload.notify() for sending
21
from canonical.launchpad.scripts import logger, logger_options
8294.6.5 by Julian Edwards
Fix a bunch of circular imports, but there's still one I can't find.
22
from lp.soyuz.scripts.queue import (
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
23
    CommandRunner, CommandRunnerError, name_queue_map)
3048.5.11 by Celso Providelo
More fixes in queue, better options handler.
24
25
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
26
def main():
27
    parser = OptionParser()
4898.1.1 by Julian Edwards
Change the ftpmaster queue tool to use PackageUpload.notify() for sending
28
    logger_options(parser)
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
29
30
    parser.add_option("-Q", "--queue",
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
31
                      dest="queue_name", metavar="QUEUE", default="new",
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
32
                      help="Which queue to consider")
2865.2.36 by Celso Providelo
Implementing queue script support for receiving a bunch of simultaneous commands from a file.
33
3500.3.39 by Celso Providelo
Fix bug #59280 (add suite support in queue tool)
34
    parser.add_option("-d", "--distribution",
35
                      dest="distribution_name", metavar="DISTRO", default=None,
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
36
                      help="Which distro to look in")
2865.2.36 by Celso Providelo
Implementing queue script support for receiving a bunch of simultaneous commands from a file.
37
3500.3.39 by Celso Providelo
Fix bug #59280 (add suite support in queue tool)
38
    parser.add_option("-s", "--suite",
39
                      dest="suite_name", metavar="DISTRORELEASE",
3048.5.6 by Celso Providelo
Add missed test file, queue tool defaults to 'ubuntu' and its currentrelease.
40
                      default=None,
41
                      help=("Which distrorelease to look in, defaults "
3691.312.37 by Celso Providelo
Quick fix for bug #121519 (missing bits of distrorelease\distroseries rename in untested scripts).
42
                            "to distribution 'currentseries'."))
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
43
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.")
47
3048.5.2 by Celso Providelo
Queue tool sending email when accepting new packages, added a test for the entire script.
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.")
51
2865.2.35 by Celso Providelo
Implementing exact_match support for IDistroRelease.getSourceQueueItem() and queue scritp itself, tests and fixes.
52
    parser.add_option("-e", "--exact-match", action="store_true",
53
                      dest="exact_match", metavar="EXACTMATCH",
54
                      default=False,
55
                      help="Whether treat filter as a exact match or not.")
56
2865.2.64 by Celso Providelo
Fix queue tool for ignore error when performing a list of actions, fix DRQ acceptation to properly treat architecture independance.
57
    parser.add_option("-i", "--ignore-errors", action="store_true",
58
                      dest="ignore_errors", metavar="IGNOREERRORS",
59
                      default=False,
60
                      help="Ignore errors when performing a list of commands.")
61
2865.2.36 by Celso Providelo
Implementing queue script support for receiving a bunch of simultaneous commands from a file.
62
    parser.add_option("-f", "--file", metavar="FILE", default=None,
63
                      help="file containing a sequence of command lines.")
64
4500.1.1 by Julian Edwards
First cut, probably broken, completely untested.
65
    parser.add_option("-c", "--component", dest="component_name",
66
                      metavar="COMPONENT", default=None,
67
                      help="When overriding, move package to COMPONENT")
68
69
    parser.add_option("-x", "--section", dest="section_name",
70
                      metavar="SECTION", default=None,
71
                      help="When overriding, move package to SECTION")
72
73
    parser.add_option("-p", "--priority", dest="priority_name",
74
                      metavar="PRIORITY", default=None,
75
                      help="When overriding, move package to PRIORITY")
76
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
77
    options, args = parser.parse_args()
4898.1.1 by Julian Edwards
Change the ftpmaster queue tool to use PackageUpload.notify() for sending
78
    log = logger(options, "ftpmaster.queue")
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
79
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
80
    if options.queue_name not in name_queue_map:
3691.226.1 by Malcolm Cleaton
Fix exception when trying to display error when queue cannot be found by name.
81
        print 'Unable to map queue name "%s"' % options.queue_name
3048.5.11 by Celso Providelo
More fixes in queue, better options handler.
82
        return 1
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
83
3048.5.11 by Celso Providelo
More fixes in queue, better options handler.
84
    no_mail = options.dryrun or options.nomail
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
85
    queue = name_queue_map[options.queue_name]
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
86
2865.2.36 by Celso Providelo
Implementing queue script support for receiving a bunch of simultaneous commands from a file.
87
    if options.file:
88
        args_list = [args.strip().split() for args in
89
                     open(options.file).readlines()]
90
    else:
91
        args_list = [args]
92
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
93
    cmd_runner = CommandRunner(
4500.1.3 by Julian Edwards
Seems to work now. Tests need writing.
94
        queue, options.distribution_name, options.suite_name,
13144.1.3 by Steve Kowalik
Drop -A from queue and clean it up.
95
        no_mail, options.component_name, options.section_name,
96
        options.priority_name, log=log)
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
97
13194.2.1 by Gavin Panella
Change all uses of 'initialise' to 'initialize'.
98
    print ("Initializing connection to queue %s" % options.queue_name)
3500.3.38 by Celso Providelo
applying review comments, moved code from scripts/ftpmaster/queue to l/scripts/queue.py library and setup a dedicated ftest with a dedicated test for fix to bug #59291.
99
5821.5.18 by James Henstridge
fix a few more tools that did initZopeless before execute_zcml_for_scripts
100
    execute_zcml_for_scripts()
5842.1.1 by James Henstridge
Rename the transaction isolation level constants to match the psycopg2
101
    ztm = initZopeless(dbuser=config.uploadqueue.dbuser,
102
                       isolation=ISOLATION_LEVEL_READ_COMMITTED)
3048.5.2 by Celso Providelo
Queue tool sending email when accepting new packages, added a test for the entire script.
103
2865.2.36 by Celso Providelo
Implementing queue script support for receiving a bunch of simultaneous commands from a file.
104
    for single_args in args_list:
3048.5.11 by Celso Providelo
More fixes in queue, better options handler.
105
        try:
4500.1.1 by Julian Edwards
First cut, probably broken, completely untested.
106
            cmd_runner.execute(single_args, options.exact_match)
3048.5.11 by Celso Providelo
More fixes in queue, better options handler.
107
        except CommandRunnerError, info:
108
            print (info)
4500.1.1 by Julian Edwards
First cut, probably broken, completely untested.
109
            if options.ignore_errors:
2865.2.64 by Celso Providelo
Fix queue tool for ignore error when performing a list of actions, fix DRQ acceptation to properly treat architecture independance.
110
                continue
3048.5.11 by Celso Providelo
More fixes in queue, better options handler.
111
            ztm.abort()
112
            print 'Aborting current transaction'
2865.2.36 by Celso Providelo
Implementing queue script support for receiving a bunch of simultaneous commands from a file.
113
            return 1
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.
114
        else:
3048.5.11 by Celso Providelo
More fixes in queue, better options handler.
115
            if not options.dryrun:
116
                ztm.commit()
117
            else:
118
                print "DRY RUN requested, not committing."
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.
119
120
    return 0
121
3048.5.10 by Celso Providelo
Improving ftpmaster queue tool
122
2865.2.32 by Celso Providelo
Landing redesigned ftp-master/queue.py, sample deb packages for soyuz-uploads and missed test file for binarypackagerelease.
123
if __name__ == '__main__':
124
    sys.exit(main())