Skip to content

Commit

Permalink
Do not overwrite existing yaml files by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesper-friis committed Oct 27, 2024
1 parent d29adb8 commit 3c5b097
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions bindings/python/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@
location: Path to YAML file.
options: Supported options:
- `mode`: Mode for opening. Valid values are:
- `a`: Append to existing file or create new file (default).
- `r`: Open existing file for read-only.
- `w`: Truncate existing file or create new file.
- `a`: Open for writing, add to existing `location` (default).
- `r`: Open existing `location` for reading.
- `w`: Open for writing. If `location` exists, it is truncated.
- `soft7`: Whether to save using SOFT7 format.
- `single`: Whether the input is assumed to be in single-entity form.
If "auto" (default) the form will be inferred automatically.
Expand Down
14 changes: 7 additions & 7 deletions storages/python/python-storage-plugins/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def open(self, location: str, options=None):
location: Path to YAML file.
options: Supported options:
- `mode`: Mode for opening. Valid values are:
- `a`: Append to existing file or create new file (default).
- `r`: Open existing file for read-only.
- `w`: Truncate existing file or create new file.
- `a`: Open for writing, add to existing `location` (default).
- `r`: Open existing `location` for reading.
- `w`: Open for writing. If `location` exists, it is truncated.
- `soft7`: Whether to save using SOFT7 format.
- `single`: Whether the input is assumed to be in single-entity form.
If "auto" (default) the form will be inferred automatically.
Expand All @@ -35,13 +35,13 @@ def open(self, location: str, options=None):
self.options = Options(
options, defaults="mode=a;soft7=true;single=auto;with_uuid=false"
)
self.readable = "r" in self.options.mode
self.writable = "r" != self.options.mode
mode = self.options.mode
self.writable = "w" in mode or "a" in mode
self.generic = True
self.location = location
self.flushed = False # whether buffered data has been written to file
self.flushed = True # whether buffered data has been written to file
self._data = {} # data buffer
if self.options.mode in ("r", "a", "append"):
if "r" in mode or "a" in mode:
with open(location, "r") as f:
data = pyyaml.safe_load(f)
if data:
Expand Down

0 comments on commit 3c5b097

Please sign in to comment.