2
# -*- coding: utf-8 -*-
3
"""util -- Apt-Xapian-Index integration"""
4
# Copyright (c) 2010 Sebastian Heinlein <devel@glatzor.de>
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License along
17
# with this program; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
__author__ = "Sebastian Heinlein <devel@glatzor.de>"
21
__state__ = "experimental"
26
from xdg.DesktopEntry import DesktopEntry
28
__ALL__ = ("get_package_desc", "APP_INSTALL_DATA", "AXI_DATABASE")
30
APP_INSTALL_DATA = "/usr/share/app-install/desktop"
31
AXI_DATABASE = "/var/lib/apt-xapian-index/index"
33
log = logging.getLogger("sessioninstaller")
37
os.stat(APP_INSTALL_DATA)
38
axi = xapian.Database("/var/lib/apt-xapian-index/index")
39
except (ImportError, OSError, xapian.DatabaseOpeningError):
40
log.warning("Falling back to package information")
46
path = os.path.join(APP_INSTALL_DATA, file_name)
47
return DesktopEntry(path)
49
def get_package_desc(pkg):
50
"""Return a pango markup description of the package.
51
If the package provides one or more applications
52
use the name and comment of the applications.
56
for m in axi.postlist("XP" + pkg.name):
57
doc = axi.get_document(m.docid)
58
for term_iter in doc.termlist():
60
if term_iter.term.startswith("XDF"):
63
file_name = term_iter.term[3:]
64
de = _desktop_cache.setdefault(file_name, _load(file_name))
66
comment = de.getComment()
68
markup += "<b>%s</b>\n%s" % (name, comment)
70
markup = "<b>%s</b>\n%s" % (pkg.name, pkg.summary)