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

Update debianqa plugin to the new API. Tested and working.

parent 91172a85
......@@ -46,27 +46,36 @@ import urllib2
from debexpo.model import meta
from debexpo.model.users import User
from debexpo.plugins import BasePlugin
from debexpo.plugins.api import *
log = logging.getLogger(__name__)
class DebianqaResult(PluginResult):
@property
def in_debian(self):
return True if self.get('in_debian') == 'true' else False
@test_result
class DebianqaTest(PluginResult):
in_debian = bool_field('in_debian')
is_nmu = bool_field('is_nmu')
is_debian_maintainer = bool_field('is_debian_maintainer')
def __str__(self):
# FIXME: this variable name sucks.
s = 'already' if self.in_debian else 'not'
return 'Package is %s in debian' % s
class DebianPlugin(BasePlugin):
result_model = DebianqaResult
class DebianQAPlugin(QAPlugin):
""" Plugin for Debian QA tests """
@property
def _in_debian(self):
try:
self.qa_page = urllib2.urlopen('http://packages.qa.debian.org/%s' % self.changes['Source'])
self.qa_page = urllib2.urlopen('http://packages.qa.debian.org/%s'
% self.changes['Source'])
except urllib2.HTTPError:
return False
else:
self.parsed_qa = lxml.etree.fromstring(self.qa_page.read())
return = True
return True
def _qa_xpath(self, query, item = None):
"""Perform the xpath query on the given item"""
......@@ -82,8 +91,7 @@ class DebianPlugin(BasePlugin):
Finds whether the package is in Debian.
"""
log.debug('Testing whether the package is in Debian already')
self._add_result(in-debian = 'true' if self._in_debian else 'false')
self.test_result.in_debian=self._in_debian
def _test_last_upload(self):
"""
......@@ -96,7 +104,7 @@ class DebianPlugin(BasePlugin):
if 'Accepted' in self._qa_xpath('xhtml:a/child::text()', item):
last_change = item.text[1:11]
log.debug('Last upload on %s' % last_change)
self.data["latest-upload"] = last_change
self.test_result["latest_upload"] = last_change
return
log.warning('Couldn\'t find last upload date')
......@@ -115,7 +123,7 @@ class DebianPlugin(BasePlugin):
changes = str(self.changes["Changes"]).lower().translate(None, delete_chars).splitlines()
self.data["nmu"] = (
self.test_result.is_nmu = (
any(change.startswith('nonmaintainerupload') for change in changes) or
any(change.startswith('nmu') for change in changes) or
'nmu' in self.changes["Version"]
......@@ -131,8 +139,9 @@ class DebianPlugin(BasePlugin):
self.user_name = ""
self.user_email = ""
if self.user_id is not None:
user = meta.session.query(User).get(self.user_id)
user_id = self.kw.get('user_id', None)
if user_id is not None:
user = meta.session.query(User).get(user_id)
if user is not None:
self.user_name = user.name
......@@ -145,7 +154,7 @@ class DebianPlugin(BasePlugin):
log.debug('Finding out whether the package Maintainer is the Debian Maintainer')
self.data["is-debian-maintainer"] = self.user_name in self.debian_maintainers
self.test_result.is_debian_maintainer = self.user_name in self.debian_maintainers
def _test_has_new_maintainer(self):
......@@ -164,16 +173,14 @@ class DebianPlugin(BasePlugin):
# TODO
@importercmd
def test_qa(self):
"""Run the Debian QA tests"""
self._in_debian()
self.outcome = ""
self.data = {}
self.test_result = self.new_test_result()
self._test_package_in_debian()
if self.in_debian:
if self._in_debian:
self._test_last_upload()
self._test_is_nmu()
self._get_debian_maintainer_data()
......@@ -181,7 +188,10 @@ class DebianPlugin(BasePlugin):
self._test_has_new_maintainer()
self._test_previous_sponsors()
self.info(self.outcome, self.data)
plugin = DebianPlugin
plugin = DebianQAPlugin
models = [
DebianqaTest,
]
template = 'debianqa'
<div class="qa-header">
${str(o.outcome)}
${test_result}
</div>
%if o.rich_data["in-debian"]:
% if test_result.in_debian:
<div class="qa-content debian-qa">
<ul>
%if o.rich_data["nmu"]:
<li>Detected as a non-maintainer upload</li>
%endif
<li>The package uploader is ${"not" if not o.rich_data["is-debian-maintainer"] else ""} currently maintaining <a href="http://packages.qa.debian.org/${o.package_version.package.name}">${o.package_version.package.name} in Debian</a></li>
<ul>
% if test_result.is_nmu:
<li>Detected as a non-maintainer upload</li>
% endif
<li>The package uploader is ${"not" if not test_result.is_debian_maintainer else ""} currently maintaining <a href="http://packages.qa.debian.org/${test_result.package_version.package.name}">${test_result.package_version.package.name} in Debian</a></li>
</ul>
</div>
%endif
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