#!/usr/bin/python

import sys
import os
import os.path
import types

def getClass(directory, classType, name):
    
    sys.path.insert(0, directory)
    classes = {}
    file = "%s.py" % name

    if not os.path.isfile(os.path.join(directory, file)):
        return None

    if file.startswith("_"):
        return None

    mod = __import__(name)

    for (n, obj) in mod.__dict__.items():
        print n, obj
        #if type(obj) is not types.ClassType:
        #    continue
        # XXX: python 2.4.1 bug??
        if type(obj) is not type(object):
            continue
        if not issubclass(obj, classType):
            continue
        if obj is classType:
            continue

        # Basica sanity checks done we have a class of the correct parent
        if n == name:
            return obj

    # Found nothing...should not get here
    return None

