Commit 2b65c6f8 authored by Jelmer Vernooij's avatar Jelmer Vernooij

Make RemoteReport base class rather than wrapper class.

parent 1a9c5d3c
......@@ -52,14 +52,12 @@ class DupeExn(Exception):
class RemoteReport:
"""Describes a bug report that exists in a remote bug tracker."""
def __init__(self, data, bts):
def __init__(self, bts, id, status, resolution):
self.bts = bts
assert(data.id and data.status)
self.id = data.id
self.status = data.status
self.resolution = data.resolution
self.id = id
self.status = status
self.resolution = resolution
self.uri = self.bts.getUri(self.id)
self.closed = self.bts.isClosing(self.status, self.resolution)
......@@ -133,8 +131,7 @@ class RemoteBts:
:param uri: Bug report URI
"""
data = self._getReportData(uri)
return data and RemoteReport(data, self)
return self._getReportData(uri)
def getReports(self, uris):
"""Mass-obtain a set of bug reports.
......@@ -187,7 +184,7 @@ class RemoteBts:
def _getReportData(self, uri):
assert self._bugcls
return self._bugcls(uri, self.extractBugid(uri))
return self._bugcls(self, uri, self.extractBugid(uri))
def _bugId(self, data):
return data.id
......
......@@ -32,6 +32,7 @@
import urllib, urlparse, cgi, re
from BeautifulSoup import BeautifulSoup
from base import RemoteReport
from __init__ import *
#the status page
......@@ -53,8 +54,8 @@ def parse_status_page(soup, id):
return Null
gid_re = re.compile(r'.*group_id=([0-9]+).*')
class BerliosData:
def __init__(self, uri, id):
class BerliosData(RemoteReport):
def __init__(self, bts, uri, id):
self.id = id or failwith(uri, "Berlios: no id")
......
......@@ -32,10 +32,12 @@ from __init__ import *
from base import RemoteReport
from BeautifulSoup import BeautifulSoup
class OldBugzillaData:
class OldBugzillaData(RemoteReport):
dupre = re.compile(r'\*\*\* This (?:bug|issue) has been marked as a duplicate of(?: bug)? ([0-9]+) \*\*\*$')
def __init__(self, uri):
def __init__(self, bts, uri):
self.bts = bts
self.uri = uri
soup = BeautifulSoup(wget(uri))
if soup.bugzilla:
......@@ -63,11 +65,13 @@ class OldBugzillaData:
if not self.duplicate:
failwith(uri, "BugZilla: cannot find duplicate")
class BugzillaData:
class BugzillaData(RemoteReport):
dupre = re.compile(r'\*\*\* This (?:bug|issue) has been marked as a duplicate of(?: bug)? ([0-9]+) \*\*\*$')
def __init__(self, bug):
def __init__(self, bts, uri, bug):
self.uri = uri
self.bts = bts
self.id = bug.bug_id.string or failwith("?", "BugZilla: no bug_id")
self.status = bug.bug_status.string or failwith(self.id, "BugZilla: no bug_status")
......@@ -148,12 +152,8 @@ class RemoteBugzilla(OldRemoteBugzilla):
if not bugs:
failwith("Bugzilla: invalid XML: %s" % massuri)
for bug in bugs.bugzilla.fetch('bug'):
data = BugzillaData(bug)
if not data: continue
rbug = RemoteReport(data, self)
yield rbug
for uri, bug in zip(uris, bugs.bugzilla.fetch('bug')):
yield BugzillaData(self, uri, bug)
RemoteBts.register('old-bugzilla', OldRemoteBugzilla)
RemoteBts.register('bugzilla', RemoteBugzilla)
......@@ -32,6 +32,7 @@
import urllib, urlparse, cgi
from BeautifulSoup import BeautifulSoup
from base import RemoteReport
from __init__ import *
# <tr><td nowrap><b>State:</b></td>
......@@ -43,8 +44,10 @@ def parse_table(soup, key):
# Cookie: gnatsweb-global=email&cb%40df7cb.de&database&mutt&Submitter-Id&any&columns&Notify-List%20Category%20Synopsis%20Confidential%20Severity%20Priority%20Responsible%20State%20Keywords%20Date-Required%20Class%20Submitter-Id%20Arrival-Date%20Closed-Date%20Last-Modified%20Originator%20Release; gnatsweb-db-mutt=password&g%60vft&user&guest
class GnatsData:
def __init__(self, uri, id):
class GnatsData(RemoteReport):
def __init__(self, bts, uri, id):
self.bts = bts
self.uri = uri
soup = BeautifulSoup(wget(uri, "cookies.txt"))
self.id = id or failwith(uri, "Gnats: no id")
......
......@@ -30,6 +30,7 @@
import urllib, urlparse, re
from __init__ import *
from base import RemoteReport
import rfc822
......@@ -62,8 +63,10 @@ class LaunchpadBug:
task = rfc822.Message(text)
class RemoteLaunchpadData:
def __init__(self, uri, id=None):
class RemoteLaunchpadData(RemoteReport):
def __init__(self, bts, uri, id=None):
self.bts = bts
self.uri = uri
text = urllib.urlopen(urlparse.urljoin(uri+"/", "+text"))
# Two forms of URLs supported:
if uri.split("/")[-2] == "+bug":
......
......@@ -31,6 +31,7 @@ import urllib, urlparse, cgi, re
from BeautifulSoup import BeautifulSoup
from __init__ import *
from base import RemoteReport
status_re = re.compile(r'^\s*Status\s*$')
resolution_re = re.compile(r'^\s*Resolution\s*$')
......@@ -44,8 +45,10 @@ def find_dupe(soup):
cell = cell.findNextSibling('td')
return cell.a.string
class MantisData:
def __init__(self, uri, id):
class MantisData(RemoteReport):
def __init__(self, bts, uri, id):
self.bts = bts
self.uri = uri
self.id = id or failwith(uri, "Mantis: no id")
soup = BeautifulSoup(urllib.urlopen(uri))
......
......@@ -32,14 +32,17 @@
import urllib, urlparse, cgi
from BeautifulSoup import BeautifulSoup
from base import RemoteReport
from __init__ import *
def parse_table(soup, key):
cell = soup.firstText(key).findParent('td')
return cell.findNextSibling('td').string
class RTData:
def __init__(self, uri, id):
class RTData(RemoteReport):
def __init__(self, bts, uri, id):
self.bts = bts
self.uri = uri
soup = BeautifulSoup(urllib.urlopen(uri))
self.id = id or failwith(uri, "RT: no id")
......
......@@ -31,14 +31,17 @@
import urllib, urlparse, cgi
from BeautifulSoup import BeautifulSoup
from base import RemoteReport
from __init__ import *
def parse_table(soup, key):
cell = soup.firstText(key).findParent('td')
return cell.nextSibling.string
class SavaneData:
def __init__(self, uri, id):
class SavaneData(RemoteReport):
def __init__(self, bts, uri, id):
self.bts = bts
self.uri = uri
self.id = id or failwith(uri, "Savane: no id")
soup = BeautifulSoup(urllib.urlopen(uri))
......
......@@ -37,7 +37,9 @@ def get_value(table, key):
return td.contents[-1].string.strip()
class SourceForgeData:
def __init__(self, uri, id):
def __init__(self, bts, uri, id):
self.bts = bts
self.uri = uri
self.id = id or failwith(uri, "SourceForge: no id")
soup = BeautifulSoup(wget(uri))
......
......@@ -33,6 +33,7 @@
import re, urllib
from BeautifulSoup import BeautifulSoup
from base import RemoteReport
from __init__ import *
any = re.compile(r'.*')
......@@ -81,8 +82,10 @@ class TracTicket:
return [x.strip('()') for x in words]
class TracData:
def __init__(self, uri, id):
class TracData(RemoteReport):
def __init__(self, bts, uri, id):
self.bts = bts
self.uri = uri
self.id = id or failwith(uri, "Trac: no id")
page = wget(uri + '?format=tab')
......
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