2018-11-01 21:25:42 +01:00
|
|
|
import logging
|
2018-11-01 21:27:37 +01:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from core.utils.utils import load_config as load
|
2018-11-18 15:40:10 +01:00
|
|
|
|
|
|
|
__all__ = ["CBPiExtension"]
|
|
|
|
|
|
|
|
|
2018-11-01 21:25:42 +01:00
|
|
|
logger = logging.getLogger(__file__)
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
2018-11-18 15:40:10 +01:00
|
|
|
|
2018-11-01 21:25:42 +01:00
|
|
|
class CBPiExtension():
|
|
|
|
|
2018-11-18 15:40:10 +01:00
|
|
|
def __init__(self, *args, **kwds):
|
2018-11-18 23:09:17 +01:00
|
|
|
|
2018-11-18 15:40:10 +01:00
|
|
|
for a in kwds:
|
2018-11-18 23:09:17 +01:00
|
|
|
|
2018-11-18 15:40:10 +01:00
|
|
|
super(CBPiExtension, self).__setattr__(a, kwds.get(a))
|
|
|
|
self.cbpi = kwds.get("cbpi")
|
|
|
|
self.id = kwds.get("id")
|
|
|
|
self.value = None
|
|
|
|
self.__dirty = False
|
|
|
|
|
|
|
|
def __setattr__(self, name, value):
|
|
|
|
|
|
|
|
if name != "_CBPiExtension__dirty":
|
|
|
|
self.__dirty = True
|
|
|
|
super(CBPiExtension, self).__setattr__(name, value)
|
|
|
|
else:
|
|
|
|
super(CBPiExtension, self).__setattr__(name, value)
|
|
|
|
|
2018-11-01 21:25:42 +01:00
|
|
|
def load_config(self):
|
|
|
|
path = os.path.dirname(sys.modules[self.__class__.__module__].__file__)
|
|
|
|
try:
|
|
|
|
return load("%s/config.yaml" % path)
|
|
|
|
except:
|
|
|
|
logger.warning("Faild to load config %s/config.yaml" % path)
|