summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2013-03-25 15:27:28 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2013-03-25 15:27:28 -0700
commite1551de976355bdd7836c6e38a045df9ec91f0d0 (patch)
treece96ee5004c389d15f35875aea6e4bdabda9a540
parentb224d249bb43d858c7b3c825e7433ee5892df3a2 (diff)
downloadspack-e1551de976355bdd7836c6e38a045df9ec91f0d0.tar.gz
spack-e1551de976355bdd7836c6e38a045df9ec91f0d0.tar.bz2
spack-e1551de976355bdd7836c6e38a045df9ec91f0d0.tar.xz
spack-e1551de976355bdd7836c6e38a045df9ec91f0d0.zip
Moved install-spack to its own simpler command.
-rwxr-xr-xbin/install-spack61
-rw-r--r--lib/spack/spack/cmd/__init__.py11
-rw-r--r--lib/spack/spack/cmd/install-spack.py45
3 files changed, 53 insertions, 64 deletions
diff --git a/bin/install-spack b/bin/install-spack
deleted file mode 100755
index 38ac08976d..0000000000
--- a/bin/install-spack
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/usr/bin/python
-usage="""\
-This script installs spack in a new prefix.
-To use: cd to the prefix and execute this script.
-"""
-import os
-import sys
-import getpass
-from subprocess import check_call
-
-def escape(s):
- """Returns a TTY escape code if stdout is a tty, otherwise empty string"""
- if sys.stdout.isatty():
- return "\033[{}m".format(s)
- return ''
-
-def bold(n):
- return escape("1;{}".format(n))
-
-blue = bold(34)
-red = bold(31)
-white = bold(39)
-reset = escape(0)
-
-def msg(msg):
- print "{}==>{} {}{}".format(blue, white, str(msg), reset)
-
-def error(msg):
- print "{}==> ERROR: {} {}{}".format(red, white, str(msg), reset)
- sys.exit(1)
-
-
-user = getpass.getuser()
-if not user:
- error("Couldn't determine username!")
-
-spack_repo = "https://%s@lc.llnl.gov/stash/scm/SCALE/spack.git" % user
-msg("Fetching spack from %s" % spack_repo)
-
-prefix = os.getcwd()
-
-if os.path.exists(".git"):
- error("There already seems to be a git repository here.")
-
-files_in_the_way = os.listdir(".")
-if files_in_the_way:
- msg("There are already some files in this directory:")
- for file in files_in_the_way:
- print file
- error("Delete these files before installing spack.")
-
-msg("This script will install:")
-print " %s/bin/spack" % prefix
-print " %s/lib/spack/..." % prefix
-
-check_call(["git", "init", "--shared", "-q"])
-check_call(["git", "remote", "add", "origin", spack_repo])
-check_call(["git", "fetch", "origin", "master:refs/remotes/origin/master", "-n", "-q"])
-check_call(["git", "reset", "--hard", "origin/master", "-q"])
-
-msg("Successfully installed spack in %s" % prefix)
diff --git a/lib/spack/spack/cmd/__init__.py b/lib/spack/spack/cmd/__init__.py
index a54ade741e..a175ce7cfb 100644
--- a/lib/spack/spack/cmd/__init__.py
+++ b/lib/spack/spack/cmd/__init__.py
@@ -25,6 +25,10 @@ def null_op(*args):
pass
+def get_cmd_function_name(name):
+ return name.replace("-", "_")
+
+
def get_module(name):
"""Imports the module for a particular command name and returns it."""
module_name = "%s.%s" % (__name__, name)
@@ -35,13 +39,14 @@ def get_module(name):
attr.setdefault(module, SETUP_PARSER, null_op)
attr.setdefault(module, DESCRIPTION, "")
- if not hasattr(module, name):
+ fn_name = get_cmd_function_name(name)
+ if not hasattr(module, fn_name):
tty.die("Command module %s (%s) must define function '%s'."
- % (module.__name__, module.__file__, name))
+ % (module.__name__, module.__file__, fn_name))
return module
def get_command(name):
"""Imports the command's function from a module and returns it."""
- return getattr(get_module(name), name)
+ return getattr(get_module(name), get_cmd_function_name(name))
diff --git a/lib/spack/spack/cmd/install-spack.py b/lib/spack/spack/cmd/install-spack.py
new file mode 100644
index 0000000000..a8663e97ac
--- /dev/null
+++ b/lib/spack/spack/cmd/install-spack.py
@@ -0,0 +1,45 @@
+import os
+from subprocess import check_call, check_output
+import spack
+from spack import new_path
+import spack.tty as tty
+
+description = "Create a new installation of spack in another prefix"
+
+def setup_parser(subparser):
+ subparser.add_argument('prefix', help="names of prefix where we should install spack")
+
+
+def get_origin_url():
+ git_dir = new_path(spack.prefix, '.git')
+ origin_url = check_output(
+ ['git', '--git-dir=%s' % git_dir, 'config', '--get', 'remote.origin.url'])
+ return origin_url.strip()
+
+
+def install_spack(parser, args):
+ origin_url = get_origin_url()
+ prefix = args.prefix
+
+ tty.msg("Fetching spack from origin: %s" % origin_url)
+
+ if os.path.exists(new_path(prefix, '.git')):
+ tty.die("There already seems to be a git repository in %s" % prefix)
+
+ files_in_the_way = os.listdir(prefix)
+ if files_in_the_way:
+ tty.die("There are already files there! Delete these files before installing spack.",
+ *files_in_the_way)
+
+ tty.msg("Installing:",
+ "%s/bin/spack" % prefix,
+ "%s/lib/spack/..." % prefix)
+
+ os.chdir(prefix)
+ check_call(['git', 'init', '--shared', '-q'])
+ check_call(['git', 'remote', 'add', 'origin', origin_url])
+ check_call(['git', 'fetch', 'origin', 'master:refs/remotes/origin/master', '-n', '-q'])
+ check_call(['git', 'reset', '--hard', 'origin/master', '-q'])
+
+ tty.msg("Successfully installed spack in %s" % prefix,
+ "Run %s/bin/spack to use this installation." % prefix)