Modified import_site_class() to not wrap baseclass with a local dummy
class when the site specific class does not exist (thus hopefully fixing
an issue in SVN about not being able to run server side tests because
sysinfo cannot be pickle dumped), instead have import_site_class return
the baseclass when the site specific class does not exist. Also, have it
perform automatically the mixin of baseclass and the site specific class
when the site specific one is not inherited already from baseclass and
removed the mixin that was done in some of the users.
Signed-off-by: Mihai Rusu <dizzy@google.com>
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
git-svn-id: http://test.kernel.org/svn/autotest/trunk@3050 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/common_lib/utils.py b/client/common_lib/utils.py
index 77b2397..93a1226 100644
--- a/client/common_lib/utils.py
+++ b/client/common_lib/utils.py
@@ -858,23 +858,26 @@
path: full filename of the source file calling this (ie __file__)
module: full module name
classname: class name to be loaded from site file
- baseclass: base class object to inherit from when no site file present
+ baseclass: base class object to return when no site file present or
+ to mixin when site class exists but is not inherited from baseclass
modulefile: module filename
- Returns: class object of the site class or baseclass
+ Returns: baseclass if site specific class does not exist, the site specific
+ class if it exists and is inherited from baseclass or a mixin of the
+ site specific class and baseclass when the site specific class exists
+ and is not inherited from baseclass
Raises: ImportError if the site file exists but imports fails
"""
res = import_site_symbol(path, module, classname, None, modulefile)
-
- if not res:
- # we cannot just return baseclass because some callers will want to
- # use multiple inheritance on the class object we return and baseclass
- class dummy(baseclass):
- pass
-
- res = dummy
+ if res:
+ if not issubclass(res, baseclass):
+ # if not a subclass of baseclass then mix in baseclass with the
+ # site specific class object and return the result
+ res = type(classname, (res, baseclass), {})
+ else:
+ res = baseclass
return res