diff --git a/weboob/backends/redmine/__init__.py b/weboob/backends/redmine/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..3f7c620b210f71d58351fbbdea3ddf4bad745ea5 --- /dev/null +++ b/weboob/backends/redmine/__init__.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. + + +from .backend import RedmineBackend + +__all__ = ['RedmineBackend'] diff --git a/weboob/backends/redmine/backend.py b/weboob/backends/redmine/backend.py new file mode 100644 index 0000000000000000000000000000000000000000..be6636bace44aefe8770688ac61d508a7465c919 --- /dev/null +++ b/weboob/backends/redmine/backend.py @@ -0,0 +1,62 @@ +# -*- 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.capabilities.content import ICapContent, Content +from weboob.tools.backend import BaseBackend + +from .browser import RedmineBrowser + + +__all__ = ['RedmineBackend'] + + +class RedmineBackend(BaseBackend, ICapContent): + NAME = 'redmine' + MAINTAINER = 'Romain Bignon' + EMAIL = 'romain@peerfuse.org' + VERSION = '0.3' + DESCRIPTION = 'The Redmine project management web application' + LICENSE = 'GPLv3' + CONFIG = {'url': BaseBackend.ConfigField(description='URL of the Redmine'), + 'username': BaseBackend.ConfigField(description='Login'), + 'password': BaseBackend.ConfigField(description='Password', is_masked=True), + } + BROWSER = RedmineBrowser + + def create_default_browser(self): + return self.create_browser(self.config['url'], self.config['username'], self.config['password']) + + def get_content(self, id): + if isinstance(id, basestring): + try: + project, _type, page = id.split('/', 2) + except ValueError: + return None + content = Content(id) + else: + content = id + id = content.id + + with self.browser: + data = self.browser.get_wiki_source(project, page) + + content.content = data + return content + + def push_content(self, content): + pass diff --git a/weboob/backends/redmine/browser.py b/weboob/backends/redmine/browser.py new file mode 100644 index 0000000000000000000000000000000000000000..6a86fc656c0ec25f0f1ea81bdbfc8ea5ad18f2dc --- /dev/null +++ b/weboob/backends/redmine/browser.py @@ -0,0 +1,75 @@ +# -*- 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 urlparse import urlsplit + +from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword + +from .pages.index import LoginPage, IndexPage, MyPage +from .pages.wiki import WikiEditPage + + +__all__ = ['RedmineBrowser'] + + +# Browser +class RedmineBrowser(BaseBrowser): + ENCODING = 'utf-8' + PAGES = {'%s/': IndexPage, + '%s/login': LoginPage, + '%s/my/page': MyPage, + '%s/projects/\w+/wiki/\w+/edit': WikiEditPage, + } + + is_logging = False + + def __init__(self, url, *args, **kwargs): + v = urlsplit(url) + self.PROTOCOL = v.scheme + self.DOMAIN = v.netloc + self.BASEPATH = v.path + if self.BASEPATH.endswith('/'): + self.BASEPATH = self.BASEPATH[:-1] + + prefix = '%s://%s%s' % (self.PROTOCOL, self.DOMAIN, self.BASEPATH) + + self.PAGES = {} + for key, value in RedmineBrowser.PAGES.iteritems(): + self.PAGES[key % prefix] = value + BaseBrowser.__init__(self, *args, **kwargs) + + def is_logged(self): + return self.is_logging or (self.page and len(self.page.document.getroot().cssselect('a.my-account')) == 1) + + def login(self): + assert isinstance(self.username, basestring) + assert isinstance(self.password, basestring) + + self.is_logging = True + if not self.is_on_page(LoginPage): + self.location('%s/login' % self.BASEPATH) + + self.page.login(self.username, self.password) + + self.is_logging = False + if self.is_on_page(LoginPage): + raise BrowserIncorrectPassword() + + def get_wiki_source(self, project, page): + self.location('%s/projects/%s/wiki/%s/edit' % (self.BASEPATH, project, page)) + return self.page.get_source() diff --git a/weboob/backends/redmine/pages/__init__.py b/weboob/backends/redmine/pages/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/weboob/backends/redmine/pages/index.py b/weboob/backends/redmine/pages/index.py new file mode 100644 index 0000000000000000000000000000000000000000..64a2f9c2295bf38f70376a447b28d956dc5a6458 --- /dev/null +++ b/weboob/backends/redmine/pages/index.py @@ -0,0 +1,32 @@ +# -*- 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.tools.browser import BasePage + +class LoginPage(BasePage): + def login(self, username, password): + self.browser.select_form(nr=1) + self.browser['username'] = username + self.browser['password'] = password + self.browser.submit() + +class IndexPage(BasePage): + pass + +class MyPage(BasePage): + pass diff --git a/weboob/backends/redmine/pages/wiki.py b/weboob/backends/redmine/pages/wiki.py new file mode 100644 index 0000000000000000000000000000000000000000..abbb968453fed4d884be6a14e8f8b18d9400db9f --- /dev/null +++ b/weboob/backends/redmine/pages/wiki.py @@ -0,0 +1,24 @@ +# -*- 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.tools.browser import BasePage +from weboob.tools.parsers.lxmlparser import select + +class WikiEditPage(BasePage): + def get_source(self): + return select(self.document.getroot(), 'textarea#content_text', 1).text diff --git a/weboob/backends/redmine/test.py b/weboob/backends/redmine/test.py new file mode 100644 index 0000000000000000000000000000000000000000..5f73b856a3a7172ba992c459ebbf2bb8e39434d0 --- /dev/null +++ b/weboob/backends/redmine/test.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.tools.test import BackendTest + +class RedmineTest(BackendTest): + BACKEND = 'redmine' + + def test_redmine(self): + pass diff --git a/weboob/tools/browser/browser.py b/weboob/tools/browser/browser.py index 40c978c04bb66a3d203be0b3fbb3c356c5e09c3a..7cbd2b8ea8d050bc7e0b798aefdccca3d9184e51 100644 --- a/weboob/tools/browser/browser.py +++ b/weboob/tools/browser/browser.py @@ -128,7 +128,7 @@ def home(self): Go to the home page. """ if self.DOMAIN is not None: - self.location('%s://%s' % (self.PROTOCOL, self.DOMAIN)) + self.location('%s://%s/' % (self.PROTOCOL, self.DOMAIN)) def login(self): """