Exemplo n.º 1
0
def load(context):
    
    if ("modules" in os.listdir(os.path.join(os.path.curdir, MODULES_DIR_PREFIX))):
        context = load_all_rec(context, os.path.join(os.path.curdir, MODULES_DIR_PREFIX, "modules"), "modules")
    else :  
        print_error("No modules directory found, nothing to load...")      
        exit(-1)
Exemplo n.º 2
0
def load_all_rec(context, curdir, package):
    for f in os.listdir(curdir):
        fl = os.path.join(curdir,f)
        if (os.path.isdir(fl)):
            load_all_rec(context, fl, package + "." + f)
        elif (os.path.splitext(fl)[1] == ".py" and f != "__init__.py"):            
            print_debug ("Loading plugin " + package+"."+os.path.splitext(f)[0])
            module = importlib.import_module(package+"."+os.path.splitext(f)[0])
            try:             
                class_inst = module.main_class(context)
                context.modules.append(class_inst)
                try :
                     
                    assert((class_inst.get_role() != None  and class_inst.get_class() == None) or
                            (class_inst.get_role() == None  and class_inst.get_class() != None))
                    if (class_inst.get_role() != None) :
                        context.roles[class_inst.get_role()] = class_inst
                    else :
                        if (class_inst.get_class() in context.classes) :                            
                            context.classes[class_inst.get_class()].append(class_inst)
                        else :
                            context.classes[class_inst.get_class] = [class_inst]
                        
                        
                except :
                    print_error("Incorrent interface realization: " + str(sys.exc_info()[1]))
            except:
                print_warning("Cannot load " + package+"."+os.path.splitext(f)[0] + ", reason : " + str(sys.exc_info()[1]))
Exemplo n.º 3
0
def init(context):
    modules = context.modules
    modules.sort(cmp=lambda x, y : cmp(x.get_priority(), y.get_priority()))
    for module in modules :
        log.print_debug("Init module " + module.get_name())
        module.plugin()
    log.print_error("Unreachable point!")
    exit(-1)