def handle_expression(resulttag, json_output, logger): result = None if resulttag.startswith('(') and resulttag.endswith(')'): express = resulttag[resulttag.find("(")+1:resulttag.find(")")] for tag in json_output: logger.DEBUG('is tag %s in express %s' % (tag, express)) if tag in express: if json_output[tag] != None: express = express.replace(tag, json_output[tag]) else: return None try: logger.DEBUG('try eval of <%s>' % express) result = evalExpress.eval_expr(express) except: logger.ERROR('could not evaluation %s, which became %s' % (resulttag, express)) sys.exit(1) else: logger.ERROR('handleExpress called with %s, expected expression in parens' % resulttag) return result
def validate_parameter_result(parameter_list, resultidlist, goals, inputtag): validate_ok = True use_target = "" if "." in inputtag: (use_target, inputtagstring) = inputtag.split('.') if use_target == "": use_target = "result" inputtagstring = inputtag if use_target == "parameter" or use_target == "parameter_ascii": if inputtagstring not in parameter_list: validate_ok = False elif use_target == "result": if inputtagstring not in resultidlist: # handle expression here if inputtagstring.startswith('(') and inputtagstring.endswith(')'): express = inputtagstring[inputtagstring.find("(") + 1:inputtagstring.find(")")] for tag in resultidlist: labutils.logger.debug('is tag %s in express %s' % (tag, express)) if tag in express: # Replace each occurence of tag with 2 express = express.replace(tag, "2") try: labutils.logger.debug('try eval of <%s>' % express) result = evalExpress.eval_expr(express) except: labutils.logger.error( 'could not evaluation %s, which became %s' % (inputtagstring, express)) validate_ok = False else: labutils.logger.error('invalid tag %s' % inputtagstring) validate_ok = False else: validate_ok = False return validate_ok