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

Update native and buildsystem plugins to the latest API.

parent 3a4fe08e
......@@ -7,6 +7,7 @@
# Copyright © 2008 Jonny Lamb <jonny@debian.org>
# Copyright © 2010 Jan Dittberner <jandd@debian.org>
# Copyright © 2012 Nicolas Dandrimont <nicolas.dandrimont@crans.org>
# Copyright © 2012 Clément Schreiner <clement@mux.me>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
......@@ -38,60 +39,83 @@ __copyright__ = ', '.join([
'Copyright © 2008 Jonny Lamb',
'Copyright © 2010 Jan Dittberner',
'Copyright © 2012 Nicolas Dandrimont',
'Copyright © 2012 Clément Schreiner',
])
__license__ = 'MIT'
from debexpo.lib import constants
from debexpo.plugins.api import *
import logging
import os
from debian import deb822
from debexpo.lib import constants
from debexpo.plugins import BasePlugin
from debexpo.models.plugin_results import PluginResult, plugin_result_mapper
from sqlalchemy import orm
log = logging.getLogger(__name__)
class BuildSystemResult(PluginResult):
pass
@test_result
class BuildsystemTest(PluginResult):
"""
Result of the 'buildsystem' plugin.
"""
orm.mapper(BuildSystemResult, inherits=plugin_result_mapper,
polymorphic_identity = 'buildsystem_result')
@property
def known(self):
return self['buildsystem'] != 'unknown'
class BuildSystemPlugin(BasePlugin):
model = BuildSystemResult
def __str__(self):
if self.known:
msg = 'Package uses %s' % self['buildsystem']
else:
msg = 'Unknown'
return 'Build system: %s' % msg
class BuildSystemPlugin(QAPlugin):
@importercmd
def test_build_system(self):
"""
Finds the build system of the package.
"""
log.debug('Finding the package\'s build system')
log.debug("Finding the package's build system")
dsc = deb822.Dsc(file(self.changes.get_dsc()))
log.debug('Opening dsc file in %s' % os.getcwd())
dsc_path = os.path.join(self.changes.get_pool_path(),
self.changes.get_dsc())
with open(dsc_path, 'r') as dsc_file:
dsc = deb822.Dsc(dsc_file)
build_depends = dsc.get('Build-Depends', '')
result = self.new_test_result()
if 'cdbs' in build_depends:
self._add_data(buildsystem = 'cdbs')
result['buildsystem'] = 'cdbs'
elif 'debhelper' in build_depends:
self._add_data(buildsystem = 'debhelper')
result['buildsystem'] = 'debhelper'
# Retrieve the debhelper compat level
compatpath = os.path.join(self.tempdir, "extracted/debian/compat")
try:
with open(compatpath, "rb") as f:
compat_level = int(f.read().strip())
except IOError:
if hasattr(self, 'tempdir'):
compatpath = os.path.join(self.tempdir, "extracted/debian/compat")
try:
with open(compatpath, "rb") as f:
compat_level = int(f.read().strip())
except IOError:
compat_level = 'unknown'
else:
compat_level = 'unknown'
self._add_data(compat-level = compat_level)
result['compat_level'] = compat_level
# Warn on old compatibility levels
if compat_level is None or compat_level <= 4:
self._add_data(severity = constants.PLUGIN_SEVERITY_WARNING)
result['severity'] = constants.PLUGIN_SEVERITY_WARNING
else:
self._add_data(build-system = 'unknown',
severity = constants.PLUGIN_SEVERITY_WARNING)
result['buildsystem'] = 'unknown'
result['severity'] = constants.PLUGIN_SEVERITY_WARNING
plugin = BuildSystemPlugin
models = [
BuildsystemTest,
]
......@@ -44,18 +44,17 @@ __license__ = 'MIT'
import logging
from debexpo.lib import constants, filesystem
from debexpo.plugins import QAPlugin
from debexpo.model.plugin_results import PluginResult
from debexpo.plugins.api import *
log = logging.getLogger(__name__)
class Test(PluginResult):
@test_result
class NativeTest(PluginResult):
"""
Result of the 'native' plugin for a package.
"""
plugin = 'native'
@property
def is_native(self):
return self['native'] == 'true'
......@@ -68,13 +67,8 @@ class NativePlugin(QAPlugin):
"""
Plugin checking whether a package is a native package.
"""
plugin = 'native'
# entity representing the result of the QA test
# (yes, this is ugly)
test_entity = 'native_test'
@importercmd
def test_native(self):
"""
Test to see whether the package is a native package.
......@@ -84,7 +78,7 @@ class NativePlugin(QAPlugin):
is_native = filecheck.is_native_package(self.changes)
result = self._new_result(Test)
result = self.new_test_result()
if is_native:
# Most uploads will not be native, and especially on mentors, a native
# package is almost probably in error.
......@@ -97,3 +91,6 @@ class NativePlugin(QAPlugin):
result['severity'] = constants.PLUGIN_SEVERITY_INFO
plugin = NativePlugin
models = [
NativeTest,
]
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