7
from ConfigParser import RawConfigParser, NoOptionError
12
class DesktopConfigParser(RawConfigParser):
13
" thin wrapper that is tailored for xdg Desktop files "
14
def get_desktop(self, key):
15
" get generic option under 'Desktop Entry'"
16
return self.get("Desktop Entry", key)
17
def has_option_desktop(self, key):
18
" test if there is the option under 'Desktop Entry'"
19
return self.has_option("Desktop Entry", key)
20
def get_desktop_categories(self):
21
" get the list of categories for the desktop file "
24
categories_str = self.get_desktop("Categories")
25
for item in categories_str.split(";"):
27
categories.append(item)
32
def update(db, datadir="/usr/share/app-install/"):
33
" index the desktop files in $datadir/desktop/*.desktop "
34
term_generator = xapian.TermGenerator()
35
for desktopf in glob(datadir+"/desktop/*.desktop"):
36
logging.debug("processing %s" % desktopf)
37
parser = DesktopConfigParser()
38
doc = xapian.Document()
39
term_generator.set_document(doc)
43
name = parser.get_desktop("Name")
45
doc.add_term("XA"+name)
46
pkgname = parser.get_desktop("X-AppInstall-Package")
47
doc.add_term("XP"+pkgname)
48
if parser.has_option_desktop("Icon"):
49
icon = parser.get_desktop("Icon")
50
doc.add_value(XAPIAN_DATA_ICON, icon)
51
for cat in parser.get_desktop_categories():
52
doc.add_term("XC"+cat.lower())
53
# now add search data from the desktop file
54
for key in ["Name","Generic Name","Comment"]:
55
if not parser.has_option_desktop(key):
57
s = parser.get_desktop(key)
58
term_generator.index_text_without_positions(s)
59
# FIXME: now do the same for the localizations in the
62
logging.warn("error processing: %s %s" % (desktopf, e))
68
if __name__ == "__main__":
69
#logging.basicConfig(level=logging.DEBUG)
70
desktop_base_path = "/usr/share/app-install"
71
xapian_base_path = "/var/cache/app-install"
73
pathname = os.path.join(xapian_base_path, "xapian")
74
db = xapian.WritableDatabase(pathname, xapian.DB_CREATE_OR_OVERWRITE)
75
update(db, desktop_base_path)