fix type hints and describe state functions

This commit is contained in:
Marek Wolan
2023-08-20 18:38:02 +01:00
parent 6ca53803cd
commit 01c912c094
10 changed files with 459 additions and 49 deletions

View File

@@ -13,7 +13,7 @@ _LOGGER = getLogger(__name__)
class FileSystem(SimComponent):
"""Class that contains all the simulation File System."""
folders: Dict = {}
folders: Dict[str, FileSystemFolder] = {}
"""List containing all the folders in the file system."""
def describe_state(self) -> Dict:
@@ -26,7 +26,7 @@ class FileSystem(SimComponent):
:rtype: Dict
"""
state = super().describe_state()
state.update({"folders": {uuid: folder for uuid, folder in self.folders.items()}})
state.update({"folders": {uuid: folder.describe_state() for uuid, folder in self.folders.items()}})
return state
def get_folders(self) -> Dict:

View File

@@ -45,9 +45,11 @@ class FileSystemFile(FileSystemItem):
:return: Current state of this object and child objects.
:rtype: Dict
"""
return {
"uuid": self.uuid,
"name": self.name,
"size": self.size,
"file_type": self.file_type,
}
state = super().describe_state()
state.update(
{
"uuid": self.uuid,
"file_type": self.file_type.name,
}
)
return state

View File

@@ -10,7 +10,7 @@ _LOGGER = getLogger(__name__)
class FileSystemFolder(FileSystemItem):
"""Simulation FileSystemFolder."""
files: Dict = {}
files: Dict[str, FileSystemFile] = {}
"""List of files stored in the folder."""
is_quarantined: bool = False
@@ -25,13 +25,14 @@ class FileSystemFolder(FileSystemItem):
:return: Current state of this object and child objects.
:rtype: Dict
"""
return {
"uuid": self.uuid,
"name": self.name,
"size": self.size,
"files": {uuid: file for uuid, file in self.files.items()},
"is_quarantined": self.is_quarantined,
}
state = super().describe_state()
state.update(
{
"files": {uuid: file.describe_state() for uuid, file in self.files.items()},
"is_quarantined": self.is_quarantined,
}
)
return state
def get_file_by_id(self, file_id: str) -> FileSystemFile:
"""Return a FileSystemFile with the matching id."""