示例#1
0
    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")
示例#2
0
    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()
示例#3
0
 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
示例#4
0
    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()
示例#5
0
    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
示例#6
0
文件: type.py 项目: pkropf/opsmop
 def template_file(self, path):
     return Template.from_file(path, self)
示例#7
0
文件: type.py 项目: pkropf/opsmop
 def template(self, msg):
     return Template.from_string(msg, self)
示例#8
0
 def evaluate(self, resource):
     return Template.native_eval(self.expr, resource)
示例#9
0
文件: template.py 项目: xinity/opsmop
 def evaluate(self, resource):
     return CoreTemplate.from_string(self.expr, resource)