示例#1
0
def load(module_name, name):
    log.info('application', "Importing application %s from module %s",
             name, module_name)
    module = sys.modules.get(module_name)
    if module:
        log.warning('application',
                    "Application module %s has already been loaded. ",
                    module_name)
    else:
        module = reflect.named_module(module_name)
    application = getattr(module, name, None)
    if application is None:
        raise ValueError('Module %s has no attribute %s' % (module_name, name))
    if not IApplication.providedBy(application):
        raise ValueError('Variable %s.%s should provide IApplication interface'
                         % (module_name, name))
    try:
        application.load()
    except Exception as e:
        error.handle_exception(
            'application', e, 'Error loading application: %s',
            application.name)
        application.unload()
        raise
    else:
        get_application_registry().register(application)
        log.info('application', "Loading application %s complete.", name)
示例#2
0
文件: imports.py 项目: f3at/feattool
    def do_import(self, iter, force=False):
        canonical_name, auto = self._parse_row(iter)

        if force or auto:
            try:
                o = reflect.named_object(canonical_name)
                if IApplication.providedBy(o):
                    o.load()
                elif isinstance(o, types.ModuleType):
                    reflect.named_module(canonical_name)
                else:
                    raise TypeError("Uknown type of canonical name target: "
                                    "%r -> %s" % (canonical_name, type(o)))
            except Exception, e:
                error.handle_exception('imports', e, 'Error importing')