1
# add software-center custom metadata to the index
8
sys.path.insert(0, "/usr/share/software-center")
9
from softwarecenter.enums import (
13
from softwarecenter.db.update import (
17
from softwarecenter.distro import get_distro
20
class SoftwareCenterMetadataPlugin:
24
Return general information about the plugin.
26
The information returned is a dict with various keywords:
29
the last modified timestamp of this data source. This will be used
30
to see if we need to update the database or not. A timestamp of 0
31
means that this data source is either missing or always up to date.
33
an array of dicts { name: name, desc: description }, one for every
34
numeric value indexed by this data source.
36
Note that this method can be called before init. The idea is that, if
37
the timestamp shows that this plugin is currently not needed, then the
38
long initialisation can just be skipped.
40
file = apt.apt_pkg.config.find_file("Dir::Cache::pkgcache")
41
if not os.path.exists(file):
42
return dict(timestamp=0)
43
return dict(timestamp=os.path.getmtime(file))
45
def init(self, info, progress):
47
If needed, perform long initialisation tasks here.
49
info is a dictionary with useful information. Currently it contains
52
"values": a dict mapping index mnemonics to index numbers
54
The progress indicator can be used to report progress.
56
self.indexer = xapian.TermGenerator()
60
Return documentation information for this data source.
62
The documentation information is a dictionary with these keys:
63
name: the name for this data source
64
shortDesc: a short description
65
fullDoc: the full description as a chapter in ReST format
68
name="SoftwareCenterMetadata",
69
shortDesc="SoftwareCenter meta information",
71
Software-center metadata
73
AA for the Application name
74
AP for the Package name
76
AT to "application" for applications
77
It sets the following xapian values from the software-center
80
XapianValues.ICON_NEEDS_DOWNLOAD
82
XapianValues.SCREENSHOT_URLS
83
XapianValues.THUMBNAIL_URL
86
def index(self, document, pkg):
88
Update the document with the information from this data source.
90
document is the document to update
91
pkg is the python-apt Package object for this package
94
# if there is no version or the AppName custom key is not
95
# found we can skip the pkg
96
if ver is None or not CustomKeys.APPNAME in ver.record:
98
# we want to index the following custom fields:
104
if CustomKeys.APPNAME in ver.record:
105
name = ver.record[CustomKeys.APPNAME]
106
self.indexer.set_document(document)
107
# add s-c values/terms for the name
108
document.add_term("AA"+name)
109
document.add_value(XapianValues.APPNAME, name)
110
for t in get_pkgname_terms(pkg.name):
112
self.indexer.index_text_without_positions(
113
name, WEIGHT_DESKTOP_NAME)
114
# we pretend to be an application
115
document.add_term("AT" + "application")
116
# and we inject a custom component value to indicate "independent"
117
document.add_value(XapianValues.ARCHIVE_SECTION, "independent")
118
if CustomKeys.ICON in ver.record:
119
icon = ver.record[CustomKeys.ICON]
120
document.add_value(XapianValues.ICON, icon)
121
# calculate the url and add it (but only if there actually is
124
distro = get_distro()
127
# new python-apt returns None instead of StopIteration
129
url = distro.get_downloadable_icon_url(base_uri, icon)
130
document.add_value(XapianValues.ICON_URL, url)
131
except StopIteration:
133
if CustomKeys.SCREENSHOT_URLS in ver.record:
134
screenshot_url = ver.record[CustomKeys.SCREENSHOT_URLS]
135
document.add_value(XapianValues.SCREENSHOT_URLS, screenshot_url)
136
if CustomKeys.THUMBNAIL_URL in ver.record:
137
url = ver.record[CustomKeys.THUMBNAIL_URL]
138
document.add_value(XapianValues.THUMBNAIL_URL, url)
139
if CustomKeys.CATEGORY in ver.record:
140
categories_str = ver.record[CustomKeys.CATEGORY]
141
for cat in categories_str.split(";"):
143
document.add_term("AC" + cat.lower())
145
def indexDeb822(self, document, pkg):
147
Update the document with the information from this data source.
149
This is alternative to index, and it is used when indexing with package
150
data taken from a custom Packages file.
152
document is the document to update
153
pkg is the Deb822 object for this package
155
# NOTHING here, does not make sense for non-downloadable data
161
Create and return the plugin object.
163
return SoftwareCenterMetadataPlugin()