summaryrefslogtreecommitdiff
path: root/lib/spack/spack/spec.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/spack/spack/spec.py')
-rw-r--r--lib/spack/spack/spec.py40
1 files changed, 34 insertions, 6 deletions
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py
index 3046aa1d08..9f310c8dc7 100644
--- a/lib/spack/spack/spec.py
+++ b/lib/spack/spack/spec.py
@@ -183,6 +183,13 @@ default_format = '{name}{@version}'
default_format += '{%compiler.name}{@compiler.version}{compiler_flags}'
default_format += '{variants}{arch=architecture}'
+#: Regular expression to pull spec contents out of clearsigned signature
+#: file.
+CLEARSIGN_FILE_REGEX = re.compile(
+ (r"^-----BEGIN PGP SIGNED MESSAGE-----"
+ r"\s+Hash:\s+[^\s]+\s+(.+)-----BEGIN PGP SIGNATURE-----"),
+ re.MULTILINE | re.DOTALL)
+
#: specfile format version. Must increase monotonically
specfile_format_version = 3
@@ -2395,8 +2402,8 @@ class Spec(object):
def from_dict(data):
"""Construct a spec from JSON/YAML.
- Parameters:
- data -- a nested dict/list data structure read from YAML or JSON.
+ Args:
+ data: a nested dict/list data structure read from YAML or JSON.
"""
return _spec_from_dict(data)
@@ -2405,8 +2412,8 @@ class Spec(object):
def from_yaml(stream):
"""Construct a spec from YAML.
- Parameters:
- stream -- string or file object to read from.
+ Args:
+ stream: string or file object to read from.
"""
try:
data = yaml.load(stream)
@@ -2421,8 +2428,8 @@ class Spec(object):
def from_json(stream):
"""Construct a spec from JSON.
- Parameters:
- stream -- string or file object to read from.
+ Args:
+ stream: string or file object to read from.
"""
try:
data = sjson.load(stream)
@@ -2434,6 +2441,27 @@ class Spec(object):
)
@staticmethod
+ def extract_json_from_clearsig(data):
+ m = CLEARSIGN_FILE_REGEX.search(data)
+ if m:
+ return sjson.load(m.group(1))
+ return sjson.load(data)
+
+ @staticmethod
+ def from_signed_json(stream):
+ """Construct a spec from clearsigned json spec file.
+
+ Args:
+ stream: string or file object to read from.
+ """
+ data = stream
+ if hasattr(stream, 'read'):
+ data = stream.read()
+
+ extracted_json = Spec.extract_json_from_clearsig(data)
+ return Spec.from_dict(extracted_json)
+
+ @staticmethod
def from_detection(spec_str, extra_attributes=None):
"""Construct a spec from a spec string determined during external
detection and attach extra attributes to it.