diff options
author | Brett Viren <brett.viren@gmail.com> | 2016-02-24 12:19:06 +0100 |
---|---|---|
committer | Brett Viren <bv@bnl.gov> | 2016-04-28 14:54:14 -0400 |
commit | 49956faab97e2dea52371755d0fcb9b013567ac7 (patch) | |
tree | 013ccb388233b0d31b2a048f4844b9205009e853 | |
parent | 1b731e525f42f2c90f82ab442867a28168d44db5 (diff) | |
download | spack-49956faab97e2dea52371755d0fcb9b013567ac7.tar.gz spack-49956faab97e2dea52371755d0fcb9b013567ac7.tar.bz2 spack-49956faab97e2dea52371755d0fcb9b013567ac7.tar.xz spack-49956faab97e2dea52371755d0fcb9b013567ac7.zip |
First try to make file system views of specs.
-rw-r--r-- | lib/spack/spack/cmd/view.py | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/lib/spack/spack/cmd/view.py b/lib/spack/spack/cmd/view.py new file mode 100644 index 0000000000..c7f1c21f67 --- /dev/null +++ b/lib/spack/spack/cmd/view.py @@ -0,0 +1,108 @@ +############################################################################## +# 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://github.com/llnl/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 +import argparse + +import spack +import spack.cmd +import llnl.util.tty as tty + +description = "Produce a single-rooted directory view of a spec." + +def setup_parser(subparser): + setup_parser.parser = subparser + + subparser.add_argument('prefix', nargs=1, + help="Path to top-level directory for the view.") + subparser.add_argument('specs', nargs=argparse.REMAINDER, + help="specs of packages to expose in the view.") + +def assuredir(path): + 'Assure path exists as a directory' + if not os.path.exists(path): + os.makedirs(path) + +def relative_to(prefix, path): + assert 0 == path.find(prefix) + reldir = path[len(prefix):] + if reldir.startswith('/'): + reldir = reldir[1:] + return reldir + +def view_one(prefix, spec): + print spec.name,spec.prefix + + dotspack = os.path.join(prefix, '.spack', spec.name) + + if os.path.exists(os.path.join(dotspack)): + tty.warn("Skipping previously added package %s"%spec.name) + return + + + for dirpath,dirnames,filenames in os.walk(spec.prefix): + if not filenames: + continue # avoid explicitly making empty dirs + + reldir = relative_to(spec.prefix, dirpath) + + # fixme: assumes .spack has no subdirs + if dirpath.endswith('.spack'): + targdir = dotspack + else: + targdir = os.path.join(prefix, reldir) + + assuredir(targdir) + + print '\t%s...'%reldir, + nlinks = 0 + for fname in filenames: + src = os.path.join(dirpath, fname) + dst = os.path.join(targdir, fname) + if os.path.exists(dst): + tty.warn("Skipping existing file for view: %s" % dst) + continue + os.symlink(src,dst) + nlinks += 1 + print nlinks + + +def view(parser, args): + # if not args.specs: + # tty.die("view creation requires at least one spec argument") + + specs = spack.cmd.parse_specs(args.specs, normalize=True, concretize=True) + if not specs: + setup_parser.parser.print_help() + return 1 + + prefix = args.prefix[0] + assuredir(prefix) + + flat = set() + for spec in specs: + flat.update(spec.normalized().traverse()) + + for spec in flat: + view_one(prefix, spec) |