Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
mentors.debian.net
debexpo
Commits
bf60da0d
Commit
bf60da0d
authored
Jul 16, 2012
by
Clément Schreiner
Browse files
Re-implement the plugin using debexpo.lib.axi.
(+ update to latest plugin API.)
parent
5fd67b93
Changes
1
Hide whitespace changes
Inline
Side-by-side
debexpo/plugins/similar.py
View file @
bf60da0d
...
...
@@ -47,7 +47,7 @@ from sqlalchemy import orm
log
=
logging
.
getLogger
(
__name__
)
class
Similar
Result
(
PluginResult
):
class
Similar
Package
(
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment