summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2013-12-23 12:09:19 -0800
committerTodd Gamblin <tgamblin@llnl.gov>2013-12-23 12:09:19 -0800
commit7267734a5b66f76f3c199c2474424d6725a75146 (patch)
tree5f81d3be4fff7d24f4fa027312ad61003ada833d /lib
parent358bfdaaf1e90c2ab06411ace68cb58b318f9ed7 (diff)
downloadspack-7267734a5b66f76f3c199c2474424d6725a75146.tar.gz
spack-7267734a5b66f76f3c199c2474424d6725a75146.tar.bz2
spack-7267734a5b66f76f3c199c2474424d6725a75146.tar.xz
spack-7267734a5b66f76f3c199c2474424d6725a75146.zip
Spack create works again w/new package format.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/create.py62
-rw-r--r--lib/spack/spack/cmd/info.py8
-rw-r--r--lib/spack/spack/util/compression.py4
-rw-r--r--lib/spack/spack/util/executable.py7
-rw-r--r--lib/spack/spack/validate.py4
5 files changed, 75 insertions, 10 deletions
diff --git a/lib/spack/spack/cmd/create.py b/lib/spack/spack/cmd/create.py
index cc3274f70e..af75f40d73 100644
--- a/lib/spack/spack/cmd/create.py
+++ b/lib/spack/spack/cmd/create.py
@@ -1,28 +1,50 @@
import string
import os
+import hashlib
+import re
import spack
import spack.packages as packages
import spack.tty as tty
import spack.url
+import spack.util.crypto as crypto
+from spack.util.executable import which
from spack.stage import Stage
from contextlib import closing
description = "Create a new package file from an archive URL"
package_template = string.Template("""\
+# FIXME:
+# This is a template package file for Spack. We've conveniently
+# put giant "FIXME" labels next to all the things you'll probably
+# want to change.
+#
+# Once you've edited all the FIXME's, delete this whole message,
+# save this file, and test out your package like this:
+#
+# spack install ${name}
+#
+# You can always get back here with 'spack edit ${name}'. See
+# the spack documentation for more information on building
+# packages.
+#
from spack import *
class ${class_name}(Package):
+ ""\"FIXME: put a proper description of your package here.""\"
+ # FIXME: add a proper url for your package's homepage here.
homepage = "http://www.example.com"
url = "${url}"
- md5 = "${md5}"
+
+ versions = ${versions}
def install(self, prefix):
- # Insert the configure line for your build system here.
- configure("--prefix=%s" % prefix)
- # cmake(".", *std_cmake_args)
+ # FIXME: Modify the configure line to suit your build system here.
+ ${configure}
+
+ # FIXME:
make()
make("install")
""")
@@ -34,6 +56,26 @@ def setup_parser(subparser):
help="Remove existing package file.")
+def guess_configure(archive_file):
+ """Try to guess the type of build system used by the project, and return
+ an appropriate configure line.
+ """
+ tar = which('tar')
+ output = tar("--exclude=*/*/*", "-tf", archive_file, return_output=True)
+
+ autotools = 'configure("--prefix=%s" % prefix)'
+ cmake = 'cmake(".", *std_cmake_args)'
+ lines = output.split('\n')
+
+ if any(re.search(r'/configure$', l) for l in lines):
+ return autotools
+ elif any(re.search(r'/CMakeLists.txt$', l) for l in lines):
+ return cmake
+ else:
+ # Both, with cmake commented out
+ return '%s\n # %s' % (autotools, cmake)
+
+
def create(parser, args):
url = args.url
@@ -51,7 +93,7 @@ def create(parser, args):
if not version:
tty.die("Couldn't guess a version string from %s." % url)
- path = packages.filename_for(name)
+ path = packages.filename_for_package_name(name)
if not args.force and os.path.exists(path):
tty.die("%s already exists." % path)
@@ -62,17 +104,21 @@ def create(parser, args):
except spack.FailedDownloadException, e:
tty.die(e.message)
- md5 = spack.md5(archive_file)
+ md5 = crypto.checksum(hashlib.md5, archive_file)
+ versions = '{ "%s" : "%s" }' % (version, md5)
class_name = packages.class_name_for_package_name(name)
+ configure = guess_configure(archive_file)
- # Write outa template for the file
+ # Write out a template for the file
tty.msg("Editing %s." % path)
with closing(open(path, "w")) as pkg_file:
pkg_file.write(
package_template.substitute(
+ name=name,
+ configure=configure,
class_name=class_name,
url=url,
- md5=md5))
+ versions=versions))
# If everything checks out, go ahead and edit.
spack.editor(path)
diff --git a/lib/spack/spack/cmd/info.py b/lib/spack/spack/cmd/info.py
index 973fe86268..cae180ec9b 100644
--- a/lib/spack/spack/cmd/info.py
+++ b/lib/spack/spack/cmd/info.py
@@ -18,6 +18,14 @@ def info(parser, args):
print "Download: ", package.url
print
+ print "Safe versions: "
+
+ if package.versions:
+ colify(reversed(sorted(package.versions)), indent=4)
+ else:
+ print "None. Use spack versions %s to get a list of downloadable versions." % package.name
+
+ print
print "Dependencies:"
if package.dependencies:
colify(package.dependencies, indent=4)
diff --git a/lib/spack/spack/util/compression.py b/lib/spack/spack/util/compression.py
index c4ac256826..c4ce7275af 100644
--- a/lib/spack/spack/util/compression.py
+++ b/lib/spack/spack/util/compression.py
@@ -9,6 +9,10 @@ EXTS = ["gz", "bz2", "xz", "Z", "zip", "tgz"]
ALLOWED_ARCHIVE_TYPES = [".".join(l) for l in product(PRE_EXTS, EXTS)] + EXTS
+def allowed_archive(path):
+ return any(path.endswith(t) for t in ALLOWED_ARCHIVE_TYPES)
+
+
def decompressor_for(path):
"""Get the appropriate decompressor for a path."""
tar = which('tar', required=True)
diff --git a/lib/spack/spack/util/executable.py b/lib/spack/spack/util/executable.py
index d44420ab72..ad13695405 100644
--- a/lib/spack/spack/util/executable.py
+++ b/lib/spack/spack/util/executable.py
@@ -9,9 +9,16 @@ class Executable(object):
def __init__(self, name):
self.exe = name.split(' ')
+
def add_default_arg(self, arg):
self.exe.append(arg)
+
+ @property
+ def command(self):
+ return self.exe[0]
+
+
def __call__(self, *args, **kwargs):
"""Run the executable with subprocess.check_output, return output."""
return_output = kwargs.get("return_output", False)
diff --git a/lib/spack/spack/validate.py b/lib/spack/spack/validate.py
index ceeca052b5..9f4daf9866 100644
--- a/lib/spack/spack/validate.py
+++ b/lib/spack/spack/validate.py
@@ -1,7 +1,7 @@
import tty
from urlparse import urlparse
-from spack.util.compression import ALLOWED_ARCHIVE_TYPES
+from spack.util.compression import allowed_archive
ALLOWED_SCHEMES = ["http", "https", "ftp"]
@@ -10,5 +10,5 @@ def url(url_string):
if url.scheme not in ALLOWED_SCHEMES:
tty.die("Invalid protocol in URL: '%s'" % url_string)
- if not any(url_string.endswith(t) for t in ALLOWED_ARCHIVE_TYPES):
+ if not allowed_archive(url_string):
tty.die("Invalid file type in URL: '%s'" % url_string)