|
16 | 16 | from .exceptions import BreakInnerLoop |
17 | 17 | from .action import action |
18 | 18 | 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 |
20 | 20 | from .property import Property, ClassProperties |
21 | 21 | from .properties import String, ClassSelector, Selector, TypedKeyMappingsConstrainedDict |
22 | 22 | from .zmq_message_brokers import RPCServer, ServerTypes, EventPublisher |
@@ -210,7 +210,7 @@ class attribute, see docs. |
210 | 210 | # choose storage type, if use_json_file is True - use JSON storage, else - use database |
211 | 211 | if kwargs.get('use_json_file', |
212 | 212 | 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')}")) |
214 | 214 | else: |
215 | 215 | self._prepare_DB(kwargs.get('use_default_db', False), kwargs.get('db_config_file', None)) |
216 | 216 |
|
@@ -277,23 +277,10 @@ def _prepare_DB(self, default_db : bool = False, config_file : str = None): |
277 | 277 |
|
278 | 278 | def _prepare_json_storage(self, filename: str = None): |
279 | 279 | if not filename: |
280 | | - filename = f"{self._prepare_json_filename()}" |
| 280 | + filename = f"{get_a_filename_from_instance(self, 'json')}" |
281 | 281 | self.db_engine = ThingJsonStorage(filename=filename, instance=self) |
282 | 282 |
|
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 | + |
297 | 284 | @object_info.getter |
298 | 285 | def _get_object_info(self): |
299 | 286 | if not hasattr(self, '_object_info'): |
|
0 commit comments