file_manager: add method to retreive the metadata storage object

This allows other components to synchronously access and update
metadata if necessary.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-02-01 11:30:05 -05:00
parent 0dd10ce116
commit 9e57db0611
1 changed files with 10 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import logging
import json
import tempfile
import asyncio
from copy import deepcopy
from inotify_simple import INotify
from inotify_simple import flags as iFlags
@ -198,6 +199,9 @@ class FileManager:
return ""
return os.path.relpath(full_path, start=root_dir)
def get_metadata_storage(self) -> MetadataStorage:
return self.gcode_metadata
def check_file_exists(self, root: str, filename: str) -> bool:
root_dir = self.file_paths.get(root, "")
file_path = os.path.join(root_dir, filename)
@ -1500,7 +1504,12 @@ class MetadataStorage:
key: str,
default: _T = None
) -> Union[_T, Dict[str, Any]]:
return self.metadata.get(key, default)
return deepcopy(self.metadata.get(key, default))
def insert(self, key: str, value: Dict[str, Any]) -> None:
val = deepcopy(value)
self.metadata[key] = val
self.mddb[key] = val
def _has_valid_data(self,
fname: str,