X-Git-Url: http://git.tremily.us/?p=hooke.git;a=blobdiff_plain;f=hooke%2Futil%2Fpluggable.py;h=a3c2d5b8a16427b13d8491114c9829bd349d0c73;hp=ad2d85b89ed37f26a3a8629ee38e4c603f5bdab3;hb=fd155ef5b2366994f69252c7cd49d46186b62af0;hpb=d864072b1b3076fc5c9478f629102e3168a3b928 diff --git a/hooke/util/pluggable.py b/hooke/util/pluggable.py index ad2d85b..a3c2d5b 100644 --- a/hooke/util/pluggable.py +++ b/hooke/util/pluggable.py @@ -1,20 +1,19 @@ -# Copyright (C) 2010 W. Trevor King +# Copyright (C) 2010-2012 W. Trevor King # # This file is part of Hooke. # -# Hooke is free software: you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation, either -# version 3 of the License, or (at your option) any later version. +# Hooke is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. # -# Hooke is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. +# Hooke is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. # -# You should have received a copy of the GNU Lesser General Public -# License along with Hooke. If not, see -# . +# You should have received a copy of the GNU Lesser General Public License +# along with Hooke. If not, see . """``pluggable`` provides utility functions for extensible plugin modules. """ @@ -97,7 +96,12 @@ def construct_odict(this_modname, submodnames, class_selector, obj = getattr(submod, objname) if class_selector(obj): if instantiate == True: - obj = obj() + try: + obj = obj() + except Exception, e: + logging.error('could not instantiate %s from %s: %s' + % (obj, submodname, e)) + raise name = getattr(obj, 'name', submodname) objs[name] = obj return objs @@ -121,7 +125,12 @@ def construct_graph(this_modname, submodnames, class_selector, for objname in dir(submod): obj = getattr(submod, objname) if class_selector(obj): - instance = obj() + try: + instance = obj() + except Exception, e: + logging.error('could not instantiate %s from %s: %s' + % (obj, submodname, e)) + raise if assert_name_match == True and instance.name != submodname: raise Exception( 'Instance name %s does not match module name %s'