Skip to content

filesystem

dev_tool.config.filesystem

log = logging.getLogger(__name__) module-attribute

FilesystemConfig

A class for handling filesystem operations for configuration.

This class provides methods for resolving paths and reading configuration files.

get_resource_path

A method that resolves a resource path.

This method handles both packaged (frozen) and development environments by resolving the appropriate absolute path to a resource. In frozen builds bundled resources are persisted outside the volatile temp directory so they survive temp cleaners while the application is running.

Parameters:

  • path (str) –

    The relative path to the resource.

Returns:

  • Path

    The absolute Path to the resource.

Source code in dev_tool/config/filesystem.py
def get_resource_path(self, path: str) -> Path:
    """
    A method that resolves a resource path.

    This method handles both packaged (frozen) and development environments
    by resolving the appropriate absolute path to a resource. In frozen builds
    bundled resources are persisted outside the volatile temp directory so they
    survive temp cleaners while the application is running.

    :param path: The relative path to the resource.
    :return: The absolute Path to the resource.
    """

    if not hasattr(sys, '_MEIPASS'):
        return Path(__file__).parent.parent.parent / path

    self._sync_bundled_resources()

    if (RESOURCES / path).exists():
        return RESOURCES / path

    self._sync_bundled_resources(force=True)

    if (RESOURCES / path).exists():
        return RESOURCES / path

    return Path(sys._MEIPASS, path)

get_developer_token

A method that retrieves a developer token from a file.

This method reads a token from the specified file, stripping any whitespace.

Parameters:

  • path (Path) –

    The path to the file containing the token.

Returns:

  • str | None

    The token as a string, or None if the file doesn't exist.

Source code in dev_tool/config/filesystem.py
def get_developer_token(self, path: Path) -> str | None:
    """
    A method that retrieves a developer token from a file.

    This method reads a token from the specified file, stripping any whitespace.

    :param path: The path to the file containing the token.
    :return: The token as a string, or None if the file doesn't exist.
    """

    if not path.exists():
        return None

    with open(path, 'r', encoding='utf-8') as handle:
        return handle.read().strip()