~xnox/ubuntu-archive-tools/riscv64

1285 by Sebastien Bacher
Switch some of the script to use python3 so they work on focal
1
#! /usr/bin/python3
748 by Colin Watson
demote-to-proposed: new script (still a bit rough due to LP bugs)
2
3
# Copyright (C) 2013  Canonical Ltd.
4
# Author: Colin Watson <cjwatson@ubuntu.com>
5
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; version 3 of the License.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18
"""Demote packages to proposed pocket.
19
20
This is useful in the case where a package fails to build or is otherwise
21
broken, but we don't want to remove it from the archive permanently and
22
would be happy to take a fix by way of a sync from Debian or similar.  In
23
cases where the package comes from Debian, make sure that any demotion to
24
proposed is accompanied by a Debian bug report.
25
26
This is analogous to removing a package from Debian testing.
27
"""
28
29
from __future__ import print_function
30
31
from optparse import OptionParser
32
import sys
33
34
from launchpadlib.launchpad import Launchpad
35
from ubuntutools.question import YesNoQuestion
36
37
import lputils
38
39
40
def demote(options, packages):
41
    print("Demoting packages to %s-proposed:" % options.suite)
42
    try:
43
        demotables = []
44
        for package in packages:
45
            source = lputils.find_latest_published_source(options, package)
46
            demotables.append(source)
47
            print("\t%s" % source.display_name)
48
    except lputils.PackageMissing as message:
49
        print(message, ".  Exiting.")
50
        sys.exit(1)
51
    print("Comment: %s" % options.comment)
52
53
    if options.dry_run:
54
        print("Dry run; no packages demoted.")
55
    else:
56
        if not options.confirm_all:
57
            if YesNoQuestion().ask("Demote", "no") == "no":
58
                return
59
60
        for source in demotables:
61
            options.archive.copyPackage(
62
                source_name=source.source_package_name,
63
                version=source.source_package_version,
64
                from_archive=options.archive,
65
                from_series=options.series.name, from_pocket="Release",
66
                to_series=options.series.name, to_pocket="Proposed",
67
                include_binaries=True, auto_approve=True)
68
            if not options.confirm_all:
851 by Colin Watson
demote-to-proposed: make prompts clearer when demoting multiple packages
69
                if YesNoQuestion().ask(
70
                        "Remove %s from release" % source.source_package_name,
71
                        "no") == "no":
748 by Colin Watson
demote-to-proposed: new script (still a bit rough due to LP bugs)
72
                    continue
73
            source.requestDeletion(removal_comment=options.comment)
74
75
        print("%d %s successfully demoted." % (
76
            len(demotables),
77
            "package" if len(demotables) == 1 else "packages"))
78
79
80
def main():
81
    parser = OptionParser(
82
        usage='usage: %prog -m "comment" [options] package [...]')
83
    parser.add_option(
84
        "-l", "--launchpad", dest="launchpad_instance", default="production")
85
    parser.add_option(
86
        "-n", "--dry-run", default=False, action="store_true",
87
        help="only show demotions that would be performed")
88
    parser.add_option(
89
        "-y", "--confirm-all", default=False, action="store_true",
90
        help="do not ask for confirmation")
91
    parser.add_option(
92
        "-d", "--distribution", default="ubuntu",
93
        metavar="DISTRIBUTION", help="demote from DISTRIBUTION")
94
    parser.add_option(
95
        "-s", "--suite", metavar="SUITE", help="demote from SUITE")
96
    parser.add_option(
97
        "-e", "--version",
98
        metavar="VERSION", help="package version (default: current version)")
99
    parser.add_option("-m", "--comment", help="demotion comment")
100
    options, args = parser.parse_args()
101
102
    options.launchpad = Launchpad.login_with(
103
        "demote-to-proposed", options.launchpad_instance, version="devel")
104
    lputils.setup_location(options)
105
106
    if options.comment is None:
107
        parser.error("You must provide a comment/reason for all demotions.")
108
109
    demote(options, args)
110
111
112
if __name__ == '__main__':
113
    main()