diff --git a/bicho/backends/trac.py b/bicho/backends/trac.py index 2697458..6801347 100644 --- a/bicho/backends/trac.py +++ b/bicho/backends/trac.py @@ -252,6 +252,13 @@ class TracRPC(object): def __init__(self, url): self.url = url + self.backend_user = None + self.backend_password = None + self.requests = requests + + if hasattr(Config, 'backend_user') and hasattr(Config, 'backend_password'): + self.backend_user = Config.backend_user + self.backend_password = Config.backend_password def tickets(self, since=None): """Returns a list of IDs of tickets that have changed since timestamp.""" @@ -288,10 +295,19 @@ def call(self, method, params): # POST parameters data = {'method': method, 'params': params} data = json.dumps(data) + auth = None + + if self.backend_user and self.backend_password: + auth = (self.backend_user, self.backend_password) + url = '%s/login/jsonrpc' % self.url + else: + url = '%s/jsonrpc' % self.url - res = requests.post('%s/jsonrpc' % self.url, + res = self.requests.post(url, headers=self.HEADERS, - data=data) + data=data, + auth=auth) + printdbg("Trac RPC %s method called: %s" % (method, res.url)) # Raise HTTP errors, if any diff --git a/bicho/backends/trac_wordpress.py b/bicho/backends/trac_wordpress.py new file mode 100644 index 0000000..518f98b --- /dev/null +++ b/bicho/backends/trac_wordpress.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2015 Bitergia +# +# 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; either version 2 +# of the License, or (at your option) any later version. +# +# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# Authors: Santiago DueƱas +# + +import requests + +from bicho.backends import Backend +from bicho.backends.trac import Trac, TracRPC + + +class TracWordPress(Trac): + def __init__(self): + Trac.__init__(self) + + self.trac_rpc = TracRPCWordPress(self.url) + +class TracRPCWordPress(TracRPC): + def __init__(self, url): + TracRPC.__init__(self, url) + + self.requests = requests.Session() + login_url = 'https://wordpress.org/support/bb-login.php' + login_data = {'password': self.backend_password, 'user_login': self.backend_user} + + self.requests.post(login_url, login_data) + +Backend.register_backend('trac_wordpress', TracWordPress)