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
abc8a314
Commit
abc8a314
authored
Jul 12, 2012
by
Clément Schreiner
Browse files
Improve debdata interface. Not complete, but it runs.
parent
73e57bc9
Changes
1
Hide whitespace changes
Inline
Side-by-side
debexpo/plugins/debtags.py
View file @
abc8a314
...
...
@@ -38,9 +38,11 @@ __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
debexpo.lib.debtagsd.debdata
import
autotag
,
datasources
,
utils
from
debexpo.lib.repository
import
Repository
from
sqlalchemy
import
orm
import
pylons
import
urllib2
from
debian
import
debtags
...
...
@@ -49,15 +51,13 @@ import logging
log
=
logging
.
getLogger
(
__name__
)
class
Debtag
sResult
(
PluginResult
):
class
Debtag
(
PluginResult
):
pass
orm
.
mapper
(
Debtag
sResult
,
inherits
=
plugin_result_mapper
,
polymorphic_identity
=
'debtag
s
'
)
orm
.
mapper
(
Debtag
,
inherits
=
plugin_result_mapper
,
polymorphic_identity
=
'debtag'
)
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
...
...
@@ -79,29 +79,35 @@ class DebtagsPlugin(BasePlugin):
db
.
read
(
open
(
'/var/lib/debtags/package-tags'
,
'r'
))
return
db
.
tags_of_package
(
self
.
package_version
.
package
.
name
)
def
test_debtags
(
self
):
def
run
(
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'
)
self
.
_new_result
(
Debtag
,
tag
=
tag
,
source
=
'debtags'
)
log
.
debug
(
'Applying debtags heuristics to the package'
)
self
.
tags
=
set
()
autotag
=
Autodebtag
(
BinPackages
)
class
Autodebtag
(
autotag
.
Autodebtag
):
"""
Use debtagsd's heuristics to assign debtags to a new package
"""
def
__init__
(
self
,
sources
):
def
__init__
(
self
):
self
.
sources
=
{}
for
src
in
sources
:
self
.
sources
[
src
.
__name__
.
lower
()]
=
src
.
create
()
for
src
in
(
BinPackages
,)
:
self
.
sources
[
src
.
__name__
.
lower
()]
=
src
.
create
(
'data'
)
self
.
rules
=
list
()
self
.
create_rule
(
autotag
.
RuleSections
)
def
load_sources
(
self
,
package_list
):
for
key
in
self
.
sources
:
self
.
sources
[
key
].
load
(
packages
=
package_list
)
def
get_tags
(
self
):
tags
=
{}
for
r
in
self
.
rules
:
...
...
@@ -115,16 +121,7 @@ class Apriori(datasources.Action):
"""
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
):
class
SrcPackage
(
datasources
.
DataSource
):
"""
Implement DataSource, for use with Autodebtag and Apriori, with
the source package data
...
...
@@ -133,28 +130,36 @@ class SrcPackage(DataSource):
def
load
(
self
,
**
kw
):
pass
class
BinPackages
(
DataSource
):
class
BinPackages
(
datasources
.
DataSource
):
"""
Implement DataSource, for use with Autodebtag and Apriori, with
binary packages data
"""
def
__init__
(
self
,
*
packages
,
**
kw
):
self
.
datafile
=
None
self
.
packages
=
packages
FILENAME
=
None
def
load
(
self
,
**
kw
):
packages
=
kw
[
'packages'
]
self
.
by_name
=
dict
()
self
.
by_section
=
dict
()
for
p
in
self
.
packages
:
repository
=
Repository
(
pylons
.
config
[
'debexpo.repository'
])
for
p
in
packages
:
pkg_from_repo
=
repository
.
get_bin_package
(
p
.
name
,
p
.
arch
)
section
=
p
.
package_version
.
section
desc
=
pkg_from_repo
.
get
(
'Description'
,
None
)
sdesc
,
ldesc
=
utils
.
splitdesc
(
desc
)
section
=
'libs'
info
=
datasources
.
Pkg
(
p
.
name
,
p
.
package_version
.
version
,
p
.
package_version
.
package
.
name
,
p
.
package_version
.
section
,
p
.
desc
ription
,
p
.
desc
ription
,
section
,
s
desc
,
l
desc
,
[
p
.
arch
],
[],
# predeps
[],
# deps
...
...
@@ -162,7 +167,7 @@ class BinPackages(DataSource):
[],
# suggests
[],
# enhances
p
.
package_version
.
distribution
)
self
.
by_name
[
name
]
=
info
self
.
by_name
[
p
.
name
]
=
info
self
.
by_section
.
setdefault
(
section
,
[]).
append
(
info
)
plugin
=
DebtagsPlugin
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