Skip to content

ark_cache_action

ArkCacheAction

Bases: ArkAction

Source code in ark_sdk_python/actions/ark_cache_action.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class ArkCacheAction(ArkAction):
    @overrides
    def define_action(self, subparsers: argparse._SubParsersAction) -> None:
        """
        Defines the CLI `cache` action, and adds the clear cache function.

        Args:
            subparsers (argparse._SubParsersAction): _description_
        """
        cache_parser: argparse.ArgumentParser = subparsers.add_parser('cache')
        self._common_actions_configuration(cache_parser)
        cache_cmd_subparsers = cache_parser.add_subparsers(dest="cache_cmd")
        cache_cmd_subparsers.required = True
        cache_cmd_subparsers.add_parser('clear', help='Clears all profiles cache')

    def __run_clear_cache_action(self) -> None:
        if isinstance(ArkKeyring.get_keyring(), BasicKeyring):
            cache_folder_path = os.path.join(os.path.expanduser('~'), DEFAULT_BASIC_KEYRING_FOLDER)
            if ARK_BASIC_KEYRING_FOLDER_ENV_VAR in os.environ:
                cache_folder_path = os.environ[ARK_BASIC_KEYRING_FOLDER_ENV_VAR]
            os.unlink(f'{cache_folder_path}{os.sep}keyring')
            os.unlink(f'{cache_folder_path}{os.sep}mac')
        else:
            ArkArgsFormatter.print_normal('Cache clear is only valid for basic keyring implementation at the moment')

    @overrides
    def run_action(self, args: argparse.Namespace) -> None:
        """
        Runs the cache action.

        Args:
            args (argparse.Namespace): _description_

        Raises:
            ArkException: _description_
        """
        if args.cache_cmd == 'clear':
            self.__run_clear_cache_action()
        else:
            raise ArkException(f'Invalid command {args.profile_cmd} given')

    @overrides
    def can_run_action(self, action_name: str, args: argparse.Namespace) -> bool:
        """
        Asserts the action is `cache`.

        Args:
            action_name (str): _description_
            args (argparse.Namespace): _description_

        Returns:
            bool: _description_
        """
        return action_name == 'cache'

can_run_action(action_name, args)

Asserts the action is cache.

Parameters:

Name Type Description Default
action_name str

description

required
args Namespace

description

required

Returns:

Name Type Description
bool bool

description

Source code in ark_sdk_python/actions/ark_cache_action.py
53
54
55
56
57
58
59
60
61
62
63
64
65
@overrides
def can_run_action(self, action_name: str, args: argparse.Namespace) -> bool:
    """
    Asserts the action is `cache`.

    Args:
        action_name (str): _description_
        args (argparse.Namespace): _description_

    Returns:
        bool: _description_
    """
    return action_name == 'cache'

define_action(subparsers)

Defines the CLI cache action, and adds the clear cache function.

Parameters:

Name Type Description Default
subparsers _SubParsersAction

description

required
Source code in ark_sdk_python/actions/ark_cache_action.py
13
14
15
16
17
18
19
20
21
22
23
24
25
@overrides
def define_action(self, subparsers: argparse._SubParsersAction) -> None:
    """
    Defines the CLI `cache` action, and adds the clear cache function.

    Args:
        subparsers (argparse._SubParsersAction): _description_
    """
    cache_parser: argparse.ArgumentParser = subparsers.add_parser('cache')
    self._common_actions_configuration(cache_parser)
    cache_cmd_subparsers = cache_parser.add_subparsers(dest="cache_cmd")
    cache_cmd_subparsers.required = True
    cache_cmd_subparsers.add_parser('clear', help='Clears all profiles cache')

run_action(args)

Runs the cache action.

Parameters:

Name Type Description Default
args Namespace

description

required

Raises:

Type Description
ArkException

description

Source code in ark_sdk_python/actions/ark_cache_action.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@overrides
def run_action(self, args: argparse.Namespace) -> None:
    """
    Runs the cache action.

    Args:
        args (argparse.Namespace): _description_

    Raises:
        ArkException: _description_
    """
    if args.cache_cmd == 'clear':
        self.__run_clear_cache_action()
    else:
        raise ArkException(f'Invalid command {args.profile_cmd} given')