nfsops.utils module

Utility functions.

nfsops.utils.expand_name_template(template: str, name: str) str

Expand template placeholders to the name value.

Supported placeholders:

  • {name}

  • {legacy_escaped_name}

Parameters
  • template (str) – Template string.

  • name (str) – Name value.

Returns

str – A string with the name value in place of placeholders.

Raises

ValueError – Expected template placeholder not supported.

nfsops.utils.find_executable(name: str) pathlib.Path

Find the path to a Linux executable by name.

Parameters

name (str) – Executable name.

Returns

Path – A path object referencing the executable.

Raises

KeyError – Expected executable path not found.

nfsops.utils.format_configuration_string(configuration: nfsops.configurations.configuration.Configuration) str

Format configuration object to string using the formatting style [key0=value0 key1=value1 … keyn=valuen].

Parameters

configuration (Configuration) – Configuration instance.

Returns

str – A single-line string using custom formatting style.

nfsops.utils.get_default_logger() logging.Logger

Return the default logger instance. Set the NFSOPS_LOG_LEVEL environment variable to define log level.

Levels:

  • critical (default)

  • fatal

  • error

  • warn

  • warning

  • info

  • debug

  • notset

Returns

Logger – A default logger instance for package.

nfsops.utils.get_default_volume_path(context: nfsops.context_type.ContextType) pathlib.Path

Return default volume path for context type.

Default values:

  • ContextType.ROOT: /var/nfs-shared

  • ContextType.SUBPATH: $HOME

Parameters

context (ContextType) – Context type.

Returns

Path – A path object referencing the default volume path.

nfsops.utils.timezone_aware(date: datetime.datetime) datetime.datetime

Convert naive to timezone-aware datetime (UTC timezone).

Parameters

date (datetime) – Datetime object.

Returns

datetime – A timezone-aware datetime.