bug fixes: and support for plugins

This commit is contained in:
Steve Nyemba 2024-04-01 12:52:06 -05:00
parent e7838f5de1
commit 6feae101b0
1 changed files with 20 additions and 13 deletions

View File

@ -17,12 +17,14 @@ Source Code is available under MIT License:
https://hiplab.mc.vanderbilt.edu/git/hiplab/data-transport https://hiplab.mc.vanderbilt.edu/git/hiplab/data-transport
""" """
import numpy as np import numpy as np
from transport import sql, nosql, cloud, other from transport import sql, nosql, cloud, other
import pandas as pd import pandas as pd
import json import json
import os import os
from info import __version__,__author__ from info import __version__,__author__
from transport.iowrapper import IWriter, IReader
from transport.plugins import PluginLoader
PROVIDERS = {} PROVIDERS = {}
def init(): def init():
global PROVIDERS global PROVIDERS
@ -31,7 +33,6 @@ def init():
if _provider_name.startswith('__') : if _provider_name.startswith('__') :
continue continue
PROVIDERS[_provider_name] = {'module':getattr(_module,_provider_name),'type':_module.__name__} PROVIDERS[_provider_name] = {'module':getattr(_module,_provider_name),'type':_module.__name__}
# print ([ {name:getattr(sql,name)} for name in dir(sql) if not name.startswith('__')])
def instance (**_args): def instance (**_args):
""" """
@ -55,9 +56,23 @@ def instance (**_args):
_context = _args['context'] _context = _args['context']
else: else:
_context = 'read' _context = 'read'
_pointer = getattr(_module,'Reader') if _context == 'read' else getattr(_module,'Writer') _pointer = getattr(_module,'Reader') if _context == 'read' else getattr(_module,'Writer')
return _pointer (**_args) _agent = _pointer (**_args)
pass #
loader = None
if 'plugins' in _args :
_params = _args['plugins']
if 'path' in _params and 'names' in _params :
loader = PluginLoader(**_params)
elif type(_params) == list:
loader = PluginLoader()
for _delegate in _params :
loader.set(_delegate)
return IReader(_agent,loader) if _context == 'read' else IWriter(_agent,loader)
else: else:
raise Exception ("Missing or Unknown provider") raise Exception ("Missing or Unknown provider")
pass pass
@ -79,11 +94,3 @@ class factory :
pass pass
factory.instance = instance factory.instance = instance
init() init()
# if __name__ == '__main__' :
# # if not PROVIDERS :
# init()
# print (list(PROVIDERS.keys()))
# pgr = instance(provider='postgresql',database='io',table='foo',write=True)
# print (pgr.read())
# print ()
# print (supported())