From 16af2b2dbf24a340d27dc96ca2dc3c49baff5828 Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Tue, 1 Jul 2008 00:56:34 +0200 Subject: Add context info to plugin validate() classmethod --- src/nbblib/bs.py | 2 +- src/nbblib/plugins.py | 15 ++++++++------- src/nbblib/vcs.py | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/nbblib/bs.py b/src/nbblib/bs.py index 43c3f44..02b2800 100644 --- a/src/nbblib/bs.py +++ b/src/nbblib/bs.py @@ -39,7 +39,7 @@ class BSSourceTree(plugins.GenericDetectPlugin): ambigous_match_exception = AmbigousBSDetection @classmethod - def validate(cls, obj, vcs_tree): + def validate(cls, obj, context, vcs_tree): logging.debug("BSSourceTree.validate(%s, %s, %s) %s %s", cls, obj, vcs_tree, repr(obj.tree_root), repr(vcs_tree.tree_root)) diff --git a/src/nbblib/plugins.py b/src/nbblib/plugins.py index 8131426..465df39 100644 --- a/src/nbblib/plugins.py +++ b/src/nbblib/plugins.py @@ -38,7 +38,7 @@ class MyPluginType(p.GenericDetectPlugin): [ambigous_match_exception = ...] [ @classmethod - def validate(cls, obj, *args, **kwargs): + def validate(cls, obj, context, *args, **kwargs): return True # or False, depending on params ] @@ -243,7 +243,7 @@ class GenericDetectPlugin(object): Example: >>> class FooDetectPlugin(GenericDetectPlugin): ... @classmethod - ... def validate(cls, obj, foo, bar): + ... def validate(cls, obj, context, foo, bar): ... return cls.__name__ == 'A' ... >>> class FooDetectPluginA(FooDetectPlugin): @@ -265,9 +265,10 @@ class GenericDetectPlugin(object): self.context = context @classmethod - def validate(cls, obj, *args, **kwargs): + def validate(cls, obj, context, *args, **kwargs): """Override this in subclass to validate the given args + @context Context information @param cls subclass of GenericDetectPlugin and type of obj @param obj instance of cls which is to be validated @param args the same args as given to detect() @@ -298,7 +299,7 @@ class GenericDetectPlugin(object): t = klass(context, *args, **kwargs) logging.debug("KLASS %s unvalidated, %s", klass, klass.validate) - if klass.validate(t, *args, **kwargs): + if klass.validate(t, context, *args, **kwargs): logging.debug("KLASS %s validated", klass) matches[key] = t except PluginNoMatch, e: @@ -326,7 +327,7 @@ def selftest(): no_match_exception = PluginNoMatchA ambigous_match_exception = AmbigousPluginDetectionA @classmethod - def validate(cls, obj, *args, **kwargs): + def validate(cls, obj, context, *args, **kwargs): logging.debug("Aval") return False @@ -338,7 +339,7 @@ def selftest(): class TestDetectPluginC(GenericDetectPlugin): __metaclass__ = GenericPluginMeta @classmethod - def validate(cls, obj, *args, **kwargs): + def validate(cls, obj, context, *args, **kwargs): logging.debug("Cval") return False @@ -364,7 +365,7 @@ def selftest(): class TestDetectPluginC3(TestDetectPluginC): name = "C3" @classmethod - def validate(cls, obj, *args, **kwargs): + def validate(cls, obj, context, *args, **kwargs): logging.debug("C3val") return True diff --git a/src/nbblib/vcs.py b/src/nbblib/vcs.py index ed7d73e..61c2531 100644 --- a/src/nbblib/vcs.py +++ b/src/nbblib/vcs.py @@ -76,7 +76,7 @@ class VCSourceTree(plugins.GenericDetectPlugin): ambigous_match_exception = AmbigousVCSDetection @classmethod - def validate(cls, obj, srcdir): + def validate(cls, obj, context, srcdir): logging.debug("cls %s", cls) logging.debug("obj %s", obj) logging.debug("srcdir %s", srcdir) -- cgit