Bugtracker/plugin.py: Update Trac class to use the "Tab-delimited Text" source rather than screen-scraping

This commit is contained in:
Terence Simpson 2009-04-18 07:54:05 +01:00
parent 45f51e064c
commit 46a4ea34d2

View File

@ -681,35 +681,39 @@ class Mantis(IBugtracker):
s = 'Could not parse data returned by %s bugtracker: %s' % (self.description, e) s = 'Could not parse data returned by %s bugtracker: %s' % (self.description, e)
raise BugtrackerError, s raise BugtrackerError, s
# For trac based trackers we also need to do some screenscraping - should be # For trac based trackers we get the tab-separated-values format.
# doable unless a certain track instance uses weird templates. # The other option is a comma-separated-values format, but if the description
# has commas, things get tricky.
# This should be more robust than the screen-scraping done previously.
class Trac(IBugtracker): class Trac(IBugtracker):
def get_bug(self, id): def get_bug(self, id): # This is still a little rough, but it works :)
url = "%s/%d" % (self.url, id) bug_url = "%s/%d" % (self.url, id)
try: try:
bugdata = utils.web.getUrl(url) raw = utils.web.getUrl("%s?format=tab" % bug_url)
except Exception, e: except Exception, e:
# Hacketiehack
if 'HTTP Error 500' in str(e): if 'HTTP Error 500' in str(e):
raise BugNotFoundError raise BugNotFoundError
s = 'Could not parse data returned by %s: %s' % (self.description, e) s = 'Could not parse data returned by %s: %s' % (self.description, e)
raise BugtrackerError, s raise BugtrackerError, s
# Make sure all the variables are set, just incase the HTML doesn't contain them raw = raw.replace("\r\n", '\n')
(headers, rest) = raw.split('\n', 1)
headers = headers.strip().split('\t')
rest = rest.strip().split('\t')
title = status = package = severity = assignee = "Unknown" title = status = package = severity = assignee = "Unknown"
for l in bugdata.split("\n"): if "summary" in headers:
if 'class="summary' in l: title = rest[headers.index("summary")]
title = l[l.find('>')+1:l.find('</')] if "status" in headers:
if 'class="status"' in l: status = rest[headers.index("status")]
status = l[l.find('>(')+2:l.find(')')] if "component" in headers:
if 'headers="h_component"' in l: package = rest[headers.index("component")]
package = l[l.find('>')+1:l.find('</')] if "severity" in headers:
if 'headers="h_severity"' in l: severity = rest[headers.index("severity")]
severity = l[l.find('>')+1:l.find('</')] if "owner" in headers:
if 'headers="h_stage"' in l: assingee = rest[headers.index("owner")]
severity = l[l.find('>')+1:l.find('</')] if severity == "Unknown" and "priority" in headers:
if 'headers="h_owner"' in l: severity = rest[headers.index("priority")]
assignee = l[l.find('>')+1:l.find('</')]
return [(id, package, title, severity, status, assignee, "%s/%s" % (self.url, id))] return [(id, package, title, severity, status, assignee, bug_url)]
class WikiForms(IBugtracker): class WikiForms(IBugtracker):
def get_bug(self, id): def get_bug(self, id):