Add spack cd and spack location commands.
- Better shell support for cd'ing into directories - Fix some csh weirdness with nested aliases.
This commit is contained in:
38
lib/spack/spack/cmd/cd.py
Normal file
38
lib/spack/spack/cmd/cd.py
Normal file
@@ -0,0 +1,38 @@
|
||||
##############################################################################
|
||||
# Copyright (c) 2013, Lawrence Livermore National Security, LLC.
|
||||
# Produced at the Lawrence Livermore National Laboratory.
|
||||
#
|
||||
# This file is part of Spack.
|
||||
# Written by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
|
||||
# LLNL-CODE-647188
|
||||
#
|
||||
# For details, see https://scalability-llnl.github.io/spack
|
||||
# Please also see the LICENSE file for our notice and the LGPL.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License (as published by
|
||||
# the Free Software Foundation) version 2.1 dated February 1999.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
|
||||
# conditions of the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
##############################################################################
|
||||
import spack.cmd.location
|
||||
import spack.modules
|
||||
|
||||
description="cd to spack directories in the shell."
|
||||
|
||||
def setup_parser(subparser):
|
||||
"""This is for decoration -- spack cd is used through spack's
|
||||
shell support. This allows spack cd to print a descriptive
|
||||
help message when called with -h."""
|
||||
spack.cmd.location.setup_parser(subparser)
|
||||
|
||||
|
||||
def cd(parser, args):
|
||||
spack.modules.print_help()
|
93
lib/spack/spack/cmd/location.py
Normal file
93
lib/spack/spack/cmd/location.py
Normal file
@@ -0,0 +1,93 @@
|
||||
##############################################################################
|
||||
# Copyright (c) 2013, Lawrence Livermore National Security, LLC.
|
||||
# Produced at the Lawrence Livermore National Laboratory.
|
||||
#
|
||||
# This file is part of Spack.
|
||||
# Written by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
|
||||
# LLNL-CODE-647188
|
||||
#
|
||||
# For details, see https://scalability-llnl.github.io/spack
|
||||
# Please also see the LICENSE file for our notice and the LGPL.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License (as published by
|
||||
# the Free Software Foundation) version 2.1 dated February 1999.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
|
||||
# conditions of the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
##############################################################################
|
||||
import os
|
||||
from external import argparse
|
||||
|
||||
import llnl.util.tty as tty
|
||||
from llnl.util.filesystem import join_path
|
||||
|
||||
import spack
|
||||
import spack.cmd
|
||||
|
||||
description="Print out locations of various diectories used by Spack"
|
||||
|
||||
def setup_parser(subparser):
|
||||
global directories
|
||||
directories = subparser.add_mutually_exclusive_group()
|
||||
|
||||
directories.add_argument(
|
||||
'-m', '--module-dir', action='store_true', help="Spack python module directory.")
|
||||
directories.add_argument(
|
||||
'-r', '--spack-root', action='store_true', help="Spack installation root.")
|
||||
|
||||
directories.add_argument(
|
||||
'-i', '--install-dir', action='store_true',
|
||||
help="Install prefix for spec (spec need not be installed).")
|
||||
directories.add_argument(
|
||||
'-p', '--package-dir', action='store_true',
|
||||
help="Directory enclosing a spec's package.py file.")
|
||||
directories.add_argument(
|
||||
'-s', '--stage-dir', action='store_true', help="Stage directory for a spec.")
|
||||
directories.add_argument(
|
||||
'-b', '--build-dir', action='store_true',
|
||||
help="Expanded archive directory for a spec (requires it to be staged first).")
|
||||
|
||||
subparser.add_argument(
|
||||
'spec', nargs=argparse.REMAINDER, help="spec of package to fetch directory for.")
|
||||
|
||||
|
||||
def location(parser, args):
|
||||
if args.module_dir:
|
||||
print spack.module_path
|
||||
|
||||
elif args.spack_root:
|
||||
print spack.prefix
|
||||
|
||||
else:
|
||||
specs = spack.cmd.parse_specs(args.spec, concretize=True)
|
||||
if not specs:
|
||||
tty.die("You must supply a spec.")
|
||||
if len(specs) != 1:
|
||||
tty.die("Too many specs. Need only one.")
|
||||
spec = specs[0]
|
||||
|
||||
if args.install_dir:
|
||||
print spec.prefix
|
||||
|
||||
elif args.package_dir:
|
||||
print join_path(spack.db.root, spec.name)
|
||||
|
||||
else:
|
||||
pkg = spack.db.get(spec)
|
||||
|
||||
if args.stage_dir:
|
||||
print pkg.stage.path
|
||||
|
||||
else: # args.build_dir is the default.
|
||||
if not os.listdir(pkg.stage.path):
|
||||
tty.die("Build directory does not exist yet. Run this to create it:",
|
||||
"spack stage " + " ".join(args.spec))
|
||||
print pkg.stage.expanded_archive_path
|
||||
|
@@ -41,7 +41,7 @@
|
||||
from spack.util.compression import extension
|
||||
|
||||
|
||||
description = "Manage spack mirrors."
|
||||
description = "Manage mirrors."
|
||||
|
||||
def setup_parser(subparser):
|
||||
subparser.add_argument(
|
||||
|
@@ -37,13 +37,6 @@ def setup_parser(subparser):
|
||||
help="Do not check downloaded packages against checksum")
|
||||
|
||||
dir_parser = subparser.add_mutually_exclusive_group()
|
||||
dir_parser.add_argument(
|
||||
'-d', '--print-stage-dir', action='store_const', dest='print_dir',
|
||||
const='print_stage', help="Prints out the stage directory for a spec.")
|
||||
dir_parser.add_argument(
|
||||
'-b', '--print-build-dir', action='store_const', dest='print_dir',
|
||||
const='print_build', help="Prints out the expanded archive path for a spec.")
|
||||
|
||||
subparser.add_argument(
|
||||
'specs', nargs=argparse.REMAINDER, help="specs of packages to stage")
|
||||
|
||||
@@ -56,24 +49,7 @@ def stage(parser, args):
|
||||
spack.do_checksum = False
|
||||
|
||||
specs = spack.cmd.parse_specs(args.specs, concretize=True)
|
||||
|
||||
if args.print_dir:
|
||||
if len(specs) != 1:
|
||||
tty.die("--print-stage-dir and --print-build-dir options only take one spec.")
|
||||
|
||||
spec = specs[0]
|
||||
pkg = spack.db.get(spec)
|
||||
|
||||
if args.print_dir == 'print_stage':
|
||||
print pkg.stage.path
|
||||
elif args.print_dir == 'print_build':
|
||||
if not os.listdir(pkg.stage.path):
|
||||
tty.die("Stage directory is empty. Run this first:",
|
||||
"spack stage " + " ".join(args.specs))
|
||||
print pkg.stage.expanded_archive_path
|
||||
|
||||
else:
|
||||
for spec in specs:
|
||||
package = spack.db.get(spec)
|
||||
package.do_stage()
|
||||
for spec in specs:
|
||||
package = spack.db.get(spec)
|
||||
package.do_stage()
|
||||
|
||||
|
@@ -64,10 +64,10 @@
|
||||
def print_help():
|
||||
"""For use by commands to tell user how to activate shell support."""
|
||||
|
||||
tty.msg("Spack module/dotkit support is not initialized.",
|
||||
tty.msg("This command requires spack's shell integration.",
|
||||
"",
|
||||
"To use dotkit or modules with Spack, you must first run",
|
||||
"one of the commands below. You can copy/paste them.",
|
||||
"To initialize spack's shell commands, you must run one of",
|
||||
"the commands below. Choose the right command for your shell.",
|
||||
"",
|
||||
"For bash and zsh:",
|
||||
" . %s/setup-env.sh" % spack.share_path,
|
||||
|
Reference in New Issue
Block a user