Merge lp:~tsimonq2/ubuntu-archive-tools/skip-missing-remove-package into lp:ubuntu-archive-tools

Proposed by Simon Quigley
Status: Merged
Merged at revision: 1178
Proposed branch: lp:~tsimonq2/ubuntu-archive-tools/skip-missing-remove-package
Merge into: lp:ubuntu-archive-tools
Diff against target: 51 lines (+19/-9)
1 file modified
remove-package (+19/-9)
To merge this branch: bzr merge lp:~tsimonq2/ubuntu-archive-tools/skip-missing-remove-package
Reviewer Review Type Date Requested Status
Colin Watson Approve
Review via email: mp+351370@code.launchpad.net

Commit message

Add a --skip-missing flag to remove-package.

Description of the change

12:02:31 PM < Lord-Kamina> My humble feedback: You guys really need to make it so remove-package doesn't auto-exit if it can't find a package name when you've provided a bunch of them.
12:04:16 PM < Lord-Kamina> For whatever reason, it won't find all package names shown in the web interface (don't know if that's a bug on the web interface or on package-remove) and when it doesn't find any package, it quits without checking the rest. So it ends up being a sysiphean task, running the script fifty times while removing one or two packages from the command each time. :P

Not that we always take feedback from IRC or anything...

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

This doesn't achieve the requested result. The exception handler here is outside the loop, so it will skip everything from the point of the failure and then carry on.

I think you need an extra exception handler in find_all_removables instead.

review: Needs Fixing
1179. By Simon Quigley

Remove the lputils.PackageMissing exception handling up a bit.

Revision history for this message
Colin Watson (cjwatson) :
review: Needs Fixing
1180. By Simon Quigley

options, not args.

1181. By Simon Quigley

options, not argument.

Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'remove-package'
2--- remove-package 2015-08-08 00:31:04 +0000
3+++ remove-package 2018-07-26 18:23:28 +0000
4@@ -48,21 +48,25 @@
5
6 def find_all_removables(options, packages):
7 for package in packages:
8- for removable in find_removables(options, package):
9- yield removable
10+ try:
11+ for removable in find_removables(options, package):
12+ yield removable
13+ except lputils.PackageMissing as message:
14+ print(message)
15+ if options.skip_missing:
16+ print("Skipping")
17+ else:
18+ print("Exiting")
19+ sys.exit(1)
20
21
22 def remove_package(options, packages):
23 removables = []
24
25 print("Removing packages from %s:" % options.suite)
26- try:
27- for removable, direct in find_all_removables(options, packages):
28- removables.append((removable, direct))
29- print("\t%s%s" % ("" if direct else "\t", removable.display_name))
30- except lputils.PackageMissing as message:
31- print(message, ". Exiting.")
32- sys.exit(1)
33+ for removable, direct in find_all_removables(options, packages):
34+ removables.append((removable, direct))
35+ print("\t%s%s" % ("" if direct else "\t", removable.display_name))
36 print("Comment: %s" % options.removal_comment)
37
38 if options.dry_run:
39@@ -109,6 +113,12 @@
40 "-b", "--binary", dest="binaryonly",
41 default=False, action="store_true", help="remove binaries only")
42 parser.add_option("-m", "--removal-comment", help="removal comment")
43+ parser.add_option(
44+ "--skip-missing", default=False, action="store_true",
45+ help=(
46+ "When a package cannot be removed, normally this script exits "
47+ "with a non-zero status. With --skip-missing instead, the "
48+ "error is printed and removing continues"))
49
50 # Deprecated in favour of -A.
51 parser.add_option(

Subscribers

People subscribed via source and target branches