3
# Copyright (c) Stephen Smally <stephen.smally@gmail.com>
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
usage = '''Build a sqlite3-based database from the given directory of desktop files
22
Usage: lubuntu-software-center-build-db [DB_PATH] [DIRECTORY] [CATEGORYFILE]'''
27
from xdg import DesktopEntry as DE
29
from ConfigParser import RawConfigParser
37
arch = arch_dict[platform.machine()]
43
database = sys.argv[1]
44
base_folder = sys.argv[2]
45
tags_file = open(sys.argv[3], "r")
47
if os.path.exists(database):
51
print("Creating package database in %s" % database)
53
db = sqlite3.Connection(database)
56
aiddir = os.listdir(base_folder)
59
for (index, tags) in app_tags:
64
def get_pkg_depends(pkg):
67
if not (cache[pkg].version_list == []) and (depcache.get_candidate_ver(cache[pkg]) != None):
68
version = depcache.get_candidate_ver(cache[pkg])
70
depends_list = version.depends_list_str["Depends"]
74
rec = version.depends_list_str["Recommends"]
78
elif not cache[pkg].provides_list == []:
79
for pkgs in cache[pkg].provides_list:
82
depends_list = version.depends_list_str["Depends"]
86
rec = version.depends_list_str["Recommends"]
89
return (depends_list, rec)
94
cache = apt_pkg.Cache()
95
depcache = apt_pkg.DepCache(cache)
96
infos = apt_pkg.PackageRecords(cache)
99
if item.partition(".desktop")[-2] == ".desktop":
100
single_pkg = DE.DesktopEntry(base_folder+item)
101
name = single_pkg.getName()
102
pkg = single_pkg.get("X-AppInstall-Package")
103
icon = single_pkg.get("Icon")
104
categs = single_pkg.getCategories()
107
comment = single_pkg.get("Comment").decode("UTF-8")
110
if (pkg in cache) and (cache[pkg].has_versions):
112
deps = get_pkg_depends(pkg)
113
for items in deps[0]:
114
dep_list.append(items[0][0])
115
for items in deps[1]:
116
rec_list.append(items[0][0])
117
ver = depcache.get_candidate_ver(cache[pkg])
118
infos.lookup(ver.translated_description.file_list[0])
119
desc = infos.long_desc
121
comment = infos.short_desc.decode("UTF-8").capitalize()
131
except AttributeError: pass
134
print("%s: package not found" % pkg)
137
cat_parser = RawConfigParser()
138
cat_parser.readfp(tags_file)
139
cursor.execute("CREATE TABLE tables(id, contains, showboth, name, comment, icon)")
140
for section in cat_parser.sections():
141
cursor.execute("INSER INTO tables VALUES (?, ?, ?, ?, ?, ?)", (
143
cat_parser.get(section, "contains"),
144
cat_parser.get(section, "showboth"),
145
cat_parser.get(section, "name"),
146
cat_parser.get(section, "comment"),
147
cat_parser.get(section, "icon")
149
categ_string = "CREATE TABLE %s(name, pkg_name, tags, comment, icon, desc, deps, recs, ID)" % section
150
print("Creating table %s" % section)
151
cursor.execute(categ_string)
152
app_tags[section] = cat_parser.get(section, "contains")
155
tag_list = ["packages"]
157
for item in app_tags.items():
158
if tag in item[1].strip(";").split(";"):
159
if not item[0] in tag_list:
160
tag_list.append(item[0])
163
for package in cache.packages:
165
if package.architecture == arch:
166
if package.has_versions:
170
cat = ";".join(packages[pkg][0])
171
name = packages[pkg][1]
172
comment = packages[pkg][2]
173
icon = packages[pkg][3]
174
desc = packages[pkg][4]
175
deps = packages[pkg][5]
176
rec = packages[pkg][6]
179
ver = depcache.get_candidate_ver(package)
180
infos.lookup(ver.translated_description.file_list[0])
181
cat = package.section.replace("multiverse/", "").replace("universe/", "").replace("restricted/", "")
182
name = pkg.capitalize()
183
comment = infos.short_desc
185
desc = infos.long_desc
186
deps_func = get_pkg_depends(pkg)
189
for items in deps_func[0]:
190
dep_list.append(items[0][0])
191
for items in deps_func[1]:
192
rec_list.append(items[0][0])
193
deps = ";".join(dep_list)
194
recs = ";".join(rec_list)
195
for items in in_cat(cat.split(";")):
196
cursor.execute("INSERT INTO %s VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)" % items , (name, pkg, cat, comment, icon, desc, deps, recs, id))
198
print("%s: not found" % pkg)