Fix SPACK-27 & remove dependence on check_output

- subprocess.check_output is python 2.7 only
- Spack checks for existence of requested prefix, creates it if it does not exist.
This commit is contained in:
Todd Gamblin 2014-08-10 11:52:17 -07:00
parent 7714d08e2e
commit 5a5da817a1

View File

@ -23,12 +23,13 @@
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
import os import os
from subprocess import check_call, check_output from subprocess import check_call
import llnl.util.tty as tty import llnl.util.tty as tty
from llnl.util.filesystem import join_path from llnl.util.filesystem import join_path, mkdirp
import spack import spack
from spack.util.executable import which
description = "Create a new installation of spack in another prefix" description = "Create a new installation of spack in another prefix"
@ -38,8 +39,10 @@ def setup_parser(subparser):
def get_origin_url(): def get_origin_url():
git_dir = join_path(spack.prefix, '.git') git_dir = join_path(spack.prefix, '.git')
origin_url = check_output( git = which('git', required=True)
['git', '--git-dir=%s' % git_dir, 'config', '--get', 'remote.origin.url']) origin_url = git(
'--git-dir=%s' % git_dir, 'config', '--get', 'remote.origin.url',
return_output=True)
return origin_url.strip() return origin_url.strip()
@ -49,6 +52,11 @@ def bootstrap(parser, args):
tty.msg("Fetching spack from origin: %s" % origin_url) tty.msg("Fetching spack from origin: %s" % origin_url)
if os.path.isfile(prefix):
tty.die("There is already a file at %s" % prefix)
mkdirp(prefix)
if os.path.exists(join_path(prefix, '.git')): if os.path.exists(join_path(prefix, '.git')):
tty.die("There already seems to be a git repository in %s" % prefix) tty.die("There already seems to be a git repository in %s" % prefix)
@ -62,10 +70,11 @@ def bootstrap(parser, args):
"%s/lib/spack/..." % prefix) "%s/lib/spack/..." % prefix)
os.chdir(prefix) os.chdir(prefix)
check_call(['git', 'init', '--shared', '-q']) git = which('git', required=True)
check_call(['git', 'remote', 'add', 'origin', origin_url]) git('init', '--shared', '-q')
check_call(['git', 'fetch', 'origin', 'master:refs/remotes/origin/master', '-n', '-q']) git('remote', 'add', 'origin', origin_url)
check_call(['git', 'reset', '--hard', 'origin/master', '-q']) git('fetch', 'origin', 'master:refs/remotes/origin/master', '-n', '-q')
git('reset', '--hard', 'origin/master', '-q')
tty.msg("Successfully created a new spack in %s" % prefix, tty.msg("Successfully created a new spack in %s" % prefix,
"Run %s/bin/spack to use this installation." % prefix) "Run %s/bin/spack to use this installation." % prefix)