Commit 8c4340be authored by Romain Bignon's avatar Romain Bignon

create backends with Weboob object

parent 7cdf5060
......@@ -20,8 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
class Backend:
def __init__(self, config):
self.config = config
def __init__(self, weboob):
self.weboob = weboob
def hasCaps(self, caps):
if not isinstance(caps, (list,tuple)):
......
......@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
from weboob.backend import Backend
from weboob.capabilities.messages import IMessages, IMessagesReply
from weboob.capabilities.messages import ICapMessages, ICapMessagesReply
class AuMBackend(Backend, IMessages, IMessagesReply):
class AuMBackend(Backend, ICapMessages, ICapMessagesReply):
pass
......@@ -19,7 +19,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
from weboob.backend import Backend
from weboob.capabilities.messages import IMessages, IMessagesReply
from weboob.capabilities.messages import ICapMessages, ICapMessagesReply, Message
class DLFPBackend(Backend, IMessages, IMessagesReply):
pass
class DLFPBackend(Backend, ICapMessages, ICapMessagesReply):
def __init__(self, weboob):
Backend.__init__(self, weboob)
def getNewMessages(self, thread=None):
m = Message('threadid', 'msgid', 'Title', 'Sender', signature='Bite bite bite bite', content='Content content\nContent content.')
return [m]
......@@ -48,8 +48,8 @@ class Module:
return True
return False
def createBackend(self, config):
return self.klass(config)
def createBackend(self, weboob):
return self.klass(weboob)
class ModulesLoader:
def __init__(self):
......
......@@ -38,22 +38,22 @@ class Weboob:
self.modules_loader = ModulesLoader()
self.modules_loader.load()
def getFrontendConfig(self):
return self.config.get('frontends', self.app_name, create=True)
def getFrontendConfig(self, default={}):
return self.config.get('frontends', self.app_name, default=default)
def getBackendConfig(self, backend_name):
return self.config.get('backends', backend_name, create=True)
def getBackendConfig(self, backend_name, default={}):
return self.config.get('backends', backend_name, default=default)
def loadmodules(self, caps=None, name=None):
for name, module in self.modules_loader.modules.iteritems():
if (not caps or module.hasCaps(caps)) and \
(not name or module.name == name):
backend = module.createBackend(self.getBackendConfig(module.name))
backend = module.createBackend(self)
self.backends[module.name] = backend
def loadmodule(self, modname, instname):
module = self.modules_loader[modname]
self.backends[instname] = module.createBackend(self.getBackendConfig(instname))
self.backends[instname] = module.createBackend(self)
def getBackends(self, caps=None):
if caps is None:
......
......@@ -27,12 +27,13 @@ from weboob import Weboob
class BaseApplication(object):
APPNAME = ''
CONFIG = {}
def __init__(self):
self.weboob = Weboob(self.APPNAME)
self.config = self.weboob.getFrontendConfig()
self.config = self.weboob.getFrontendConfig(self.CONFIG)
def ask(question, default=None, masked=False, regexp=None):
def ask(self, question, default=None, masked=False, regexp=None):
"""
Ask a question to user.
......@@ -49,7 +50,6 @@ def ask(question, default=None, masked=False, regexp=None):
question = '%s [%s]' % (question, default)
while not correct:
sys.stdout.write('%s: ' % (question))
if masked:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment