From 92e214f42ccd007d6ab1d45bbd78bfa64c6fb1ed Mon Sep 17 00:00:00 2001 From: Javier Luraschi Date: Tue, 26 Nov 2024 12:33:55 -0800 Subject: [PATCH] [python] automatically create storage folder --- CHANGELOG.md | 4 ++++ python/hal9/events.py | 3 +++ python/hal9/iobind.py | 8 ++++++++ python/pyproject.toml | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a297af90..4d8ef038 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.8.1 + +- Automatically create `.storage` folder when it does not exist + ## 2.8.0 - `save()` now stores data under `/.storage` diff --git a/python/hal9/events.py b/python/hal9/events.py index 393687c9..87f88067 100644 --- a/python/hal9/events.py +++ b/python/hal9/events.py @@ -2,6 +2,9 @@ import os def event(name, details): + if not os.path.exists('.storage'): + os.mkdir('.storage') + events_file = '.storage/.events' if os.path.exists(events_file): diff --git a/python/hal9/iobind.py b/python/hal9/iobind.py index f5827e20..59d7444b 100644 --- a/python/hal9/iobind.py +++ b/python/hal9/iobind.py @@ -41,7 +41,13 @@ def get_hidden(file_path): return hidden_path return file_path +def ensure_storage(): + if not os.path.exists('.storage'): + os.mkdir('.storage') + def load(name, default): + ensure_storage() + file_path = ".storage/" + name file_path = find_extension(file_path) file_path = get_hidden(file_path) @@ -66,6 +72,8 @@ def load(name, default): return contents def save(name, contents = None, hidden = False, files = None): + ensure_storage() + if not isinstance(name, str): raise Exception(f"The name parameter in save() must be a string, got {str(type(name))}") diff --git a/python/pyproject.toml b/python/pyproject.toml index 4fdd0f3d..716da93e 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "hal9" -version = "2.8.0" +version = "2.8.1" description = "" authors = ["Javier Luraschi "] readme = "README.md"