support of backend capabilities
This commit is contained in:
parent
458c92b4f8
commit
2aa2e01bc5
10 changed files with 147 additions and 8 deletions
|
|
@ -18,4 +18,4 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
"""
|
||||
|
||||
from ouiboube import Weboob
|
||||
from .ouiboube import Weboob
|
||||
|
|
|
|||
23
weboob/backend.py
Normal file
23
weboob/backend.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Copyright(C) 2010 Romain Bignon
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
"""
|
||||
|
||||
class Backend:
|
||||
CAPS = 0
|
||||
|
|
@ -1 +1,22 @@
|
|||
from adopte import AdopteUnMec
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Copyright(C) 2010 Romain Bignon
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
"""
|
||||
|
||||
from .adopte import AdopteUnMec
|
||||
from .backend import AuMBackend
|
||||
|
|
|
|||
25
weboob/backends/aum/backend.py
Normal file
25
weboob/backends/aum/backend.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Copyright(C) 2010 Romain Bignon
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
"""
|
||||
|
||||
from weboob.backend import Backend
|
||||
from weboob.capabilities import CAP_MAILS
|
||||
|
||||
class AuMBackend(Backend):
|
||||
CAPS = CAP_MAILS
|
||||
|
|
@ -19,3 +19,4 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
"""
|
||||
|
||||
from .browser import DLFP
|
||||
from .backend import DLFPBackend
|
||||
|
|
|
|||
25
weboob/backends/dlfp/backend.py
Normal file
25
weboob/backends/dlfp/backend.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Copyright(C) 2010 Romain Bignon
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
"""
|
||||
|
||||
from weboob.backend import Backend
|
||||
from weboob.capabilities import CAP_MAILS
|
||||
|
||||
class DLFPBackend(Backend):
|
||||
CAPS = CAP_MAILS
|
||||
21
weboob/capabilities.py
Normal file
21
weboob/capabilities.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Copyright(C) 2010 Romain Bignon
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
"""
|
||||
|
||||
CAP_MAILS = 0x00001
|
||||
|
|
@ -22,13 +22,29 @@ import re
|
|||
import os
|
||||
import sys
|
||||
from logging import warning, debug
|
||||
from types import ClassType
|
||||
|
||||
import weboob.backends as backends
|
||||
from backend import Backend
|
||||
|
||||
class Backend:
|
||||
class Module:
|
||||
def __init__(self, name, module):
|
||||
self.name = name
|
||||
self.module = module
|
||||
self.klass = None
|
||||
for attrname in dir(self.module):
|
||||
attr = getattr(self.module, attrname)
|
||||
if isinstance(attr, ClassType) and issubclass(attr, Backend) and attr != Backend:
|
||||
self.klass = attr
|
||||
|
||||
if not self.klass:
|
||||
raise ImportError("This is not a backend module (no Backend class found)")
|
||||
|
||||
def hasCaps(self, caps):
|
||||
return self.klass.CAPS & caps
|
||||
|
||||
def createBackend(self):
|
||||
return self.klass()
|
||||
|
||||
class ModulesLoader:
|
||||
def __init__(self):
|
||||
|
|
@ -44,10 +60,9 @@ class ModulesLoader:
|
|||
|
||||
def load_module(self, name):
|
||||
try:
|
||||
backend = Backend(name, __import__(name, fromlist=[name]))
|
||||
except ImportError:
|
||||
warning('Unable to import %s (%s)' % (name, path))
|
||||
raise
|
||||
backend = Module(name, __import__(name, fromlist=[name]))
|
||||
except ImportError, e:
|
||||
warning('Unable to load module %s: %s' % (name, e))
|
||||
return
|
||||
if name in self.modules:
|
||||
warning('Module "%s" is already loaded (%s)' % self.modules[name].module)
|
||||
|
|
|
|||
|
|
@ -34,3 +34,10 @@ class Weboob:
|
|||
self.modules_loader = ModulesLoader()
|
||||
self.modules_loader.load()
|
||||
|
||||
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.backends[module.name] = backend
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
import sys
|
||||
from weboob import Weboob
|
||||
from weboob.capabilities import CAP_MAILS
|
||||
|
||||
class User:
|
||||
def __init__(self, username, password, email):
|
||||
|
|
@ -36,7 +37,7 @@ class Application:
|
|||
self.weboob = Weboob(self.APPNAME)
|
||||
|
||||
def main(self, argv):
|
||||
pass
|
||||
self.weboob.loadmodules(CAP_MAILS)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = Application()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue