Beispiel #1
0
    def get_app_action(self, app_name, action_name):
        """
        Gets the action function for a given app and action name

        Args:
            app_name (str): Name of the app
            action_name(str): Name of the action

        Returns:
            (func) The action
        """
        try:
            app_cache = self._cache[app_name]
            if 'actions' not in app_cache:
                _logger.warning(
                    'App {} has no actions. Returning None'.format(app_name))
                raise UnknownAppAction(app_name, action_name)
        except KeyError:
            _logger.error('Cannot locate app {} in cache!'.format(app_name))
            raise UnknownApp(app_name)
        try:
            return app_cache['actions'][action_name]['run']
        except KeyError:
            _logger.error('App {0} has no action {1}'.format(
                app_name, action_name))
            raise UnknownAppAction(app_name, action_name)
Beispiel #2
0
    def is_app_action_bound(self, app_name, action_name):
        """
        Determines if the action is bound (meaning it's inside a class) or not

        Args:
            app_name (str): Name of the app
            action_name(str): Name of the action

        Returns:
            (bool) Is the action bound?
        """
        try:
            app_cache = self._cache[app_name]
            if 'actions' not in app_cache:
                _logger.warning(
                    'App {} has no actions. Returning None'.format(app_name))
                raise UnknownAppAction(app_name, action_name)
        except KeyError:
            _logger.error('Cannot locate app {} in cache!'.format(app_name))
            raise UnknownApp(app_name)
        try:
            return app_cache['actions'][action_name]['bound']
        except KeyError:
            _logger.error('App {0} has no action {1}'.format(
                app_name, action_name))
            raise UnknownAppAction(app_name, action_name)
Beispiel #3
0
    def is_app_action_bound(self, app_name, action_name):
        """Determines if the action is bound (meaning it's inside a class) or not

        Args:
            app_name (str): Name of the app
            action_name(str): Name of the action

        Returns:
            bool: Is the action bound?

        Raises:
            UnknownApp: If the app is not found in the cache
            UnknownAppAction: If the app does not have the specified action
        """
        try:
            app_cache = self._cache[app_name]
            if 'actions' not in app_cache:
                _logger.warning('App {} has no actions'.format(app_name))
                raise UnknownAppAction(app_name, action_name)
        except KeyError:
            _logger.error('Cannot locate app {} in cache!'.format(app_name))
            raise UnknownApp(app_name)
        try:
            return app_cache['actions'][action_name]['bound']
        except KeyError:
            _logger.error('App {0} has no action {1}'.format(app_name, action_name))
            raise UnknownAppAction(app_name, action_name)
Beispiel #4
0
    def validate_app_actions(app, actions):
        """Validates that an app's actions are valid, meaning that they exist in a defined app API

        Args:
            app (str): The app to validate
            actions (str): The action to validate

        Returns:
            set(str): The actions. Expanded to all known actions if `action` was 'all'

         Raises:
            UnknownApp: If the app specified is not found in all known app APIs or the app has no actions
            UnknownAppAction: If the action is not found in the give app's actions
        """
        try:
            available_actions = set(
                core.config.config.app_apis[app]['actions'].keys())
            if actions == 'all':
                return available_actions
            actions = set(convert_to_iterable(actions))
            if actions - available_actions:
                message = 'Unknown actions for app {0}: {1}'.format(
                    app, list(set(actions) - set(available_actions)))
                _logger.error(message)
                raise UnknownAppAction(app, actions)
            return actions
        except KeyError:
            message = 'Unknown app {} or app has no actions'.format(app)
            _logger.exception(message)
            raise UnknownApp(app)
Beispiel #5
0
def get_app_action(app_name, action_name):
    try:
        app = App.registry[app_name]
    except KeyError:
        raise UnknownApp(app_name)
    else:
        try:
            return app['actions'][action_name]
        except:
            raise UnknownAppAction(app_name, action_name)