Initialize datahandlers

This commit is contained in:
Matthias
2019-12-25 16:12:20 +01:00
parent 5fca17d7e1
commit 9547d47ae2
2 changed files with 34 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
from typing import Type
from pathlib import Path
from .idatahandler import IDataHandler
@@ -20,3 +20,17 @@ def get_datahandlerclass(datatype: str) -> Type[IDataHandler]:
return JsonGzDataHandler
else:
raise ValueError(f"No datahandler for datatype {datatype} available.")
def get_datahandler(datadir: Path, data_format: str = None,
data_handler: IDataHandler = None) -> IDataHandler:
"""
:param datadir: Folder to save data
:data_format: dataformat to use
:data_handler: returns this datahandler if it exists or initializes a new one
"""
if not data_handler:
HandlerClass = get_datahandlerclass(data_format or 'json')
data_handler = HandlerClass(datadir)
return data_handler