def apply(self): failed = False for expr in self.evals: result = None if issubclass(type(expr), Lookup): result = expr.evaluate(self.resource) elif type(expr) == str: result = Template.native_eval(expr, self.resource) else: result = expr self.echo("%s => %s" % (expr, result)) if not result: failed = True variables = self.resource.get_variables() for (k,v) in self.variable_checks.items(): if k not in variables: self.echo("%s is not defined" % k) failed = True else: actual = variables[k] if (v != actual): self.echo("%s is %s (type:%s), should be %s (type:%s)" % (k, v, type(v), actual, type(actual))) failed = True else: self.echo("%s is %s" % (k, v)) if not failed: return self.ok() else: return self.fatal("assertions failed")
def apply(self): self.cowsay = shutil.which('cowsay') txt = Template.from_string(self.msg, self.resource) if self.cowsay and os.environ.get('MOO'): cmd = COWSAY.format(msg=txt) txt = self.run(cmd, echo=False) self.echo(txt) return self.ok()
def should_replace_using_template(self): """ for from_template , should we write the template? """ if not FileTests.exists(self.name): return True if not self.overwrite: return False self.evaluated_template = Template.from_file(self.from_template, self.resource) c1 = FileTests.string_checksum(self.evaluated_template) c2 = FileTests.checksum(self.name) return c1 != c2
def apply(self): self.cowsay = shutil.which('cowsay') txt = Template.from_string(self.msg, self.resource) if self.cowsay and os.environ.get('MOO'): cmd = COWSAY.format(msg=txt) txt = subprocess.check_output(cmd, shell=True).decode() self.echo(txt) return self.ok()
def should_replace_using_template(self): """ for from_template , should we write the template? """ if not self.overwrite: return False data = self.slurp(self.from_template, remote=True) self.evaluated_template = Template.from_string(data, self.resource) if not FileTests.exists(self.name): return True original = self.slurp(self.name) return original != self.evaluated_template
def template_file(self, path): return Template.from_file(path, self)
def template(self, msg): return Template.from_string(msg, self)
def evaluate(self, resource): return Template.native_eval(self.expr, resource)
def evaluate(self, resource): return CoreTemplate.from_string(self.expr, resource)