def temp_file_structure(self, base_path, files_repr): self.make_file_structure(base_path, files_repr) try: yield finally: with swallow_os_errors(): self.cleanup_files(base_path, base_path != '')
def save_to_file(self, filename, comment=None): success = False try: json_repr = self.json_representation() # Override saved comment without changing .comment field in plan if comment is not None: json_repr['comment'] = comment with open(filename, 'wt') as f: json.dump(self.json_representation(), f, indent=4) success = True except PermissionError: raise CannotSaveRenamePlanPermissionsError(filename) from None except OSError: raise CannotSaveRenamePlanFailedWritingFileError(filename) from None except Exception as e: raise CannotSaveRenamePlanOtherError(filename, e) from None finally: if not success: with swallow_os_errors(): os.remove(filename)