XDG folders

logging_strict.util.xdg_folder.__all__: tuple[str, ...] = ("DestFolderSite", "DestFolderUser", "_get_path_config")

Module object exports

Get XDG user or site folders.

MacOS, to avoid name possible app naming collisions, requires app author name. If a package doesn’t specify an app author, e.g. selenium, the code must specify it using class property, appauthor.

appauthor is normalized for use as a folder name.

If a package doesn’t reveal the author, the appauthor is None. The (relative) folder path becomes [appname]/None. So coder should use the class property setter, appauthor, to specify what they’d like the appauthor to be.

Package platformdirs author unilaterally decided that appauthor is unnecessary; that name collisions are rare enough to be a detail better left out.

Contend that decision is not the platformdirs author to make. If OS platform compatability is important then avoid platformdirs.

Get XDG cache dir for typical package

from logging_strict.util.xdg_folder import DestFolderUser

package = "appdirs"  # with author attribution
xdg_user = DestFolderUser(package)
assert isinstance(xdg_user.cache_dir, str)

Get XDG cache dir for package without author attribution

from logging_strict.util.xdg_folder import DestFolderUser

package = "selenium"  # lacks author attribution
xdg_user = DestFolderUser(package)
xdg_user.appauthor = "John Doe"  # MacOS thanks you
assert isinstance(xdg_user.cache_dir, str)
class logging_strict.util.xdg_folder.DestFolderSite(appname, author_no_period=True, author_no_space=True, author_no_underscore=True, version=None, multipath=False)

XDG Site folders

Variables:
  • appname (str) – Package name

  • author_no_period (str) – Default True. True if should remove period from author name otherwise False

  • author_no_space (str) – Default True. True if should remove whitespace from author name otherwise False

  • author_no_underscore (str) – Default True. True if should remove underscore from author name otherwise False

  • version (str | None) – Default None. Possible to have version specific author information. Can specific version

  • multipath (bool | None) – Default False. Could retrieve all possible folders. True for multipath. False for first entry in multipath

_multipath
property config_dir

Get XDG site config dir

Returns:

XDG site config dir

Return type:

str

property data_dir

Get XDG site data dir

Returns:

XDG site data dir

Return type:

str

property multipath

multipath getter

Return type:

bool

class logging_strict.util.xdg_folder.DestFolderUser(appname, author_no_period=True, author_no_space=True, author_no_underscore=True, version=None, roaming=False, opinion=True)

XDG User folders

Variables:
  • appname (str) – Package name

  • author_no_period (str) – Default True. True if should remove period from author name otherwise False

  • author_no_space (str) – Default True. True if should remove whitespace from author name otherwise False

  • author_no_underscore (str) – Default True. True if should remove underscore from author name otherwise False

  • version (str | None) – Default None. Possible to have version specific author information. Can specific version

  • roaming (bool | None) – Default False. Only applicable to Windows

  • opinion (bool | None) – Default True. ??

_opinion
_roaming
property cache_dir

Get XDG user cache dir

Returns:

XDG user cache dir

Return type:

str

property config_dir

Get XDG user config dir

Returns:

XDG user config dir

Return type:

str

property data_dir

Get XDG user data dir

Returns:

XDG user data dir

Return type:

str

property log_dir

Get XDG user log dir

Returns:

XDG user log dir

Return type:

str

property opinion

Property getter

Return type:

bool

property roaming

Property getter

Return type:

bool

property state_dir

Get XDG user state dir

Returns:

XDG user state dir

Return type:

str

logging_strict.util.xdg_folder._get_path_config(package, author_no_period=True, author_no_space=True, author_no_underscore=True, version=None, roaming=False)

Mockable module level function. Gets the user data folder, not the user config folder

Parameters:
  • package (str) – Target package, might not be ur package!

  • author_no_period (bool) – Default True. If True removes period

  • author_no_space (bool) – Default True. If True replaced with hyphen

  • author_no_underscore (bool) – Default True. If True replaced with hyphen

Returns:

user data folder Path

Return type:

pathlib.Path