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. ...@@ -20,8 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" """
class Backend: class Backend:
def __init__(self, config): def __init__(self, weboob):
self.config = config self.weboob = weboob
def hasCaps(self, caps): def hasCaps(self, caps):
if not isinstance(caps, (list,tuple)): if not isinstance(caps, (list,tuple)):
......
...@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" """
from weboob.backend import Backend 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 pass
...@@ -19,7 +19,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -19,7 +19,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" """
from weboob.backend import Backend 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): class DLFPBackend(Backend, ICapMessages, ICapMessagesReply):
pass 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: ...@@ -48,8 +48,8 @@ class Module:
return True return True
return False return False
def createBackend(self, config): def createBackend(self, weboob):
return self.klass(config) return self.klass(weboob)
class ModulesLoader: class ModulesLoader:
def __init__(self): def __init__(self):
......
...@@ -38,22 +38,22 @@ class Weboob: ...@@ -38,22 +38,22 @@ class Weboob:
self.modules_loader = ModulesLoader() self.modules_loader = ModulesLoader()
self.modules_loader.load() self.modules_loader.load()
def getFrontendConfig(self): def getFrontendConfig(self, default={}):
return self.config.get('frontends', self.app_name, create=True) return self.config.get('frontends', self.app_name, default=default)
def getBackendConfig(self, backend_name): def getBackendConfig(self, backend_name, default={}):
return self.config.get('backends', backend_name, create=True) return self.config.get('backends', backend_name, default=default)
def loadmodules(self, caps=None, name=None): def loadmodules(self, caps=None, name=None):
for name, module in self.modules_loader.modules.iteritems(): for name, module in self.modules_loader.modules.iteritems():
if (not caps or module.hasCaps(caps)) and \ if (not caps or module.hasCaps(caps)) and \
(not name or module.name == name): (not name or module.name == name):
backend = module.createBackend(self.getBackendConfig(module.name)) backend = module.createBackend(self)
self.backends[module.name] = backend self.backends[module.name] = backend
def loadmodule(self, modname, instname): def loadmodule(self, modname, instname):
module = self.modules_loader[modname] module = self.modules_loader[modname]
self.backends[instname] = module.createBackend(self.getBackendConfig(instname)) self.backends[instname] = module.createBackend(self)
def getBackends(self, caps=None): def getBackends(self, caps=None):
if caps is None: if caps is None:
......
...@@ -27,46 +27,46 @@ from weboob import Weboob ...@@ -27,46 +27,46 @@ from weboob import Weboob
class BaseApplication(object): class BaseApplication(object):
APPNAME = '' APPNAME = ''
CONFIG = {}
def __init__(self): def __init__(self):
self.weboob = Weboob(self.APPNAME) 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. Ask a question to user.
@param question text displayed (str) @param question text displayed (str)
@param default optional default value (str) @param default optional default value (str)
@param masked if True, do not show typed text (bool) @param masked if True, do not show typed text (bool)
@param regexp text must match this regexp (str) @param regexp text must match this regexp (str)
@return entered text by user (str) @return entered text by user (str)
""" """
correct = False correct = False
if not default is None: if not default is None:
question = '%s [%s]' % (question, default) question = '%s [%s]' % (question, default)
while not correct: while not correct:
sys.stdout.write('%s: ' % (question))
sys.stdout.write('%s: ' % (question)) if masked:
attr = termios.tcgetattr(sys.stdin)
tty.setcbreak(sys.stdin)
if masked: line = sys.stdin.readline().split('\n')[0]
attr = termios.tcgetattr(sys.stdin)
tty.setcbreak(sys.stdin)
line = sys.stdin.readline().split('\n')[0] if not line and not default is None:
line = default
if not line and not default is None: if masked:
line = default termios.tcsetattr(sys.stdin, termios.TCSAFLUSH, attr)
sys.stdout.write('\n')
if masked: correct = not regexp or re.match(regexp, str(line))
termios.tcsetattr(sys.stdin, termios.TCSAFLUSH, attr)
sys.stdout.write('\n')
correct = not regexp or re.match(regexp, str(line)) return line
return line
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