3
# Copyright 2012 Canonical Ltd.
4
# Author: Colin Watson <cjwatson@ubuntu.com>
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.
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.
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/>.
18
"""Override a publication."""
20
from __future__ import print_function
22
from collections import OrderedDict
23
from optparse import OptionParser, SUPPRESS_HELP
25
from launchpadlib.launchpad import Launchpad
26
from ubuntutools.question import YesNoQuestion
31
def find_publications(options, packages):
32
for package in packages:
33
# Change matching source.
34
if (options.source_and_binary or options.binary_and_source or
36
source = lputils.find_latest_published_source(options, package)
37
yield "source", source
39
# Change all binaries for matching source.
40
if options.source_and_binary:
41
for binary in source.getPublishedBinaries():
42
if not binary.is_debug:
43
yield "binary", binary
44
# Change matching binaries.
45
elif not options.source_only:
46
for binary in lputils.find_latest_published_binaries(
48
if not binary.is_debug:
49
yield "binary", binary
52
def stringify_phased_update_percentage(phased_update_percentage):
53
if phased_update_percentage is None:
56
return '%s%%' % phased_update_percentage
59
def stringify_binary_kwargs(binary_kwargs):
60
for key, value in binary_kwargs.items():
61
if key == "new_phased_update_percentage":
62
yield stringify_phased_update_percentage(value)
67
def change_overrides(options, packages):
68
source_kwargs = OrderedDict()
69
binary_kwargs = OrderedDict()
71
print("Override component to %s" % options.component)
72
source_kwargs["new_component"] = options.component
73
binary_kwargs["new_component"] = options.component
75
print("Override section to %s" % options.section)
76
source_kwargs["new_section"] = options.section
77
binary_kwargs["new_section"] = options.section
79
print("Override priority to %s" % options.priority)
80
binary_kwargs["new_priority"] = options.priority
81
if options.percentage is not None:
82
print("Override percentage to %s" % options.percentage)
83
binary_kwargs["new_phased_update_percentage"] = options.percentage
86
for pubtype, publication in find_publications(options, packages):
87
if pubtype == "source" and not source_kwargs:
90
publications.append((pubtype, publication))
92
if pubtype == "source":
93
print("%s: %s/%s -> %s" % (
94
publication.display_name,
95
publication.component_name, publication.section_name,
96
"/".join(source_kwargs.values())))
98
print("%s: %s/%s/%s/%s -> %s" % (
99
publication.display_name,
100
publication.component_name, publication.section_name,
101
publication.priority_name.lower(),
102
stringify_phased_update_percentage(
103
publication.phased_update_percentage),
104
"/".join(stringify_binary_kwargs(binary_kwargs))))
107
print("Dry run; no publications overridden.")
109
if not options.confirm_all:
110
if YesNoQuestion().ask("Override", "no") == "no":
115
for pubtype, publication in publications:
116
if pubtype == "source":
117
kwargs = source_kwargs
119
kwargs = binary_kwargs
120
if publication.changeOverride(**kwargs):
123
print("%s remained the same" % publication.display_name)
128
summary.append("%d %s overridden" % (
130
"publication" if num_overridden == 1 else "publications"))
132
summary.append("%d %s remained the same" % (
133
num_same, "publication" if num_same == 1 else "publications"))
135
print("%s." % "; ".join(summary))
139
parser = OptionParser(
140
usage="usage: %prog -s suite [options] package [...]",
141
epilog=lputils.ARCHIVE_REFERENCE_DESCRIPTION)
143
"-l", "--launchpad", dest="launchpad_instance", default="production")
145
"-n", "--dry-run", default=False, action="store_true",
146
help="only show removals that would be performed")
148
"-y", "--confirm-all", default=False, action="store_true",
149
help="do not ask for confirmation")
150
parser.add_option("-A", "--archive", help="override in ARCHIVE")
152
"-s", "--suite", metavar="SUITE", help="override in SUITE")
154
"-a", "--architecture", dest="architectures", action="append",
155
metavar="ARCHITECTURE",
156
help="architecture tag (may be given multiple times)")
159
metavar="VERSION", help="package version (default: current version)")
161
"-S", "--source-and-binary", default=False, action="store_true",
162
help="select source and all binaries from this source")
164
"-B", "--binary-and-source", default=False, action="store_true",
165
help="select source and binary (of the same name)")
167
"-t", "--source-only", default=False, action="store_true",
168
help="select source packages only")
171
metavar="COMPONENT", help="move package to COMPONENT")
174
metavar="PRIORITY", help="move package to PRIORITY")
177
metavar="SECTION", help="move package to SECTION")
179
"-z", "--percentage", type="int", default=None,
180
metavar="PERCENTAGE", help="set phased update percentage")
182
# Deprecated in favour of -A.
184
"-d", "--distribution", default="ubuntu", help=SUPPRESS_HELP)
186
"-j", "--partner", default=False, action="store_true",
188
options, args = parser.parse_args()
190
if (not options.component and not options.section and not options.priority
191
and options.percentage is None):
193
"You must override at least one of component, section, "
194
"priority, and percentage.")
196
options.launchpad = Launchpad.login_with(
197
"change-override", options.launchpad_instance, version="devel")
198
lputils.setup_location(options)
200
change_overrides(options, args)
203
if __name__ == '__main__':