diff --git a/weboob/__init__.py b/weboob/__init__.py index 9632336af33b38c4af51367a74adea8e1a00a64b..19ab13f05da784221833dd50fe1c2b5b6f74d736 100644 --- a/weboob/__init__.py +++ b/weboob/__init__.py @@ -18,4 +18,4 @@ """ -from ouiboube import Weboob +from .ouiboube import Weboob diff --git a/weboob/backend.py b/weboob/backend.py new file mode 100644 index 0000000000000000000000000000000000000000..18c5ad57ab52e789a0135abd0b84ad6c7ecc3ec9 --- /dev/null +++ b/weboob/backend.py @@ -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 diff --git a/weboob/backends/aum/__init__.py b/weboob/backends/aum/__init__.py index 399b414f5336636432858c4b1b4438beb3c2fe1c..e3309a9ede73f98b38c3cc2ecbff5f71ec5b00e4 100644 --- a/weboob/backends/aum/__init__.py +++ b/weboob/backends/aum/__init__.py @@ -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 diff --git a/weboob/backends/aum/backend.py b/weboob/backends/aum/backend.py new file mode 100644 index 0000000000000000000000000000000000000000..b39e692c1a9d21a152ebdead016e66b32eab9176 --- /dev/null +++ b/weboob/backends/aum/backend.py @@ -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 diff --git a/weboob/backends/dlfp/__init__.py b/weboob/backends/dlfp/__init__.py index 16b432bc20795613ab4c40fe291b10edf0f98ff4..e894520e4694e1b9a73ff9178968a1d2c514b53c 100644 --- a/weboob/backends/dlfp/__init__.py +++ b/weboob/backends/dlfp/__init__.py @@ -19,3 +19,4 @@ """ from .browser import DLFP +from .backend import DLFPBackend diff --git a/weboob/backends/dlfp/backend.py b/weboob/backends/dlfp/backend.py new file mode 100644 index 0000000000000000000000000000000000000000..f1823dfd9836826b4cc1b4f43f5694b013fa2f6a --- /dev/null +++ b/weboob/backends/dlfp/backend.py @@ -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 diff --git a/weboob/capabilities.py b/weboob/capabilities.py new file mode 100644 index 0000000000000000000000000000000000000000..d4efe7387764c4fd5a780cf4b154dc250313099a --- /dev/null +++ b/weboob/capabilities.py @@ -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 diff --git a/weboob/modules.py b/weboob/modules.py index 8e2f53beba21ed09f76b2be5ea4ff016a8c5df5b..c13f548138b4764b166837f758bc1f9566b089ea 100644 --- a/weboob/modules.py +++ b/weboob/modules.py @@ -22,13 +22,29 @@ 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 @@ def load(self): 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) diff --git a/weboob/ouiboube.py b/weboob/ouiboube.py index 82a89af32db3fc66d517dfc794b9988f4e1147c2..4bccd4649782da6ab9f53b9dbcc7e08c94064ce8 100644 --- a/weboob/ouiboube.py +++ b/weboob/ouiboube.py @@ -34,3 +34,10 @@ def __init__(self, app_name, config_file=CONFIG_FILE): 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 + diff --git a/weboob2mail b/weboob2mail index 37141bf4f89ec29b0af2ecbf98a59cfd4307bd1b..5f6fd8463a068e9d3fe3d47f2278146ec8d80157 100755 --- a/weboob2mail +++ b/weboob2mail @@ -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()