Ejemplo n.º 1
0
    def create_instance(self, family_name, instance_name_or_spec):
        dtu.check_isinstance(instance_name_or_spec, (dict, str))

        family = self.get_family(family_name)
        if not family.valid:
            msg = ('Cannot instantiate %r because its family %r is invalid.' %
                   (instance_name_or_spec, family_name))
            msg += '\n\n' + dtu.indent(family.error_if_invalid, "  > ")
            raise dtu.DTConfigException(msg)

        if isinstance(instance_name_or_spec, str):
            instance_name = instance_name_or_spec
            dtu.check_is_in('instance', instance_name, family.instances)
            instance = family.instances[instance_name]
            if not instance.valid:
                msg = ('Cannot instantiate %r because it is invalid:\n%s' %
                       (instance_name,
                        dtu.indent(instance.error_if_invalid, '> ')))
                raise dtu.DTConfigException(msg)
            res = dtu.instantiate(instance.constructor, instance.parameters)
        elif isinstance(instance_name_or_spec, dict):
            _name, spec = _parse_inline_spec(instance_name_or_spec)
            res = dtu.instantiate(spec.constructor, spec.parameters)
        else:
            assert False

        interface = dtu.import_name(family.interface)
        if not isinstance(res, interface):
            msg = ('I expected that %r would be a %s but it is a %s.' %
                   (instance_name, interface.__name__, type(res).__name__))
            raise dtu.DTConfigException(msg)

        return res
Ejemplo n.º 2
0
def eval_name(x, name_tuple):
    if not name_tuple:
        return x
    else:
        first = name_tuple[0]
        rest = name_tuple[1:]
        dtu.check_is_in('value', first, x, EvaluationError)
        xx = x[first]
        return eval_name(xx, rest)
Ejemplo n.º 3
0
    def eval(self, rdb):
        db_entry = rdb.query_results_one(branch=self.branch,
                                  date=self.date,
                                  commit=self.commit)
        check_isinstance(db_entry, ResultDBEntry)
#         print('Results= %s' % db_entry.__repr__())
        results = db_entry.results
        dtu.check_is_in('analyzer', self.analyzer, results, EvaluationError)
        logs = results[self.analyzer]
        dtu.check_is_in('log', self.log, logs, EvaluationError)
        forlog = logs[self.log]
        val = eval_name(forlog, self.statistic)
        return val
Ejemplo n.º 4
0
    def create_instance(self, family_name, instance_name):
        family = self.get_family(family_name)
        if not family.valid:
            msg = ('Cannot instantiate %r because its family %r is invalid.' %
                   (instance_name, family_name))
            raise DTConfigException(msg)

        check_is_in('instance', instance_name, family.instances)
        instance = family.instances[instance_name]

        if not instance.valid:
            msg = ('Cannot instantiate because it is invalid:\n%s' %
                   indent(instance.error_if_invalid, '> '))
            raise DTConfigException(msg)
        res = instantiate(instance.constructor, instance.parameters)

        interface = import_name(family.interface)
        if not isinstance(res, interface):
            msg = ('I expected that %r would be a %s but it is a %s.' %
                   (instance_name, interface.__name__, type(res).__name__))
            raise DTConfigException(msg)

        return res
Ejemplo n.º 5
0
 def get_family(self, x):
     dtu.check_is_in('family', x, self.family_name2config)
     return self.family_name2config[x]