Author: johannes Date: 2007-11-15 02:56:00 -0600 (Thu, 15 Nov 2007) New Revision: 9810
Modified: trunk/gnue-common/src/apps/plugin.py Log: More changes according to pylint Modified: trunk/gnue-common/src/apps/plugin.py =================================================================== --- trunk/gnue-common/src/apps/plugin.py 2007-11-15 08:40:12 UTC (rev 9809) +++ trunk/gnue-common/src/apps/plugin.py 2007-11-15 08:56:00 UTC (rev 9810) @@ -55,14 +55,12 @@ abstract base drivers. """ -from types import * - import os -import string import sys import traceback -from gnue.common.apps import errors, i18n +from types import ModuleType +from gnue.common.base import errors, i18n __all__ = ['LoadError', 'list', 'find'] @@ -92,9 +90,9 @@ message = u_("Cannot load plugin '%s'") % self.name detail = u_("The following plugins failed:\n") for (name, exc) in self.exceptions.items(): - list = traceback.format_exception_only(exc[0], exc[1]) - del list[1:2] - msg = unicode(string.join(list, ''), i18n.getencoding()) + tlist = traceback.format_exception_only(exc[0], exc[1]) + del tlist[1:2] + msg = unicode(''.join(tlist), i18n.get_encoding()) detail += "* %s: %s" % (name, msg) else: message = u_("Cannot find plugin '%s'") % self.name @@ -110,7 +108,7 @@ # List all available plugins # ----------------------------------------------------------------------------- -def list(base, identifier, try_to_init = True): +def list(base, identifier, try_to_init=True): """ List all available plugins. @@ -122,8 +120,8 @@ either the loaded module or the exception info tuple of the exception raised when trying to import the module as values. """ - checktype(base, [StringType, UnicodeType]) - checktype(identifier, [StringType, UnicodeType]) + checktype(base, [basestring]) + checktype(identifier, [basestring]) # Make sure everything is a string. Non-ASCII characters are not allowed in # Python module names anyway. @@ -150,9 +148,9 @@ module. @return: The loaded module of the plugin. """ - checktype(name, [StringType, UnicodeType]) - checktype(base, [StringType, UnicodeType]) - checktype(identifier, [StringType, UnicodeType]) + checktype(name, [basestring]) + checktype(base, [basestring]) + checktype(identifier, [basestring]) # Make sure everything is a string. Non-ASCII characters are not allowed in # Python module names anyway. @@ -241,29 +239,29 @@ return {base: __failed[base]} try: - m = __import__(base, None, None, '*') + mod = __import__(base, None, None, '*') except: __failed[base] = sys.exc_info() return {base: __failed[base]} - if hasattr(m, '__noplugin__'): + if hasattr(mod, '__noplugin__'): # This is not a plugin, ignore it return {} if not top: - if hasattr(m, identifier): + if hasattr(mod, identifier): # This is already a plugin, no need to go deeper - if try_to_init and hasattr(m, '__initplugin__'): + if try_to_init and hasattr(mod, '__initplugin__'): try: - m.__initplugin__() + mod.__initplugin__() except: __failed[base] = sys.exc_info() return {base: __failed[base]} - return {base: m} + return {base: mod} # List all submodules result = {} - for sub in __modules(m, False): + for sub in __modules(mod, False): result.update(__list(base + '.' + sub, identifier, try_to_init, False)) return result @@ -282,28 +280,28 @@ return {base: __failed[base]} try: - m = __import__(base, None, None, '*') + mod = __import__(base, None, None, '*') except: __failed[base] = sys.exc_info() return {base: __failed[base]} - if hasattr(m, '__noplugin__'): + if hasattr(mod, '__noplugin__'): # This is not a plugin, ignore it return {} - if hasattr(m, identifier): + if hasattr(mod, identifier): # This is already a plugin, no need to go deeper - if hasattr(m, '__initplugin__'): + if hasattr(mod, '__initplugin__'): try: - m.__initplugin__() + mod.__initplugin__() except: __failed[base] = sys.exc_info() return {base: __failed[base]} - return m + return mod # Search all submodules exceptions = {} - for sub in __modules(m, False): + for sub in __modules(mod, False): result = __first(base + '.' + sub, identifier) if isinstance(result, ModuleType): return result @@ -323,18 +321,18 @@ return {base: __failed[base]} try: - m = __import__(base, None, None, '*') + mod = __import__(base, None, None, '*') except: __failed[base] = sys.exc_info() return {base: __failed[base]} - if hasattr(m, '__noplugin__'): + if hasattr(mod, '__noplugin__'): # This is not a plugin, ignore it return {} # Is the searched driver an alias of this module? - if hasattr(m, '__pluginalias__'): - if name in m.__pluginalias__: + if hasattr(mod, '__pluginalias__'): + if name in mod.__pluginalias__: return __first(base, identifier) if __failed.has_key(base + '.' + name): @@ -342,7 +340,7 @@ return {base + '.' + name: __failed[base + '.' + name]} try: - m = __import__(base + '.' + name, None, None, '*') + mod = __import__(base + '.' + name, None, None, '*') except ImportError: pass except: @@ -353,7 +351,7 @@ # Search all submodules exceptions = {} - for sub in __modules(m, False): + for sub in __modules(mod, False): result = __find(base + '.' + sub, name, identifier) if isinstance(result, ModuleType): return result @@ -368,25 +366,25 @@ if __name__ == '__main__': - base = 'gnue.common.datasources.drivers' + basep = 'gnue.common.datasources.drivers' if len(sys.argv) == 1: # List all modules - for (name, result) in(list(base, 'Connection')).items(): - print name[len(base)+1:] + ":", - if isinstance(result, ModuleType): + for (iname, iresult) in(list(basep, 'Connection')).items(): + print iname[len(basep)+1:] + ":", + if isinstance(iresult, ModuleType): print "ok" else: - list = traceback.format_exception_only(result[0], result[1]) - print string.join(list, ''), + data = traceback.format_exception_only(iresult[0], iresult[1]) + print ''.join(data), elif sys.argv[1] == 'test': try: print 'find "postgresql.popy":', - m = find('postgresql.popy', base, 'Connection') - print m.__name__ + fmod = find('postgresql.popy', basep, 'Connection') + print fmod.__name__ except LoadError, e: print e print "Detail:" @@ -396,8 +394,8 @@ try: print 'find "pygresql":', - m = find('pygresql', base, 'Connection') - print m.__name__ + fmod = find('pygresql', basep, 'Connection') + print fmod.__name__ except LoadError, e: print e print "Detail:" @@ -407,8 +405,8 @@ try: print 'find "mysql":', - m = find('mysql', base, 'Connection') - print m.__name__ + fmod = find('mysql', basep, 'Connection') + print fmod.__name__ except LoadError, e: print e print "Detail:" @@ -418,8 +416,8 @@ try: print 'find "oracle":', - m = find('oracle', base, 'Connection') - print m.__name__ + fmod = find('oracle', basep, 'Connection') + print fmod.__name__ except LoadError, e: print e print "Detail:" @@ -429,8 +427,8 @@ try: print 'find "nonexistent":', - m = find('nonexistent', base, 'Connection') - print m.__name__ + fmod = find('nonexistent', basep, 'Connection') + print fmod.__name__ except LoadError, e: print e print "Detail:" @@ -440,8 +438,8 @@ try: print 'find %s:' % sys.argv[1], - m = find(sys.argv[1], base, 'Connection') - print m.__name__ + fmod = find(sys.argv[1], basep, 'Connection') + print fmod.__name__ except LoadError, e: print e print "Detail:" _______________________________________________ commit-gnue mailing list commit-gnue@gnu.org http://lists.gnu.org/mailman/listinfo/commit-gnue