Beispiel #1
0
def _load_module(option, opt, value, parser):
    try:
        reflect.named_module(value)
    except ImportError, e:
        from feat.common import error
        raise OptionError("Cannot import module %s: %s" % (
            value, error.get_exception_message(e))), None, sys.exc_info()[2]
Beispiel #2
0
    def load(self):
        self.debug("Loading application %s", self.name)
        for module in self.loadlist:
            self.debug("Importing module %s", module)
            if module in sys.modules:
                self.debug("Module %s is already available in sys.modules.", module)
            else:
                reflect.named_module(module)

        self.load_adapters()
Beispiel #3
0
    def load(self):
        self.info("Loading application %s", self.name)
        for module in self.loadlist:
            self.debug("Importing module %s", module)
            if module in sys.modules:
                self.warning("Module %s is already available in sys.modules.",
                             module)
            else:
                reflect.named_module(module)

        if self._adapter_hook in interface.adapter_hooks:
            self.warning("Adapter hook has already been present")
        else:
            interface.adapter_hooks.append(self._adapter_hook)
Beispiel #4
0
    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')
Beispiel #5
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)
Beispiel #6
0
 def load(self, module):
     reflect.named_module(module)
Beispiel #7
0
 def import_module(self, module):
     '''import_module(canonical_name) -> Load the given module to memory.'''
     return reflect.named_module(module)
Beispiel #8
0
def _load_module(option, opt, value, parser):
    try:
        reflect.named_module(value)
    except ImportError:
        raise OptionError("Unknown module %s" % value)
Beispiel #9
0
 def import_module(self, module):
     '''Load the given module to memory.'''
     return reflect.named_module(module)