diff options
Diffstat (limited to 'lib/spack/spack/cmd/clean.py')
-rw-r--r-- | lib/spack/spack/cmd/clean.py | 57 |
1 files changed, 48 insertions, 9 deletions
diff --git a/lib/spack/spack/cmd/clean.py b/lib/spack/spack/cmd/clean.py index b7812bffc4..634e20b4e4 100644 --- a/lib/spack/spack/cmd/clean.py +++ b/lib/spack/spack/cmd/clean.py @@ -29,21 +29,60 @@ import llnl.util.tty as tty import spack import spack.cmd -description = "remove build stage and source tarball for packages" +description = "remove temporary build files and/or downloaded archives" section = "build" level = "long" +class AllClean(argparse.Action): + """Activates flags -s -d and -m simultaneously""" + def __call__(self, parser, namespace, values, option_string=None): + parser.parse_args(['-sdm'], namespace=namespace) + + def setup_parser(subparser): - subparser.add_argument('packages', nargs=argparse.REMAINDER, - help="specs of packages to clean") + subparser.add_argument( + '-s', '--stage', action='store_true', + help="remove all temporary build stages (default)") + subparser.add_argument( + '-d', '--downloads', action='store_true', + help="remove cached downloads") + subparser.add_argument( + '-m', '--misc-cache', action='store_true', + help="remove long-lived caches, like the virtual package index") + subparser.add_argument( + '-a', '--all', action=AllClean, help="equivalent to -sdm", nargs=0 + ) + subparser.add_argument( + 'specs', + nargs=argparse.REMAINDER, + help="removes the build stages and tarballs for specs" + ) def clean(parser, args): - if not args.packages: - tty.die("spack clean requires at least one package spec.") - specs = spack.cmd.parse_specs(args.packages, concretize=True) - for spec in specs: - package = spack.repo.get(spec) - package.do_clean() + # If nothing was set, activate the default + if not any([args.specs, args.stage, args.downloads, args.misc_cache]): + args.stage = True + + # Then do the cleaning falling through the cases + if args.specs: + specs = spack.cmd.parse_specs(args.specs, concretize=True) + for spec in specs: + msg = 'Cleaning build stage [{0}]' + tty.msg(msg.format(spec.short_spec)) + package = spack.repo.get(spec) + package.do_clean() + + if args.stage: + tty.msg('Removing all temporary build stages') + spack.stage.purge() + + if args.downloads: + tty.msg('Removing cached downloads') + spack.fetch_cache.destroy() + + if args.misc_cache: + tty.msg('Removing cached information on repositories') + spack.misc_cache.destroy() |