Skip to content

Commit 1d24cc9

Browse files
committed
version 0.2.11
1 parent 261a44e commit 1d24cc9

File tree

8 files changed

+27
-22
lines changed

8 files changed

+27
-22
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ This release will contain a lot of new features and improvements so that a versi
2525
Not finalised:
2626
- cookie auth & its specification in TD (cookie auth branch)
2727

28+
## [v0.2.11] - 2025-04-25
29+
30+
- new feature - support for JSON files as backup for property values (use with `db_commit`, `db_persist` and `db_init`). Compatible only with JSON serializable properties.
31+
2832
## [v0.2.10] - 2025-04-05
2933

3034
- bug fixes to support `class_member` properties to work with `fget`, `fset` and `fdel` methods. While using custom `fget`, `fset` and `fdel` methods for `class_member`s,

examples

hololinked/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.2.10"
1+
__version__ = "0.2.11"

hololinked/server/json_storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import threading
3-
from .serializers import JSONSerializer
43
from typing import Any, Dict, List, Optional, Union
4+
from .serializers import JSONSerializer
55
from .property import Property
66
from ..param import Parameterized
77

hololinked/server/td.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import typing, inspect
22
from dataclasses import dataclass, field
33

4-
from hololinked.server.eventloop import EventLoop
54

65

76
from .constants import JSON, JSONSerializable
@@ -12,6 +11,7 @@
1211
from .property import Property
1312
from .thing import Thing
1413
from .state_machine import StateMachine
14+
from .eventloop import EventLoop
1515

1616

1717

hololinked/server/thing.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from .exceptions import BreakInnerLoop
1717
from .action import action
1818
from .dataklasses import HTTPResource, ZMQResource, build_our_temp_TD, get_organised_resources
19-
from .utils import get_default_logger, getattr_without_descriptor_read
19+
from .utils import get_a_filename_from_instance, get_default_logger, getattr_without_descriptor_read
2020
from .property import Property, ClassProperties
2121
from .properties import String, ClassSelector, Selector, TypedKeyMappingsConstrainedDict
2222
from .zmq_message_brokers import RPCServer, ServerTypes, EventPublisher
@@ -210,7 +210,7 @@ class attribute, see docs.
210210
# choose storage type, if use_json_file is True - use JSON storage, else - use database
211211
if kwargs.get('use_json_file',
212212
self.__class__.use_json_file if hasattr(self.__class__, 'use_json_file') else False):
213-
self._prepare_json_storage(filename=kwargs.get('json_filename', f"{self._prepare_json_filename()}"))
213+
self._prepare_json_storage(filename=kwargs.get('json_filename', f"{get_a_filename_from_instance(self, 'json')}"))
214214
else:
215215
self._prepare_DB(kwargs.get('use_default_db', False), kwargs.get('db_config_file', None))
216216

@@ -277,23 +277,10 @@ def _prepare_DB(self, default_db : bool = False, config_file : str = None):
277277

278278
def _prepare_json_storage(self, filename: str = None):
279279
if not filename:
280-
filename = f"{self._prepare_json_filename()}"
280+
filename = f"{get_a_filename_from_instance(self, 'json')}"
281281
self.db_engine = ThingJsonStorage(filename=filename, instance=self)
282282

283-
def _prepare_json_filename(self):
284-
class_name = self.__class__.__name__
285-
286-
# Remove invalid characters from the instance name
287-
safe_instance_name = re.sub(r'[<>:"/\\|?*\x00-\x1F]+', '_', self.instance_name)
288-
# Collapse consecutive underscores into one
289-
safe_instance_name = re.sub(r'_+', '_', safe_instance_name)
290-
# Remove leading and trailing underscores
291-
safe_instance_name = safe_instance_name.strip('_')
292-
293-
filename = f"{class_name}-{safe_instance_name or '_'}.json"
294-
return filename
295-
296-
283+
297284
@object_info.getter
298285
def _get_object_info(self):
299286
if not hasattr(self, '_object_info'):

hololinked/server/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,20 @@ def issubklass(obj, cls):
224224
return False
225225
except TypeError:
226226
return False
227+
228+
229+
def get_a_filename_from_instance(thing: type, extension: str = 'json') -> str:
230+
class_name = thing.__class__.__name__
231+
232+
# Remove invalid characters from the instance name
233+
safe_instance_name = re.sub(r'[<>:"/\\|?*\x00-\x1F]+', '_', thing.instance_name)
234+
# Collapse consecutive underscores into one
235+
safe_instance_name = re.sub(r'_+', '_', safe_instance_name)
236+
# Remove leading and trailing underscores
237+
safe_instance_name = safe_instance_name.strip('_')
238+
239+
filename = f"{class_name}-{safe_instance_name or '_'}.{extension}"
240+
return filename
227241

228242

229243
__all__ = [

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setuptools.setup(
99
name="hololinked",
10-
version="0.2.10",
10+
version="0.2.11",
1111
author="Vignesh Vaidyanathan",
1212
author_email="vignesh.vaidyanathan@hololinked.dev",
1313
description="A ZMQ-based Object Oriented RPC tool-kit for instrument control/data acquisition or controlling generic python objects.",

0 commit comments

Comments
 (0)