Scheduled maintenance on Monday 2019-06-24 between 10:00-11:00 CEST

Minor additions to backend and meta_info libs.

parent d8ee0292
......@@ -130,6 +130,8 @@ class LocalBackend(object):
# Check the type
dtype_str = dataManager.metaInfo.dtypeStr
if dtype_str is None:
raise TypeError("The metainfo '{}' does not define a dtypeStr".format(metaName))
single_types = self.single_value_type_for_metainfo_type(dtype_str)
actual_numpy_type = type(value)
if actual_numpy_type not in single_types:
......@@ -318,14 +320,14 @@ class Results(object):
if metainfo is None:
raise LookupError("The metainfo name '{}' does not exist in the metainfo environment. Check for typos or try updating the metainfo git package.".format(metaname))
def traverse(self):
def traverse(self, root_section='section_run'):
"""A generator function for traversing the data in the parser results.
This generator returns a tuple of three item: the metainfo name, the
event type, and the event value.
"""
root = self._sectionmanagers["section_run"]
for x in self.traverse_recursive("section_run", root.openSections):
root = self._sectionmanagers[root_section]
for x in self.traverse_recursive(root_section, root.openSections):
yield x
def traverse_recursive(self, name, open_sections):
......@@ -624,7 +626,7 @@ class SectionManager(object):
gI = gIndex
try:
self.openSections[gI].addValue(valueMetaInfo, value)
except KeyError:
except (KeyError, IndexError):
raise Exception("Cannot add value for metadata %s to section %d (%d) of %s, as it is not open" % (valueMetaInfo.name, gI, gIndex, self.metaInfo.name))
def setArrayValues(self, valueMetaInfo, value, offset=None, gIndex=-1):
......@@ -634,7 +636,7 @@ class SectionManager(object):
gI = gIndex
try:
self.openSections[gI].setArrayValues(valueMetaInfo, value, offset)
except KeyError:
except (KeyError, IndexError):
raise Exception("Cannot set array values for metadata %s to section %d (%d) of %s, as it is not open" % (valueMetaInfo.name, gI, gIndex, self.metaInfo.name))
def addArrayValues(self, valueMetaInfo, value, gIndex=-1):
......@@ -644,7 +646,7 @@ class SectionManager(object):
gI = gIndex
try:
self.openSections[gI].addArrayValues(valueMetaInfo, value)
except KeyError:
except (KeyError, IndexError):
raise Exception("Cannot add array values for metadata %s to section %d (%d) of %s, as it is not open" % (valueMetaInfo.name, gI, gIndex, self.metaInfo.name))
......
......@@ -10,6 +10,7 @@ import json
import os, re
from nomadcore.json_support import jsonCompactS, jsonCompactD, jsonIndentD
from io import open
import nomad_meta_info
"""objects to handle a local InfoKinds with unique name (think self written json)"""
class InfoKindEl(object):
......@@ -183,14 +184,20 @@ class RelativeDependencySolver(object):
self.deps = {}
def __call__(self, infoKindEnv, source, dep):
if "relativePath" not in dep:
raise Exception('Invalid dependency for relativeDependencySolver there must be a relativePath')
basePath = source.get('path')
if "metainfoPath" in dep:
basePath = nomad_meta_info.__file__
path = dep["metainfoPath"]
elif "relativePath" in dep:
basePath = source.get('path')
path = dep["relativePath"]
else:
raise Exception('Invalid dependency for relativeDependencySolver there must be a relativePath or metainfoPath')
if basePath:
baseDir = os.path.dirname(os.path.abspath(basePath))
else:
baseDir = os.getcwd()
dPath = os.path.realpath(os.path.join(baseDir, dep['relativePath']))
dPath = os.path.realpath(os.path.join(baseDir, path))
if dPath in self.deps:
return self.deps[dPath]
depInfo = None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment