# Path: fuzzy/utils.py
# def prop(func):
# def checkRange(value,ranges):


    import os,imp
from fuzzy.utils import inf_p,inf_n
# You should have received a copy of the GNU Lesser General Public License along with 
# this program; if not, see <http://www.gnu.org/licenses/>. 
#


__revision__ = "$Id: utils.py,v 1.6 2009/09/28 15:26:46 rliebscher Exp $"

def get_classes(package):
    """Find all classes defined in given directory
    and return them as dictionary {name,instance}"""
    package_name = package.__name__
    classes_dir = os.path.dirname(package.__file__)
    suffixes = [suffix[0] for suffix in imp.get_suffixes()]
    objects = {}
    for class_file in os.listdir(classes_dir):
        for suffix in suffixes:
            class_name = class_file[:-len(suffix)]
            if class_name == "__init__":
                break
            if  class_file[-len(suffix):] == suffix:
                module = __import__(package_name+"."+class_name)
                components = (package_name+"."+class_name).split('.')
                for comp in components[1:]:
                    module = getattr(module, comp)
                try:
                    objects.update({class_name: module.__dict__[class_name]()})
                except:
                    # probably no object with this name in file
                    pass
                break

# Path: fuzzy/utils.py
# def prop(func):
# def checkRange(value,ranges):


# Path: demo/utils.py
    import os,imp
from fuzzy.utils import inf_p,inf_n

# You should have received a copy of the GNU Lesser General Public License along with 
# this program; if not, see <http://www.gnu.org/licenses/>. 
#


__revision__ = "$Id: utils.py,v 1.6 2009/09/28 15:26:46 rliebscher Exp $"

def get_classes(package):
    """Find all classes defined in given directory
    and return them as dictionary {name,instance}"""
    package_name = package.__name__
    classes_dir = os.path.dirname(package.__file__)
    suffixes = [suffix[0] for suffix in imp.get_suffixes()]
    objects = {}
    for class_file in os.listdir(classes_dir):
        for suffix in suffixes:
            class_name = class_file[:-len(suffix)]
            if class_name == "__init__":
                break
            if  class_file[-len(suffix):] == suffix:
                module = __import__(package_name+"."+class_name)
                components = (package_name+"."+class_name).split('.')
                for comp in components[1:]:
                    module = getattr(module, comp)
                try:
                    objects.update({class_name: module.__dict__[class_name]()})
                except:
                    # probably no object with this name in file
                    pass
                break

    return objects