uninstall : permits to uninstall all installed software fixes #1477 (#1973)

This commit is contained in:
Massimiliano Culpo 2016-10-11 09:42:31 +02:00 committed by Todd Gamblin
parent c8bf8a5e6e
commit b1a2728af6

View File

@ -54,9 +54,10 @@ def setup_parser(subparser):
subparser.add_argument( subparser.add_argument(
'-a', '--all', action='store_true', dest='all', '-a', '--all', action='store_true', dest='all',
help="USE CAREFULLY. Remove ALL installed packages that match each " help="USE CAREFULLY. Remove ALL installed packages that match each "
"supplied spec. i.e., if you say uninstall libelf, ALL versions " "supplied spec. i.e., if you say uninstall `libelf`,"
"of libelf are uninstalled. This is both useful and dangerous, " " ALL versions of `libelf` are uninstalled. If no spec is "
"like rm -r.") "supplied all installed software will be uninstalled. This "
"is both useful and dangerous, like rm -r.")
subparser.add_argument( subparser.add_argument(
'-d', '--dependents', action='store_true', dest='dependents', '-d', '--dependents', action='store_true', dest='dependents',
@ -157,18 +158,15 @@ def num_installed_deps(pkg):
item.do_uninstall(force=force) item.do_uninstall(force=force)
def uninstall(parser, args): def get_uninstall_list(args):
if not args.packages: specs = [any]
tty.die("uninstall requires at least one package argument.") if args.packages:
with spack.installed_db.write_transaction():
specs = spack.cmd.parse_specs(args.packages) specs = spack.cmd.parse_specs(args.packages)
# Gets the list of installed specs that match the ones give via cli # Gets the list of installed specs that match the ones give via cli
# takes care of '-a' is given in the cli # takes care of '-a' is given in the cli
uninstall_list = concretize_specs(specs, args.all, args.force) uninstall_list = concretize_specs(specs, args.all, args.force)
dependent_list = installed_dependents( # Takes care of '-d'
uninstall_list) # takes care of '-d' dependent_list = installed_dependents(uninstall_list)
# Process dependent_list and update uninstall_list # Process dependent_list and update uninstall_list
has_error = False has_error = False
if dependent_list and not args.dependents and not args.force: if dependent_list and not args.dependents and not args.force:
@ -184,11 +182,21 @@ def uninstall(parser, args):
for key, lst in dependent_list.items(): for key, lst in dependent_list.items():
uninstall_list.extend(lst) uninstall_list.extend(lst)
uninstall_list = list(set(uninstall_list)) uninstall_list = list(set(uninstall_list))
if has_error: if has_error:
tty.die('You can use spack uninstall --dependents ' tty.die('You can use spack uninstall --dependents '
'to uninstall these dependencies as well') 'to uninstall these dependencies as well')
return uninstall_list
def uninstall(parser, args):
if not args.packages and not args.all:
tty.die("uninstall requires at least one package argument.")
with spack.installed_db.write_transaction():
uninstall_list = get_uninstall_list(args)
if not args.yes_to_all: if not args.yes_to_all:
tty.msg("The following packages will be uninstalled : ") tty.msg("The following packages will be uninstalled : ")
print('') print('')