You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

59 lines
1.7 KiB

from typing import List, Tuple
class DataImporter( object ):
"""
An abstract data importer.
Instanciate concrete instances via the Importer() function
"""
def retrieve( self ) -> List[str]:
"""
Retrieve a list of transactions
"""
return []
from .mock import MockDataImporter
from .modo import ModoDataImporter
#-------------------------------------------------------------------------------
def verify( config: dict, path: str = "" ) -> Tuple[bool, List[str]]:
"""
Verifies that the configuration is correct
Args:
config: dict with password manager configuration
path: path to the "config" dict in the main configuration file
Returns:
bool: true if the config is correct
List[str]: list of errors if the config is not correct
"""
if "import" not in config:
return (False, [f'Missing "{path}.import" value'])
if "name" not in config:
return (False, [f'Missing "{path}.name" value'])
importer = config["import"]
for cls in DataImporter.__subclasses__():
if importer == cls.name():
return cls.verify(config, path)
return (False, [f'Unknown data importer "{importer}"'])
#-------------------------------------------------------------------------------
def Importer( config: dict ) -> DataImporter:
"""
Instanciate an Importer instance from a given configuration
"""
if "import" not in config:
raise ValueError
if "name" not in config:
raise ValueError
importer = config["import"]
for cls in DataImporter.__subclasses__():
if importer == cls.name():
return cls(config)
raise ValueError