summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHans Ulrich Niedermann <hun@n-dimensional.de>2008-06-27 00:05:08 +0200
committerHans Ulrich Niedermann <hun@n-dimensional.de>2008-07-15 12:28:53 +0200
commit2a56d98fe97286918c28974a84fe1f534a45065d (patch)
tree7cd2fa990fede40368b5cbb43ada31a652cbd79f /src
parent1a88e6910815f0bc7aff3cf2ee00b1877df7524c (diff)
downloadnbb-2a56d98fe97286918c28974a84fe1f534a45065d.tar.gz
nbb-2a56d98fe97286918c28974a84fe1f534a45065d.tar.xz
nbb-2a56d98fe97286918c28974a84fe1f534a45065d.zip
Use @plugins.abstractmethod decorator
Diffstat (limited to 'src')
-rw-r--r--src/nbblib/bs.py15
-rw-r--r--src/nbblib/commands.py20
-rw-r--r--src/nbblib/newplugins.py39
3 files changed, 69 insertions, 5 deletions
diff --git a/src/nbblib/bs.py b/src/nbblib/bs.py
index 8509c92..c0a8060 100644
--- a/src/nbblib/bs.py
+++ b/src/nbblib/bs.py
@@ -52,11 +52,16 @@ class BSSourceTree(plugins.GenericDetectPlugin):
repr(self.tree_root))
# Abstract methods
- def _get_tree_root(self): raise NotImplementedError()
- def init(self): raise NotImplementedError()
- def configure(self): raise NotImplementedError()
- def build(self): raise NotImplementedError()
- def install(self): raise NotImplementedError()
+ @plugins.abstractmethod
+ def _get_tree_root(self): pass
+ @plugins.abstractmethod
+ def init(self): pass
+ @plugins.abstractmethod
+ def configure(self): pass
+ @plugins.abstractmethod
+ def build(self): pass
+ @plugins.abstractmethod
+ def install(self): pass
class AutomakeSourceTree(BSSourceTree):
diff --git a/src/nbblib/commands.py b/src/nbblib/commands.py
index b238b49..7c8e068 100644
--- a/src/nbblib/commands.py
+++ b/src/nbblib/commands.py
@@ -218,24 +218,44 @@ class BuildTestCommand(SourceClassCommand):
class InitCommand(SourceClassCommand):
name = 'init'
summary = 'initialize buildsystem'
+ def validate_args(self, *args, **kwargs):
+ """Validate command line arguments"""
+ if len(args) > 0:
+ raise CommandLineError("'%s' command takes no parameters",
+ self.name)
def run(self):
self.bs_sourcetree.init()
class ConfigureCommand(SourceClassCommand):
name = 'configure'
summary = 'configure buildsystem'
+ def validate_args(self, *args, **kwargs):
+ """Validate command line arguments"""
+ if len(args) > 0:
+ raise CommandLineError("'%s' command takes no parameters",
+ self.name)
def run(self):
self.bs_sourcetree.configure()
class BuildCommand(SourceClassCommand):
name = 'build'
summary = 'build from source'
+ def validate_args(self, *args, **kwargs):
+ """Validate command line arguments"""
+ if len(args) > 0:
+ raise CommandLineError("'%s' command takes no parameters",
+ self.name)
def run(self):
self.bs_sourcetree.build()
class InstallCommand(SourceClassCommand):
name = 'install'
summary = 'install the built things'
+ def validate_args(self, *args, **kwargs):
+ """Validate command line arguments"""
+ if len(args) > 0:
+ raise CommandLineError("'%s' command takes no parameters",
+ self.name)
def run(self):
self.bs_sourcetree.install()
diff --git a/src/nbblib/newplugins.py b/src/nbblib/newplugins.py
index bc8f1f2..1cb41cd 100644
--- a/src/nbblib/newplugins.py
+++ b/src/nbblib/newplugins.py
@@ -60,6 +60,8 @@ class MyPluginB(MyPluginType):
import sys
import logging
+import types
+import functools
class NoPluginsRegistered(Exception):
@@ -101,6 +103,43 @@ class AmbigousPluginDetection(Exception):
self.kwargs)
+# Might be used later when we do class introspection looking for
+# abstract methods.
+class UNUSED_AbstractMethodsInConcreteClass(Exception):
+ def __init__(self, cls, methods):
+ self.cls = cls
+ self.methods = methods
+ def __str__(self):
+ methods = "\n ".join(self.methods)
+ return "Concrete class %s.%s must implement these methods:\n %s" \
+ % (self.cls.__module__,
+ self.cls.__name__,
+ methods)
+
+
+class AbstractMethodError(Exception):
+ def __init__(self, name, module):
+ self.name = name
+ self.module = module
+ def __str__(self):
+ # FIXME: Class name?
+ return "Abstract method %s called someplace in %s" \
+ % (repr(self.name), repr(self.module))
+
+
+def abstractmethod(fun):
+ @functools.wraps(fun)
+ def f(self, *args, **kwargs):
+ # fun(self, *args, **kwargs)
+ raise AbstractMethodError(name=fun.__name__,
+ module=fun.__module__)
+ # We might add some introspection tool later, to be run
+ # in e.g. GenericPluginMeta.__init__(...), which makes sure
+ # that there are no abstract methods in a non-abstract class.
+ # f.abstract_method = True
+ return f
+
+
class PluginDict(dict):
"""Helper for GenericPluginMeta class