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

Re-implement the plugin using debexpo.lib.axi.

(+ update to latest plugin API.)
parent 5fd67b93
......@@ -47,7 +47,7 @@ from sqlalchemy import orm
log = logging.getLogger(__name__)
class SimilarResult(PluginResult):
class SimilarPackage(PluginResult):
pass
orm.mapper(SimilarResult, inherits=plugin_result_mapper,
......@@ -56,16 +56,45 @@ orm.mapper(SimilarResult, inherits=plugin_result_mapper,
class SimilarPlugin(BasePlugin):
result_model = SimilarResult
def _get_similar_packages(self, binary):
"""
Returns the packages similar to the binary package provided,
as a list of (package name, similarity percent) pairs
"""
q = XapianQuery()
q.add_text(binary.get_description())
q.add_not(binary.name)
return [p for p in q.query()]
def _get_pkg_info(self, name):
"""
Returns a dictionary with information about a package in apt's cache.
Keys: name, desc, maintainer
"""
cache = Cache()
return {
'name': name,
'desc': cache[name].candidate.summary,
'maintainer': cache[name].candidate.record['maintainer'].decode('utf-8')
}
def _add_similar_packages(self, binary):
"""
Retrieve packages similar to `binary` and add them as
`SimilarPackage` objects to the database, with information
from apt cache.
"""
for name, percent in self._get_similar_packages(binary):
info = self._get_info(name)
sp = self._new_result(SimilarPackage, name = name,
percent = percent, maintainer = info['maintainer'],
desc = info['desc'], binary = binary)
def test_similar_packages(self):
binary_packages = self.package_version.get_binary_packages()
packages = [b.name for b in binary_packages]
descriptions = [b.get_description() for b in binary_packages]
sd = SemanticData(packages, descriptions)
for p in sd.iter_similar_packages():
self._add_result(**p)
for bp in binary_packages:
self._add_similar_packages(bp.name)
plugin = SimilarPlugin
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