Commit 98210838 authored by Clément Schreiner's avatar Clément Schreiner
Browse files

First attempt at updating the plugin to the new API.

Not tested, probably not complete (need access to sources, with
ko_lo's work).
parent b351486f
......@@ -39,16 +39,70 @@ __license__ = 'MIT'
from collections import defaultdict
import logging
import SOAPpy
from debexpo.lib import constants
from debexpo.plugins import BasePlugin
import SOAPpy
log = logging.getLogger(__name__)
class ClosedBugsPlugin(BasePlugin):
@test_result
class ClosedbugTest(PluginResult):
"""
Represents the result of the 'closed bugs' test.
"""
@property
def nb_closed(self):
return int(self['nb_closed'])
@property
def nb_errors(self):
return int(self['nb_errors'])
@property
def closes_wnpp(self):
return True if self['wnpp'] == 'true' else False
def __str__(self):
if self.closes_wnpp(self):
return 'Package closes a WNPP bug'
strings = []
strings.append('closes {} bug{plural}'.format(
self.nb_closed if self.nb_closed else 'no',
plural='s' if self.nb_closed > 1 else ''))
if self.nb_errors:
strings.append('has {} bug{plural} not closed properly'.format(
self.nb_errors,
plural='s' if self.nb_closed > 1 else ''))
return 'Package ' + ' and '.join(strings)
class ClosedBug(PluginResult):
"""
Represents a bug closed by the package.
"""
@property
def exists(self):
return True if self['exists'] == 'true' else False
@property
def belongs(self):
return True if self['belongs'] == 'true' else False
def __str__(self):
return '{number} ({severity}: {subject}'.format(
self[
class ClosedBugsPlugin(QAPlugin):
URL = "http://bugs.debian.org/cgi-bin/soap.cgi"
NS = "Debbugs/SOAP"
@importercmd
def test_closed_bugs(self):
"""
Check to make sure the bugs closed belong to the package.
......@@ -58,7 +112,8 @@ class ClosedBugsPlugin(BasePlugin):
log.debug('Package does not close any bugs')
return
log.debug('Checking whether the bugs closed in the package belong to the package')
log.debug('Checking whether the bugs closed in the package belongs'
' to the package')
bugs = [int(x) for x in self.changes['Closes'].split()]
......@@ -66,76 +121,81 @@ class ClosedBugsPlugin(BasePlugin):
log.debug('Creating SOAP proxy to bugs.debian.org')
try:
server = SOAPpy.SOAPProxy(self.URL, self.NS, simplify_objects = 1)
bugs_retrieved = server.get_status( *bugs )
if 'item' in bugs_retrieved:
bugs_retrieved = bugs_retrieved['item']
else:
bugs_retrieved = []
# Force argument to be a list, SOAPpy returns a dictionary instead of a dictionary list
# if only one bug was found
if not isinstance(bugs_retrieved, list):
bugs_retrieved = [bugs_retrieved]
bugs_retrieved = server.get_status(*bugs)
except Exception as e:
log.critical('An error occurred when creating the SOAP proxy at "%s" (ns: "%s"): %s'
% (self.URL, self.NS, e))
log.critical('An error occurred when creating the SOAP proxy at "%s"'
' (ns: "%s"): %s' % (self.URL, self.NS, e))
return
data = {
'buglist': bugs,
'raw': {},
'errors': [],
'bugs': defaultdict(list),
}
if 'item' in bugs_retrieved:
bugs_retrieved = bugs_retrieved['item']
else:
bugs_retrieved = []
# Force argument to be a list, SOAPpy returns a
# dictionary instead of a dictionary list if only one
# bug was found
if not isinstance(bugs_retrieved, list):
bugs_retrieved = [bugs_retrieved]
raw_bugs = {}
# Index bugs retrieved
for bug in bugs_retrieved:
if 'key' in bug and 'value' in bug:
data["raw"][int(bug['key'])] = bug['value']
raw_bugs[int(bug['key'])] = bug['value']
else:
continue
severity = constants.PLUGIN_SEVERITY_INFO
nb_closed = 0
nb_errors = 0
wnpp = 'false'
for bug in bugs:
if not bug in data['raw']:
data["errors"].append('Bug #%s does not exist' % bug)
bug_result = self.new_result(ClosedBug, number=bug)
if not bug in raw_bugs:
bug_result['exists'] = 'false'
bug_result['belongs'] = 'false'
severity = max(severity, constants.PLUGIN_SEVERITY_ERROR)
nb_errors += 1
continue
name = data["raw"][bug]['package']
data["bugs"][name].append((bug, data["raw"][bug]["subject"], data["raw"][bug]["severity"]))
bug_result['exists'] = 'true'
if not (self.changes["Source"] in data["raw"][bug]['source'].split(', ') or name == "wnpp"):
data["errors"].append('Bug #%s does not belong to this package' % bug)
severity = max(severity, constants.PLUGIN_SEVERITY_ERROR)
package = raw_bugs[bug]['package']
bug_result['name'] = package
bug_result['subject'] = raw_bugs[bug]['subject']
bug_result['severity'] = raw_bugs[bug]['severity']
if severity != constants.PLUGIN_SEVERITY_INFO:
outcome = "Package closes bugs in a wrong way"
elif "wnpp" in data["bugs"] and len(data["bugs"]) == 1:
outcome = "Package closes a WNPP bug"
else:
outcome = "Package closes bug%s" % ("s" if len(bugs) > 1 else "")
source = raw_bugs['source'].split(', ')
bug_result['belongs'] = 'true'
self.failed(outcome, data, severity)
else:
log.debug('Package does not close any bugs')
if name == 'wnpp':
bug_result['wnpp'] = 'true'
wnpp = 'true'
nb_closed += 1
elif self.changes['Source'] in source:
nb_closed += 1
def _package_in_descriptions(self, name, list):
"""
Finds out whether a binary package is in a source package by looking at the Description
field of the changes file for the binary package name.
else:
bug_result['belongs'] = 'false'
nb_errors += 1
severity = max(severity, constants.PLUGIN_SEVERITY_ERROR)
``name``
Name of the binary package.
``list``
List of Description fields split by '\n'.
"""
for item in list:
if item.startswith(name + ' '):
return True
test_result = self.new_test_result(nb_errors=nb_errors,
nb_closed=nb_closed,
wnpp=wnpp,
severity=severity)
return False
else:
log.debug('Package does not close any bugs')
plugin = ClosedBugsPlugin
models = [
ClosedbugTest,
ClosedBug,
]
Supports Markdown
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