Settings

pydetecdiv.settings

Settings management according to XDG base directory specification http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html

class pydetecdiv.settings.UuidNamespace

Bases: object

Name space definition for the creation of uuid5 unique ids

pydetecdiv.settings.get_default_settings() dict

Returns default values for configuration if no configuration file is found

Returns:

a dictionary containing the default values

pydetecdiv.settings.get_config_dir() Path

Returns the directory containing the pyDetecDiv configuration files

Returns:

the config directory path

pydetecdiv.settings.get_config_files() list[Path]

Get a list configuration files conforming to the XDG Base directory specification for Linux and Mac OS or located in APPDATA folder for Microsoft Windows. This function does not check whether files exist as this is done anyway while trying to read configuration.

Returns:

a list of configuration files

pydetecdiv.settings.get_config_file() Path

Gets the first configuration file in the list of available configuration files

Returns:

the path f the configuration file

pydetecdiv.settings.get_config() ConfigParser

Get configuration parser from configuration files. If no file exists, then one is created in the favourite location with default values. Note that if the favourite directory does not exist either, it is created prior to saving the configuration.

Returns:

a configuration parser

pydetecdiv.settings.get_config_value(section: str, key: str) str

Get value for a key in a section of the configuration file.

Parameters:
  • section – the configuration section

  • key – the configuration key

Returns:

the corresponding value

pydetecdiv.settings.get_appdata_dir() Path

get the local Application directory (.local/share/pyDetecDiv on Linux, AppDatapyDetecDiv on Windows)

Returns:

the path to the local application directory

pydetecdiv.settings.get_plugins_dir() Path

Get the user directory where plugins are installed. The directory is created if it does not exist

Returns:

the user plugin path

pydetecdiv.settings.get_default_workspace_dir() Path

Get the user workspace directory. The default directory is not created if it does not exist to avoid confusion. It is up to the user to make sure the directory exists or select an existing directory.

Returns:

the user workspace path

pydetecdiv.settings.datapath_file(datapath_filename: str = '.datapath_list.csv') Path

Return the path to data source list file

Returns:

the path to the data source list file

pydetecdiv.settings.datapath_list(datapath_filename: str = '.datapath_list.csv', grouped: bool = False) DataFrame | GroupBy

Returns a DataFrame containing the data source dir definitions

Returns:

data source dir definitions

pydetecdiv.settings.all_path_ids(df: DataFrame) DataFrame

Returns all defined path ids on all devices

Parameters:

df – the DataFrame containing the data source path definitions

Returns:

a DataFrame containing only path ids

class pydetecdiv.settings.Device

Bases: object

A class handling device-specific methods, used to get information about the current device and adapt configuration thereto

classmethod name() str

returns the name of the current device

Returns:

the device name

classmethod mac() str

returns the MAC address of the current device

Returns:

the device MAC address

classmethod add_path(name: str, path: Path | str, path_id: str = None) None
Adds a new path specification for the current device. If path_id is None (i.e. this data source has not been set already on

any device) then a new id is generated from the MAC address and the current time. Otherwise, the specified path id is used, which is the case to add a path specification for a path that was created on another device. If the pair of values (path, MAC address) is already present in the list, then the name value of the corresponding row is updated.

Parameters:
  • name – the user-defined name of the data source on the current device

  • path – the path of the data source on the current device

  • path_id – the cross-device path id of the data source

classmethod data_path(path_id: str) str | None

Returns the data source path corresponding to the path_id on the current device

Parameters:

path_id – the path id

Returns:

the data source path corresponding to the path_id on the current device

classmethod path_id(path: str) str | None

Given a path, finds the corresponding root path (mounting point) for the current device and returns the path variable.

Parameters:

path – the path

Returns:

the path variable id to use in the database

classmethod path_ids(df: DataFrame) DataFrame

Returns path ids defined on the current device

Parameters:

df – the dataframe containing the list of data source path definitions

Returns:

a dataframe with the path ids that are defined for the current device

classmethod undefined_path_ids() DataFrame

Returns path ids undefined on the current device

Returns:

a dataframe of path ids that are not defined on the current device

classmethod undefined_paths() DataFrame

Returns all data source paths defined on other devices that are not defined on the current one.

Returns:

a dataframe with the data source paths

classmethod datapath_list() DataFrame

Returns a list of data source paths defined on the current device, identified by the MAC address or the device name.

Returns:

a dataframe with the list of data source paths

classmethod get_path_id_and_url(abs_url) tuple

Returns the path id and relative url corresponding to the absolute url on the current device .

Returns:

a tuple containing the path_id and the relative url

pydetecdiv.settings.create_path_id(as_string: bool = False) UUID | str

Creates a unique identifier for data source path, from the device name and current time

Returns:

the uuid5