Beispiel #1
0
    def load(self,template,vars):
        dp=os.path.dirname(template)
        if dp != '':
            self.domain=dp
            
        filename=os.path.basename(template)

        try:
            d=Domain(self.domain, quoting=None, errors=4) # fixme: what do we really want for quoting?
            t=Domain(self.domain, errors=4).get_template(filename, quoting="str") # fixme: why create two Domains?
        except Exception as e:
            print "(domain is %s)" % self.domain
            raise e

        evars=evoque_dict()             # special dict that returns missing keys as "${key}"
        evars.update(vars)
        yaml_txt=t.evoque(evars)

        # fix eval errors:
        # fixed_yaml=re.sub('\[EvalError\(([a-z_]+)\)]', "${\g<1>}", yaml_txt) # ooh, magic! great.
        # fixed_yaml=re.sub('\[NameError: name &#39; ([a-z_]+)\)]', "${\g<1>}", yaml_txt) # ooh, magic! great.
        # fixed_yaml=re.sub('&lt;built-in function ([a-z_]+)&gt;', "${\g<1>}", fixed_yaml) # christ, more magic

#        warn("syml.load: fixed_yaml is %s" % fixed_yaml)
        d=yaml.load(yaml_txt)
            
        # "fix" config; ie, resolve referenced values
        d=self._fix_hash(d,d)
        return d
Beispiel #2
0
    def load(self):
        # get globals if necessary
        if (self.globals == {}) and self.globals_file:
            f = open(self.globals_file, "r")
            self.globals = yaml.load(f)
            f.close

        # read config template (with globals)
        if not self.config_file:
            raise Exception("no config_file")

        if not self.domain:
            try:
                self.domain = self.globals["domain"]
            except:
                self.domain = os.getcwd()
                print "warning: looking for globals.yml in local directory!"

        try:
            t = Domain(self.domain).get_template(self.config_file)
        except Exception as e:
            print "(domain is %s)" % self.domain
            raise e

        conf_yaml = t.evoque(self.globals)
        conf = yaml.load(conf_yaml)

        # "fix" config; ie, resolve referenced values
        conf = self._fix_hash(conf, conf)
        conf.update({"globals": self.globals})

        self.config = conf
Beispiel #3
0
    def as_python(self):
        template_filename=self.rnaseq.globals['step_template']

        try: domain=self.rnaseq.globals['domain']
        except: domain=os.getcwd()
        t=Domain(domain).get_template(template_filename)

        # step.template needs: name, input, output, pipeline_var_name
        # fixme: we killed input_str(), etc, (not cmd_str(), tho)
        vars={'input':self.flatten_attr('inputs'),
              'output':self.flatten_attr('outputs'),
              'name':self.name,
              'pipeline_var_name':self.pipeline_var_name,
            }
        
        template=t.evoque(vars)
        return template