Exemplo n.º 1
0
def _execute(executor_type, pathitems, params):
    """Execute an action as specified by the path"""
    try:
        executor = executor_type(params).__getattribute__(pathitems[0] if pathitems else 'root')
    except AttributeError:
        raise InvalidPathError('Unknown action {}'.format('/'.join(pathitems)))
    LOG.debug('Invoking action: {}', executor.__name__)
    executor(pathitems=pathitems)
Exemplo n.º 2
0
def _call_instance_func(instance, func_name, data):
    try:
        func = getattr(instance, func_name)
    except AttributeError as exc:
        raise InvalidPathError(f'Function {func_name} not found') from exc
    if isinstance(data, dict):
        return func(**data)
    if data is not None:
        return func(data)
    return func()
Exemplo n.º 3
0
def _call(instance, func_name, data):
    try:
        func = getattr(instance, func_name)
    except AttributeError:
        raise InvalidPathError('Name of the method {} not found'.format(func_name))
    if isinstance(data, dict):
        return func(**data)
    if data is not None:
        return func(data)
    return func()
Exemplo n.º 4
0
def _execute(executor_type, pathitems, params, root_handler):
    """Execute an action as specified by the path"""
    try:
        executor = executor_type(params).__getattribute__(pathitems[0] if pathitems else 'root')
    except AttributeError as exc:
        raise InvalidPathError(f'Unknown action {"/".join(pathitems)}') from exc
    LOG.debug('Invoking action: {}', executor.__name__)
    executor(pathitems=pathitems)
    if root_handler == G.MODE_DIRECTORY and not G.IS_ADDON_EXTERNAL_CALL:
        # Save the method name of current loaded directory and his menu item id
        WndHomeProps[WndHomeProps.CURRENT_DIRECTORY] = executor.__name__
        WndHomeProps[WndHomeProps.CURRENT_DIRECTORY_MENU_ID] = pathitems[1] if len(pathitems) > 1 else ''
        WndHomeProps[WndHomeProps.IS_CONTAINER_REFRESHED] = None
Exemplo n.º 5
0
def _execute(executor_type, pathitems, params, root_handler):
    """Execute an action as specified by the path"""
    try:
        executor = executor_type(params).__getattribute__(
            pathitems[0] if pathitems else 'root')
        LOG.debug('Invoking action: {}', executor.__name__)
        executor(pathitems=pathitems)
        if root_handler == G.MODE_DIRECTORY:
            # Save the method name of current loaded directory
            G.CURRENT_LOADED_DIRECTORY = executor.__name__
            G.IS_CONTAINER_REFRESHED = False
    except AttributeError as exc:
        raise_from(
            InvalidPathError('Unknown action {}'.format('/'.join(pathitems))),
            exc)
Exemplo n.º 6
0
def _get_nav_handler(root_handler, pathitems):
    nav_handler = None
    if root_handler == G.MODE_DIRECTORY:
        from resources.lib.navigation.directory import Directory
        nav_handler = Directory
    if root_handler == G.MODE_ACTION:
        from resources.lib.navigation.actions import AddonActionExecutor
        nav_handler = AddonActionExecutor
    if root_handler == G.MODE_LIBRARY:
        from resources.lib.navigation.library import LibraryActionExecutor
        nav_handler = LibraryActionExecutor
    if not nav_handler:
        raise InvalidPathError('No root handler for path {}'.format(
            '/'.join(pathitems)))
    return nav_handler
Exemplo n.º 7
0
def _get_nav_handler(root_handler, pathitems):
    if root_handler == G.MODE_DIRECTORY:
        from resources.lib.navigation.directory import Directory
        nav_handler = Directory
    elif root_handler == G.MODE_ACTION:
        from resources.lib.navigation.actions import AddonActionExecutor
        nav_handler = AddonActionExecutor
    elif root_handler == G.MODE_LIBRARY:
        from resources.lib.navigation.library import LibraryActionExecutor
        nav_handler = LibraryActionExecutor
    elif root_handler == G.MODE_KEYMAPS:
        from resources.lib.navigation.keymaps import KeymapsActionExecutor
        nav_handler = KeymapsActionExecutor
    else:
        raise InvalidPathError(f'No root handler for path {"/".join(pathitems)}')
    return nav_handler
Exemplo n.º 8
0
def route(pathitems):
    """Route to the appropriate handler"""
    LOG.debug('Routing navigation request')
    root_handler = pathitems[0] if pathitems else G.MODE_DIRECTORY
    if root_handler == G.MODE_PLAY:
        from resources.lib.navigation.player import play
        play(videoid=pathitems[1:])
    elif root_handler == G.MODE_PLAY_STRM:
        from resources.lib.navigation.player import play_strm
        play_strm(videoid=pathitems[1:])
    elif root_handler == 'extrafanart':
        LOG.warn('Route: ignoring extrafanart invocation')
        return False
    else:
        nav_handler = _get_nav_handler(root_handler)
        if not nav_handler:
            raise InvalidPathError('No root handler for path {}'.format('/'.join(pathitems)))
        _execute(nav_handler, pathitems[1:], G.REQUEST_PARAMS)
    return True