forked from QuantFans/quantdigger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdsutil.py
More file actions
32 lines (21 loc) · 924 Bytes
/
Copy pathdsutil.py
File metadata and controls
32 lines (21 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-
import six
from quantdigger.configutil import ConfigUtil
from quantdigger.infras.ioc import *
from quantdigger.util import dlogger as logger
_ds_container = IoCContainer()
class _DatasourceTrunk(IoCTrunk):
def __init__(self, cls, args, kwargs):
super(_DatasourceTrunk, self).__init__(cls, args, kwargs)
def on_register(self, name):
logger.info('register datasource: {cls} => {name}',
cls=self.cls, name=name)
def construct(self):
a = [ConfigUtil.get(k, None) for k in self.args]
ka = {k: ConfigUtil.get(name, None) for k, name in six.iteritems(self.kwargs)}
return self.cls(*a, **ka)
register_datasource = register_to(_ds_container, _DatasourceTrunk)
resolve_datasource = resolve_from(_ds_container)
def get_setting_datasource():
ds_type = ConfigUtil.get('source')
return resolve_datasource(ds_type), ds_type