diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2014-02-10 09:07:24 -0800 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2014-02-10 09:07:24 -0800 |
commit | c9dc4636ccb8bf92ecc5b96c2036e51d60a147f8 (patch) | |
tree | 3861640c05e2417becf9946fbff537b69726fcb3 /lib | |
parent | 93e80852f579a9faa55eb326e3a2fb5b98800389 (diff) | |
download | spack-c9dc4636ccb8bf92ecc5b96c2036e51d60a147f8.tar.gz spack-c9dc4636ccb8bf92ecc5b96c2036e51d60a147f8.tar.bz2 spack-c9dc4636ccb8bf92ecc5b96c2036e51d60a147f8.tar.xz spack-c9dc4636ccb8bf92ecc5b96c2036e51d60a147f8.zip |
Command to create spack mirrors.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/cmd/mirror.py | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/lib/spack/spack/cmd/mirror.py b/lib/spack/spack/cmd/mirror.py new file mode 100644 index 0000000000..77cbb1eb58 --- /dev/null +++ b/lib/spack/spack/cmd/mirror.py @@ -0,0 +1,88 @@ +############################################################################## +# 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 +import argparse + +import spack.packages as packages +import spack.cmd +import spack.tty as tty + +from spack.stage import Stage +from spack.util.filesystem import mkdirp, new_path + +description = "Create a directory full of package tarballs that can be used as a spack mirror." + +def setup_parser(subparser): + subparser.add_argument( + 'directory', help="Directory in which to create mirror.") + subparser.add_argument( + 'packages', nargs=argparse.REMAINDER, help="names of packages to put in mirror") + + +def mirror(parser, args): + if not args.packages: + args.packages = [p for p in packages.all_package_names()] + + if os.path.isfile(args.directory): + tty.error("%s already exists and is a file." % args.directory) + + if not os.path.isdir(args.directory): + mkdirp(args.directory) + + # save working directory + working_dir = os.getcwd() + + # Iterate through packages and download all the safe tarballs for each of them + for pkg_name in args.packages: + pkg = packages.get(pkg_name) + + # Skip any package that has no checksummed versions. + if not pkg.versions: + tty.msg("No safe (checksummed) versions for package %s. Skipping." + % pkg_name) + continue + + # create a subdir for the current package. + pkg_path = new_path(args.directory, pkg_name) + mkdirp(pkg_path) + + # Download all the tarballs using Stages, then move them into place + for version in pkg.versions: + url = pkg.url_for_version(version) + stage = Stage(url) + try: + stage.fetch() + basename = os.path.basename(stage.archive_file) + final_dst = new_path(pkg_path, basename) + + os.chdir(working_dir) + os.rename(stage.archive_file, final_dst) + tty.msg("Added %s to mirror" % final_dst) + + finally: + stage.destroy() + + # Success! + tty.msg("Created Spack mirror in %s" % args.directory) |