platypush/platypush/plugins/__init__.py

38 lines
908 B
Python
Raw Normal View History

import os
import sys
2017-12-11 03:53:26 +01:00
import logging
import traceback
from platypush.response import Response
2017-10-31 09:20:35 +01:00
class Plugin(object):
2017-11-03 15:06:29 +01:00
def __init__(self, config):
self.config = config
2017-12-11 03:53:26 +01:00
self._set_logging()
2017-11-03 15:06:29 +01:00
for cls in reversed(self.__class__.mro()):
if cls is not object:
try:
cls._init(self)
except AttributeError as e:
pass
2017-12-11 03:53:26 +01:00
def _set_logging(self):
if 'logging' in self.config:
self._logging = self.config.pop('logging')
2017-12-11 03:53:26 +01:00
else:
self._logging = logging.INFO
logging.basicConfig(level=self._logging)
def run(self, method, *args, **kwargs):
try:
res = getattr(self, method)(*args, **kwargs)
except Exception as e:
res = Response(output=None, errors=[e, traceback.format_exc()])
return res
2017-10-31 09:20:35 +01:00
# vim:sw=4:ts=4:et: