multipackage.utilities.file_ops module

Helper utilities for file operations.

Summary

Functions:

atomic_json Atomically dump a dict as a json file.
atomic_save Attempt to atomically save file by saving and then moving into position

Reference

multipackage.utilities.file_ops.atomic_save(target_path, data, encoding='utf-8')[source]

Attempt to atomically save file by saving and then moving into position

The goal is to make it difficult for a crash to corrupt our data file since the move operation can be made atomic if needed on mission critical filesystems. This operation uses os.rename on non-Windows systems for atomic updates but normal saves on Windows since atomic semantics are not properly supported.

Parameters:
  • target_path (str) – The final path that the file should have.
  • data (str) – The data that we want to save.
  • encoding (str) – The file encoding that we should use, defaults to utf-8 if not specified.
multipackage.utilities.file_ops.atomic_json(target_path, obj)[source]

Atomically dump a dict as a json file.

Parameters:
  • target_path (str) – The final path that the file should have.
  • obj (dict) – The dictionary that should be dumped.