X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;ds=sidebyside;f=bin%2Ftools%2Fyaml_tag.py;h=20aabf1c54c1904663d429ae21dc0081a037182a;hb=e406b65c0b8b6a392efe5c0d0b3a411f1ac607a7;hp=1d36dc17a5bd3b7b6cde0ce879dbac666727db80;hpb=790f32d9d0327945f9f1741b58bfb6979923539e;p=odoo%2Fodoo.git diff --git a/bin/tools/yaml_tag.py b/bin/tools/yaml_tag.py index 1d36dc1..20aabf1 100644 --- a/bin/tools/yaml_tag.py +++ b/bin/tools/yaml_tag.py @@ -4,6 +4,7 @@ import logging class YamlTag(object): """ Superclass for constructors of custom tags defined in yaml file. + __str__ is overriden in subclass and used for serialization in module recorder. """ def __init__(self, **kwargs): self.__dict__.update(kwargs) @@ -15,7 +16,7 @@ class YamlTag(object): return "<%s %s>" % (self.__class__.__name__, sorted(self.__dict__.items())) class Assert(YamlTag): - def __init__(self, model, id, severity=logging.ERROR, string="NONAME", **kwargs): + def __init__(self, model, id=None, severity=logging.WARNING, string="NONAME", **kwargs): self.model = model self.id = id self.severity = severity @@ -27,13 +28,17 @@ class Record(YamlTag): self.model = model self.id = id super(Record, self).__init__(**kwargs) + def __str__(self): + return '!record {model: %s, id: %s}:' % (str(self.model,), str(self.id,)) class Python(YamlTag): - def __init__(self, model, severity=logging.ERROR, name="", **kwargs): + def __init__(self, model, severity=logging.WARNING, name="", **kwargs): self.model= model self.severity = severity self.name = name super(Python, self).__init__(**kwargs) + def __str__(self): + return '!python {model: %s}: |' % (str(self.model), ) class Menuitem(YamlTag): def __init__(self, id, name, **kwargs): @@ -42,15 +47,16 @@ class Menuitem(YamlTag): super(Menuitem, self).__init__(**kwargs) class Workflow(YamlTag): - def __init__(self, model, action, **kwargs): + def __init__(self, model, action, ref=None, **kwargs): self.model = model self.action = action + self.ref = ref super(Workflow, self).__init__(**kwargs) + def __str__(self): + return '!workflow {model: %s, action: %s, ref: %s}' % (str(self.model,), str(self.action,), str(self.ref,)) class ActWindow(YamlTag): - def __init__(self, model, action, **kwargs): - self.model = model - self.action = action + def __init__(self, **kwargs): super(ActWindow, self).__init__(**kwargs) class Function(YamlTag): @@ -67,10 +73,7 @@ class Report(YamlTag): super(Report, self).__init__(**kwargs) class Delete(YamlTag): - def __init__(self, model, id, search, **kwargs): - self.model = model - self.id = id - self.search = search + def __init__(self, **kwargs): super(Delete, self).__init__(**kwargs) class Context(YamlTag): @@ -85,11 +88,15 @@ class Eval(YamlTag): def __init__(self, expression): self.expression = expression super(Eval, self).__init__() + def __str__(self): + return '!eval %s' % str(self.expression) class Ref(YamlTag): - def __init__(self, *args, **kwargs): - print "kwargs %s" % kwargs + def __init__(self, expr="False", *args, **kwargs): + self.expr = expr super(Ref, self).__init__(*args, **kwargs) + def __str__(self): + return 'ref(%s)' % repr(self.expr) class IrSet(YamlTag): def __init__(self): @@ -157,17 +164,20 @@ def ir_set_constructor(loader, node): # Registers constructors for custom tags. # Constructors are actually defined globally: do not redefined them in another # class/file/package. This means that module recorder need import this file. -yaml.add_constructor(u"!assert", assert_constructor) -yaml.add_constructor(u"!record", record_constructor) -yaml.add_constructor(u"!python", python_constructor) -yaml.add_constructor(u"!menuitem", menuitem_constructor) -yaml.add_constructor(u"!workflow", workflow_constructor) -yaml.add_constructor(u"!act_window", act_window_constructor) -yaml.add_constructor(u"!function", function_constructor) -yaml.add_constructor(u"!report", report_constructor) -yaml.add_constructor(u"!context", context_constructor) -yaml.add_constructor(u"!delete", delete_constructor) -yaml.add_constructor(u"!url", url_constructor) -yaml.add_constructor(u"!eval", eval_constructor) -yaml.add_multi_constructor(u"!ref", ref_constructor) -yaml.add_constructor(u"!ir_set", ir_set_constructor) +def add_constructors(): + yaml.add_constructor(u"!assert", assert_constructor) + yaml.add_constructor(u"!record", record_constructor) + yaml.add_constructor(u"!python", python_constructor) + yaml.add_constructor(u"!menuitem", menuitem_constructor) + yaml.add_constructor(u"!workflow", workflow_constructor) + yaml.add_constructor(u"!act_window", act_window_constructor) + yaml.add_constructor(u"!function", function_constructor) + yaml.add_constructor(u"!report", report_constructor) + yaml.add_constructor(u"!context", context_constructor) + yaml.add_constructor(u"!delete", delete_constructor) + yaml.add_constructor(u"!url", url_constructor) + yaml.add_constructor(u"!eval", eval_constructor) + yaml.add_multi_constructor(u"!ref", ref_constructor) + yaml.add_constructor(u"!ir_set", ir_set_constructor) +add_constructors() +