Commit 57949739 authored by Romain Bignon's avatar Romain Bignon

new backend 'redmine' (implements ICapContent)

parent a39db362
# -*- 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']
# -*- 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
# -*- 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()
# -*- 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
# -*- 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
# -*- 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
......@@ -128,7 +128,7 @@ class BaseBrowser(mechanize.Browser):
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):
"""
......
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