Skip to content

gufo.thor.utils

Various utilities.

ensure_directory(path)

Check directory is exists and create, if necessary.

Parameters:

Name Type Description Default
path Path

Directory path.

required

merge_dict(x, y)

Deep merge dictionaries.

Do not affect source dictionaries. Second dictionary overrides first.

Parameters:

Name Type Description Default
x Dict[str, Any]

First dictionary.

required
y Dict[str, Any]

Second dictionary.

required

Returns:

Type Description
Dict[str, Any]

Merged dictionary.

write_file(path, content, backup_path=None)

Write data to file.

Overwrite file content only if changed. Create all nessessary directories.

Parameters:

Name Type Description Default
path Path

File path.

required
content Union[str, bytes]

File content.

required
backup_path Optional[Path]

Path to store a copy of file when overwritten.

None

Returns:

Name Type Description
True bool

if file was written.

False bool

if file wasn't changed.