Ejemplo n.º 1
0
    def _loadPackage(self, path):
        if self.isPackageLoaded(path):
            return
        LOG_DEBUG('Tries to load GUI package', path)
        imported = importlib.import_module(path)
        try:
            settings = imported.getViewSettings()
        except AttributeError:
            LOG_CURRENT_EXCEPTION()
            raise Exception(
                'Package {0} does not have method getViewSettings'.format(
                    path))

        aliases = g_entitiesFactories.initSettings(settings)
        try:
            handlers = imported.getContextMenuHandlers()
        except AttributeError:
            LOG_CURRENT_EXCEPTION()
            raise Exception(
                'Package {0} does not have method getContextMenuHandlers'.
                format(path))

        contextMenuTypes = context_menu.registerHandlers(*handlers)
        try:
            handlers = imported.getBusinessHandlers()
        except AttributeError:
            LOG_CURRENT_EXCEPTION()
            raise Exception(
                'Package {0} does not have method getBusinessHandlers'.format(
                    path))

        processed = set()
        for handler in handlers:
            if not isinstance(handler, PackageBusinessHandler):
                for handler in processed:
                    handler.fini()

                raise Exception(
                    'Package {0} has invalid business handler {1}'.format(
                        path, handler.__class__.__name__))
            handler.init()
            processed.add(handler)

        self._aliases[path] = aliases
        self._handlers[path] = processed
        self._contextMenuTypes[path] = contextMenuTypes
    def _loadPackage(self, path, arenaGuiType, isExtention):
        if self.isPackageLoaded(path):
            return
        _logger.debug('Tries to load GUI package "%s"', path)
        imported = importlib.import_module(path)
        try:
            settings = imported.getViewSettings()
            if not isExtention:
                settings = self._getHandlesWithoutExtensionOverride(settings, arenaGuiType)
        except AttributeError:
            _logger.exception('Package "%s" can not be loaded', path)
            raise SoftException('Package {0} does not have method getViewSettings'.format(path))

        aliases = g_entitiesFactories.initSettings(settings)
        self._aliases[path] = aliases
        try:
            handlers = imported.getContextMenuHandlers()
            if not isExtention:
                handlers = self._getHandlesWithoutExtensionOverride(handlers, arenaGuiType)
        except AttributeError:
            _logger.exception('Package "%s" can not be loaded', path)
            raise SoftException('Package {0} does not have method getContextMenuHandlers'.format(path))

        contextMenuTypes = context_menu.registerHandlers(*handlers)
        self._contextMenuTypes[path] = contextMenuTypes
        try:
            handlers = imported.getBusinessHandlers()
        except AttributeError:
            _logger.exception('Package "%s" can not be loaded', path)
            raise SoftException('Package {0} does not have method getBusinessHandlers'.format(path))

        processed = set()
        for handler in handlers:
            if not isinstance(handler, PackageBusinessHandler):
                for h in processed:
                    h.fini()

                raise SoftException('Package {0} has invalid business handler {1}'.format(path, handler.__class__.__name__))
            handler.init()
            processed.add(handler)

        self._handlers[path] = processed