Merge lp:~larryprice/libertine-scope/libertine-store-appstream into lp:~larryprice/libertine-scope/libertine-store-search

Proposed by Larry Price
Status: Merged
Approved by: Larry Price
Approved revision: 109
Merged at revision: 102
Proposed branch: lp:~larryprice/libertine-scope/libertine-store-appstream
Merge into: lp:~larryprice/libertine-scope/libertine-store-search
Prerequisite: lp:~larryprice/libertine-scope/preview-2
Diff against target: 141 lines (+90/-1)
4 files modified
debian/control (+2/-0)
debian/libertined.install (+1/-0)
service/libertine_service/appstream.py (+79/-0)
service/libertine_service/dbus.py (+8/-1)
To merge this branch: bzr merge lp:~larryprice/libertine-scope/libertine-store-appstream
Reviewer Review Type Date Requested Status
Christopher Townsend (community) Approve
Review via email: mp+302841@code.launchpad.net

Commit message

Appstream backend for libertine-service.

Description of the change

Appstream backend for libertine-service.

Requires version 0.9.7 > appstream > 0.10 as this bug needs to have been addressed: https://github.com/ximion/appstream/issues/63

To post a comment you must log in.
97. By Larry Price

New AppStream syntax

98. By Larry Price

Fallback

99. By Larry Price

Fixing compile issue

100. By Larry Price

Largest versions of icons and screenshots

101. By Larry Price

appstream deps

102. By Larry Price

merge

103. By Larry Price

no more ratings

104. By Larry Price

merge

105. By Larry Price

add apt to install file

106. By Larry Price

merge

107. By Larry Price

Update app_info for official version of appstream 0.10

108. By Larry Price

merge

109. By Larry Price

Add back in liburl-dispatcher1-dev dep since we still use it in this mp

Revision history for this message
Christopher Townsend (townsend) wrote :

This works well and is good.

Let's go ahead and merge this in the base MP as well.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2016-08-31 14:49:27 +0000
3+++ debian/control 2016-09-15 18:45:03 +0000
4@@ -40,6 +40,8 @@
5 Depends: python3-libertine,
6 python3-apt (>= 0.9.3),
7 python3-dbus (>= 1.2.0),
8+ appstream,
9+ gir1.2-appstream,
10 ${python3:Depends}
11 Description: Libertine packages scope for Unity
12 The libertined package provides the d-bus service for finding and
13
14=== modified file 'debian/libertined.install'
15--- debian/libertined.install 2016-08-29 16:20:35 +0000
16+++ debian/libertined.install 2016-09-15 18:45:03 +0000
17@@ -1,5 +1,6 @@
18 usr/share/dbus-1/services/com.canonical.libertine.ContainerManager.service
19 usr/bin/libertined
20 usr/lib/python*/*/libertine_service/__init__.py
21+usr/lib/python*/*/libertine_service/appstream.py
22 usr/lib/python*/*/libertine_service/apt.py
23 usr/lib/python*/*/libertine_service/dbus.py
24
25=== added file 'service/libertine_service/appstream.py'
26--- service/libertine_service/appstream.py 1970-01-01 00:00:00 +0000
27+++ service/libertine_service/appstream.py 2016-09-15 18:45:03 +0000
28@@ -0,0 +1,79 @@
29+# Copyright 2016 Canonical Ltd.
30+#
31+# This program is free software: you can redistribute it and/or modify
32+# it under the terms of the GNU General Public License as published by
33+# the Free Software Foundation; version 3 of the License.
34+#
35+# This program is distributed in the hope that it will be useful,
36+# but WITHOUT ANY WARRANTY; without even the implied warranty of
37+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38+# GNU General Public License for more details.
39+#
40+# You should have received a copy of the GNU General Public License
41+# along with this program. If not, see <http://www.gnu.org/licenses/>.
42+
43+import gi
44+gi.require_version('AppStream', '1.0')
45+from gi.repository import AppStream
46+
47+
48+def xstr(s):
49+ """Converts anything to a string"""
50+ return str(s or "")
51+
52+
53+class AppStreamCache(object):
54+ """AppStreamCache"""
55+ def __init__(self, config):
56+ super(AppStreamCache, self).__init__()
57+ self.config = config
58+ self.pool = AppStream.Pool()
59+ self.pool.load()
60+
61+ def search(self, query):
62+ packages = []
63+ for component in self.pool.search(query):
64+ if component.is_valid():
65+ package = {}
66+ package["name"] = xstr(component.get_name())
67+ package["id"] = xstr(component.get_id())
68+ package["summary"] = xstr(component.get_summary())
69+ package["uri"] = xstr(component.get_url(AppStream.UrlKind.HOMEPAGE))
70+
71+ if len(component.get_icons()) > 0:
72+ package["icon"] = xstr(self._get_largest_icon(component.get_icons()).get_filename())
73+ packages.append(package)
74+
75+ return packages[::-1]
76+
77+ def app_info(self, app_id):
78+ apps = self.pool.get_components_by_id(app_id)
79+ app_data = {}
80+ if len(apps) == 1 and apps[0].is_valid():
81+ app = apps[0]
82+ app_data["name"] = xstr(app.get_name())
83+ app_data["id"] = xstr(app.get_id())
84+ app_data["summary"] = xstr(app.get_summary())
85+ app_data["website"] = xstr(app.get_url(AppStream.UrlKind.HOMEPAGE))
86+ app_data["license"] = xstr(app.get_project_license())
87+ for screenshot in app.get_screenshots():
88+ if screenshot.is_valid() and screenshot.get_kind() is AppStream.ScreenshotKind.EXTRA:
89+ largest = self._get_largest_icon(screenshot.get_images())
90+ if largest is not None:
91+ if "screenshots" not in app_data:
92+ app_data["screenshots"] = []
93+ app_data["screenshots"].append(largest.get_url())
94+
95+ app_data["description"] = xstr(app.get_description())
96+
97+ if len(app.get_icons()) > 0:
98+ app_data["icon"] = xstr(self._get_largest_icon(app.get_icons()).get_filename())
99+
100+ return app_data
101+
102+ def _get_largest_icon(self, images):
103+ largest = None
104+ for icon in images:
105+ if largest is None or icon.get_width() > largest.get_width():
106+ largest = icon
107+ return largest
108
109=== modified file 'service/libertine_service/dbus.py'
110--- service/libertine_service/dbus.py 2016-09-15 18:45:02 +0000
111+++ service/libertine_service/dbus.py 2016-09-15 18:45:03 +0000
112@@ -16,6 +16,7 @@
113 import dbus.service
114 import logging
115 from libertine_service import apt
116+from libertine_service import appstream
117 from dbus.mainloop.glib import DBusGMainLoop
118
119
120@@ -30,7 +31,6 @@
121
122 def __init__(self, config):
123 log.info("creating service")
124- self.cache = apt.AptCache(config)
125 DBusGMainLoop(set_as_default=True)
126 try:
127 bus_name = dbus.service.BusName(LIBERTINE_SERVICE_NAME,
128@@ -39,6 +39,13 @@
129 except dbus.exceptions.NameExistsException:
130 log.warning("service is already running")
131 raise
132+
133+ try:
134+ self.cache = appstream.AppStreamCache(config)
135+ except:
136+ log.warning("AppStream backend unavailable, falling back to Apt backend.")
137+ self.cache = apt.AptCache(config)
138+
139 super().__init__(bus_name, LIBERTINE_STORE_PATH)
140
141 @dbus.service.method(LIBERTINE_STORE_INTERFACE,

Subscribers

People subscribed via source and target branches

to all changes: