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

New plugin: debtags.

Retrieve tags from debtags (packages in debian) and apply debtagsd's heuristics (all packages).
For now, only works for existing packages; heuristics integration not tested (but probably not far from working).
parent 617913a5
# -*- coding: utf-8 -*-
#
# native.py — native QA plugin
#
# This file is part of debexpo - https://alioth.debian.org/projects/debexpo/
#
# Copyright © 2008 Jonny Lamb <jonny@debian.org>
# Copyright © 2012 Nicolas Dandrimont <Nicolas.Dandrimont@crans.org>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
"""
Holds the native plugin.
"""
__author__ = 'Clément Schreiner'
__copyright__ = 'Copyright © 2012 Clément Schreiner'
__license__ = 'MIT'
from debexpo.model.plugin_results import PluginResult, plugin_result_mapper
from debexpo.plugins import BasePlugin
from debexpo.lib.debtagsd.debdata import autotag, datasources
from sqlalchemy import orm
import urllib2
from debian import debtags
import logging
log = logging.getLogger(__name__)
class DebtagsResult(PluginResult):
pass
orm.mapper(DebtagsResult, inherits=plugin_result_mapper,
polymorphic_identity = 'debtags')
class DebtagsPlugin(BasePlugin):
result_model = DebtagsResult
# TODO: use debianqa results for this
# NOTE: maybe move into lib/, or make the plugin depend on debianqa
@property
def _package_in_debian(self):
log.debug('Checking whether the package is in debian')
try:
self.qa_page = urllib2.urlopen('http://packages.qa.debian.org/%s' % self.changes['Source'])
except urllib2.HTTPError:
log.debug('Package is not in debian')
return False
else:
log.debug('Package is in debian')
return True
@property
def _tags_from_db(self):
log.debug('Getting the tags from debtags database')
db = debtags.DB()
db.read(open('/var/lib/debtags/package-tags', 'r'))
return db.tags_of_package(self.package_version.package.name)
def test_debtags(self):
"""
Apply debtags' heuristics to the package.
"""
if self._package_in_debian:
for tag in self._tags_from_db:
self._new_result(tag = tag, source = 'debtags')
log.debug('Applying debtags heuristics to the package')
self.tags = set()
class Autodebtag(autotag.Autodebtag):
"""
Use debtagsd's heuristics to assign debtags to a new package
"""
def __init__(self, sources):
self.sources = {}
for src in sources:
self.sources[src.__name__.lower()] = src.create()
self.rules = list()
self.create_rule(autotag.RuleSections)
def get_tags(self):
tags = {}
for r in self.rules:
for pkg, added, removed in r.make_patch():
tags.setdefault(pkg, set()).add(added)
return tags
class Apriori(datasources.Action):
"""
Use debtagsd's apriori rules to find probable tags
"""
pass
class DataSource(datasources.DataSource):
def __init__(self, *packages, **kw):
self.datafile = None
self.packages = packages
def load(self, **kw):
raise NotImplemented
class SrcPackage(DataSource):
"""
Implement DataSource, for use with Autodebtag and Apriori, with
the source package data
"""
def load(self, **kw):
pass
class BinPackages(DataSource):
"""
Implement DataSource, for use with Autodebtag and Apriori, with
binary packages data
"""
def __init__(self, *packages, **kw):
self.datafile = None
self.packages = packages
def load(self, **kw):
self.by_name = dict()
self.by_section = dict()
for p in self.packages:
section = 'libs'
info = datasources.Pkg(p.name,
p.package_version.version,
p.package_version.package.name,
p.package_version.section,
p.description,
p.description,
[p.arch],
[], # predeps
[], # deps
[], # recommends
[], # suggests
[], # enhances
p.package_version.distribution)
self.by_name[name] = info
self.by_section.setdefault(section, []).append(info)
plugin = DebtagsPlugin
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