예제 #1
0
    def resolve_aliases(self, pipeline,
                        customAliases=None):
        # Compute the 'locals' dictionary by evaluating named expressions
        aliases = self.build_alias_dictionary(pipeline)
        if customAliases:
            #customAliases can be only a subset of the aliases
            #so we need to build the Alias Dictionary always
            for k,v in customAliases.iteritems():
                aliases[k] = v
        
        ordered = self.compute_evaluation_order(aliases)
        casting = {'int': int, 'float': float, 'double': float, 'string': str,
                   'Integer': int, 'Float': float, 'String': str}
        for alias in reversed(ordered):
            (atype,(base,exps)) = aliases[alias]
            value = self.evaluate_exp(atype,base,exps,aliases)
            aliases[alias] = casting[atype](value)

        for mid in pipeline.modules:
            for f in pipeline.modules[mid].functions:
                for p in f.params:
                    if p.alias and p.alias!='':
                        p.evaluatedStrValue = str(aliases[p.alias])
                    else:
                        (base,exps) = expression.parse_expression(
                            str(p.strValue))
                        p.evaluatedStrValue = str(
                            self.evaluate_exp(p.type,base,exps,aliases))
        return aliases
 def assemble_aliases(self):
     """assemble_aliases() -> None
     Generate a list of all aliases across the active pipelines
     in self.pipelines, which is stored in self.aliases
     Also, for each key in self.aliases, self.sources has the same key,
     mapped to a tuple of the type (p, m, f, pa)
     where p is the index of the pipeline in self.pipelines, m is the
     index of the module, f of the function, and pa of the parameter
      
     """
     union = {}
     sources = {}
     for pi in self.active_pipelines:
         pipeline = self.pipelines[pi]
         for name, info in pipeline.aliases.iteritems():
             if not union.has_key(name):
                 value = str(pipeline.get_alias_str_value(name))
                 e = expression.parse_expression(value)
                 union[name] = (info[0], e)
                 sources[name] = [(pi, info[1], info[2], info[3])]
             else:
                 sources[name].append((pi, info[1], info[2], info[3]))
                 
     self.sources = sources
     self.aliases = union
예제 #3
0
 def build_alias_dictionary(self, pipeline):
     aliases = {}
     for mid in pipeline.modules:
         for f in pipeline.modules[mid].functions:
             fsig = f.getSignature()
             for pidx in xrange(len(f.params)):
                 palias = f.params[pidx].alias
                 if palias and palias!='':
                     for f1 in reversed(pipeline.modules[mid].functions):
                         if f1.getSignature()==fsig:
                             p = f1.params[pidx]
                             aliases[palias] = (p.type, expression.parse_expression(str(p.strValue)))
                             break
     return aliases
예제 #4
0
def run_and_get_results(w_list, parameters=""):
    """run_and_get_results(w_list: list of (locator, version), parameters: str)
    Run all workflows in w_list, and returns an interpreter result object.
    version can be a tag name or a version id.
    
    """
    elements = parameters.split(",")
    aliases = {}
    result = []
    for locator, workflow in w_list:
        v = locator.load()
        if type(workflow) == type("str"):
            version = v.get_tag_by_name(workflow).time
        elif type(workflow) == type(1):
            version = workflow
        else:
            msg = "Invalid version tag or number: %s" % workflow
            raise VistrailsInternalError(msg)

        pip = v.getPipeline(workflow)
        for e in elements:
            pos = e.find("=")
            if pos != -1:
                key = e[:pos].strip()
                value = e[pos + 1 :].strip()

                if pip.has_alias(key):
                    (vttype, pId, _, _) = pip.aliases[key]
                    parameter = pip.db_get_object(vttype, pId)
                    ptype = parameter.type
                    aliases[key] = (ptype, expression.parse_expression(value))
        view = DummyView()
        interpreter = core.interpreter.default.get_default_interpreter()

        run = interpreter.execute(None, pip, locator, version, view, aliases)
        result.append(run)
    return result