9.2.6. Utils

General utilities and helpers.

class junifer.utils.ConfigManager(*args, **kwargs)

Manage configuration parameters.

Attributes:
_configdict

Configuration parameters.

Initialize the class.

delete(key)

Delete configuration parameter.

Parameters:
keystr

The configuration key to delete.

get(key, default=None)

Get configuration parameter.

Parameters:
keystr

The configuration key to get.

defaultbool or int or float or None, optional

The default value to return if the key is not found (default None).

Returns:
bool or int or float

The configuration value.

set(key, val)

Set configuration parameter.

Parameters:
keystr

The configuration key to set.

valbool or int or float

The value to set key to.

junifer.utils.configure_logging(level='WARNING', level_datalad=None)

Configure the logging functionality.

Parameters:
levelint or {“DEBUG”, “INFO”, “WARNING”, “ERROR”}

The level of the messages to print. If string, it will be interpreted as elements of logging (default “WARNING”).

level_dataladint or {“DEBUG”, “INFO”, “WARNING”, “ERROR”}, optional

The level of the messages to print for datalad. If string, it will be interpreted as elements of logging. If None, it will be set as the level parameter (default None).

junifer.utils.deep_update(d, u)

Deep update d with u.

From: “https://stackoverflow.com/questions/3232943/update-value-of-a-nested -dictionary-of-varying-depth”

Parameters:
ddict

The dictionary to deep-update.

udict

The dictionary to deep-update d with.

Returns:
dict

The updated dictionary.

junifer.utils.make_executable(path)

Make path executable.

Parameters:
pathpathlib.Path

The path to make executable.

junifer.utils.raise_error(msg, klass=<class 'ValueError'>, exception=None)

Raise error, but first log it.

Parameters:
msgstr

The message for the exception.

klasssubclass of Exception, optional

The subclass of Exception to raise using (default ValueError).

exceptionException, optional

The original exception to follow up on (default None).

junifer.utils.run_ext_cmd(name, cmd)

Run external command via subprocess.

Parameters:
namestr

The name of the command.

cmdlist of str

The command to run as list of string.

Raises:
RuntimeError

If command fails.

junifer.utils.warn_with_log(msg, category=<class 'RuntimeWarning'>)

Warn, but first log it.

Parameters:
msgstr

Warning message.

categorysubclass of Warning, optional

The warning subclass (default RuntimeWarning).