Merge lp:~davidc3/unity-scope-reddit/many-fixes into lp:unity-scope-reddit

Proposed by David Callé
Status: Merged
Approved by: David Callé
Approved revision: 11
Merged at revision: 2
Proposed branch: lp:~davidc3/unity-scope-reddit/many-fixes
Merge into: lp:unity-scope-reddit
Diff against target: 313 lines (+115/-80)
7 files modified
data/reddit.scope.in (+7/-5)
data/unity-scope-reddit.service (+1/-1)
debian/control (+17/-10)
setup.cfg (+1/-1)
setup.py (+1/-3)
src/unity_reddit_daemon.py (+87/-59)
tests/test_reddit.py (+1/-1)
To merge this branch: bzr merge lp:~davidc3/unity-scope-reddit/many-fixes
Reviewer Review Type Date Requested Status
David Callé Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+180059@code.launchpad.net

Commit message

Better query handling and many installer fixes

Description of the change

This branch makes the scope work again and cuts querying time by 4.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
8. By David Callé

Fix packaging deps

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
9. By David Callé

Improve first comment use

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
10. By David Callé

Better preview image if available and nsfw filter toggle

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
11. By David Callé

Dummy commit for Jenkins

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
David Callé (davidc3) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/reddit.scope.in'
2--- data/reddit.scope.in 2013-02-21 11:50:58 +0000
3+++ data/reddit.scope.in 2013-08-15 13:53:44 +0000
4@@ -1,15 +1,17 @@
5 [Scope]
6 DBusName=com.canonical.Unity.Scope.Info.Reddit
7 DBusPath=/com/canonical/unity/scope/info/reddit
8-Icon=
9-_Keywords=reddit;
10+Icon=/usr/share/icons/unity-icon-theme/places/svg/service-reddit.svg
11+QueryBinary=
12+_Keywords=reddit;r;
13 RequiredMetadata=
14-OptionalMetadata=[s]author;[s]target;
15-Loader=/usr/lib/ubuntu-scopes/reddit/unity_reddit_daemon.py
16+OptionalMetadata=author[s];target[s];domain[s];subreddit[s];comments[i];
17+Loader=/usr/share/unity-scopes/reddit/unity_reddit_daemon.py
18 RemoteContent=true
19 Type=info
20+Master=info
21 _Name=Reddit
22-_Description=Find Reddit posts
23+_Description=This is an Ubuntu search plugin that enables information from Reddit to be searched and displayed in the Dash underneath the Info header. If you do not wish to search this content source, you can disable this search plugin.
24 _SearchHint=Search Reddit
25
26 [Desktop Entry]
27
28=== modified file 'data/unity-scope-reddit.service'
29--- data/unity-scope-reddit.service 2013-02-21 11:50:58 +0000
30+++ data/unity-scope-reddit.service 2013-08-15 13:53:44 +0000
31@@ -1,3 +1,3 @@
32 [D-BUS Service]
33 Name=com.canonical.Unity.Scope.Info.Reddit
34-Exec=/usr/lib/ubuntu-scopes/reddit/unity_reddit_daemon.py
35+Exec=/usr/bin/python3 /usr/share/unity-scopes/scope-runner-dbus.py /usr/share/unity-scopes/reddit/unity_reddit_daemon.py
36
37=== modified file 'debian/control'
38--- debian/control 2013-02-21 11:50:58 +0000
39+++ debian/control 2013-08-15 13:53:44 +0000
40@@ -1,25 +1,32 @@
41 Source: unity-scope-reddit
42 Section: gnome
43-Priority: extra
44+Priority: optional
45 Maintainer: David Callé <davidc@framli.eu>
46 Build-Depends: debhelper (>= 9),
47 python3,
48 python3-distutils-extra,
49+ python3-gi,
50 pkg-config,
51 python3-nose,
52- gir1.2-unity-5.0 (>= 6.8),
53- gir1.2-dee-1.0,
54+ gir1.2-unity-5.0 (>= 7),
55+ gir1.2-dee-1.0 (>= 1.2.5),
56 gir1.2-glib-2.0,
57-Standards-Version: 3.9.3
58-Homepage: https://launchpad.net/ubuntu-scopes
59-
60+Standards-Version: 3.9.4
61+Homepage: https://launchpad.net/unity-scope-reddit
62+# If you aren't a member of ~submarine but need to upload packaging changes,
63+# just go ahead. ~submarine will notice and sync up the code again.
64+Vcs-Bzr: https://code.launchpad.net/~submarine/unity-scope-reddit/trunk
65+
66 Package: unity-scope-reddit
67 Architecture: all
68 Depends: ${misc:Depends},
69 ${python3:Depends},
70 python3,
71- gir1.2-unity-5.0 (>= 6.8),
72- gir1.2-dee-1.0,
73+ python3-gi,
74+ gir1.2-unity-5.0 (>= 7),
75+ gir1.2-dee-1.0 (>= 1.2.5),
76+ unity-scopes-runner,
77 gir1.2-glib-2.0
78-Description: reddit scope for Unity
79- A Dash search plugin for reddit.
80+Description: Reddit scope for Unity
81+ This package contains the "reddit" scope which allows Unity
82+ to search for Reddit content.
83
84=== modified file 'setup.cfg'
85--- setup.cfg 2013-02-21 11:50:58 +0000
86+++ setup.cfg 2013-08-15 13:53:44 +0000
87@@ -3,4 +3,4 @@
88
89 [build_i18n]
90 domain=unity-scope-reddit
91-desktop_files=[('share/unity/scopes', ('data/reddit.scope.in',))]
92+desktop_files=[('share/unity/scopes/info', ('data/reddit.scope.in',))]
93
94=== modified file 'setup.py'
95--- setup.py 2013-02-21 11:50:58 +0000
96+++ setup.py 2013-08-15 13:53:44 +0000
97@@ -11,8 +11,6 @@
98 license='GNU General Public License (GPL)',
99 data_files=[
100 ('share/dbus-1/services', ['data/unity-scope-reddit.service']),
101- ('share/icons/unity-icon-theme/places/svg', ['data/icons/service-reddit.svg']),
102- ('lib/ubuntu-scopes/reddit', ['src/unity_reddit_daemon.py']),
103- ('lib/ubuntu-scopes/reddit', ['src/__init__.py']),
104+ ('share/unity-scopes/reddit', ['src/unity_reddit_daemon.py'])
105 ], cmdclass={'build': build_extra.build_extra,
106 'build_i18n': build_i18n.build_i18n,})
107
108=== modified file 'src/unity_reddit_daemon.py'
109--- src/unity_reddit_daemon.py 2013-02-21 11:50:58 +0000
110+++ src/unity_reddit_daemon.py 2013-08-15 13:53:44 +0000
111@@ -35,28 +35,16 @@
112 PROVIDER_CREDITS = _('Powered by Reddit')
113 SVG_DIR = '/usr/share/icons/unity-icon-theme/places/svg/'
114 PROVIDER_ICON = SVG_DIR+'service-reddit.svg'
115-DEFAULT_RESULT_ICON = SVG_DIR+'result-info.svg'
116+DEFAULT_RESULT_ICON = SVG_DIR+'service-reddit.svg'
117 DEFAULT_RESULT_MIMETYPE = 'text/html'
118 DEFAULT_RESULT_TYPE = Unity.ResultType.DEFAULT
119
120
121-c1 = {'id' :'hot',
122- 'name' :_('Hot'),
123- 'icon' :SVG_DIR+'group-installed.svg',
124- 'renderer':Unity.CategoryRenderer.VERTICAL_TILE}
125-c2 = {'id' :'new',
126- 'name' :_('New'),
127- 'icon' :SVG_DIR+'group-installed.svg',
128- 'renderer':Unity.CategoryRenderer.VERTICAL_TILE}
129-c2 = {'id' :'controversial',
130- 'name' :_('Controversial'),
131- 'icon' :SVG_DIR+'group-installed.svg',
132- 'renderer':Unity.CategoryRenderer.VERTICAL_TILE}
133-c2 = {'id' :'top',
134- 'name' :_('Top'),
135- 'icon' :SVG_DIR+'group-installed.svg',
136- 'renderer':Unity.CategoryRenderer.VERTICAL_TILE}
137-CATEGORIES = [c1, c2]
138+c1 = {'id' :'results',
139+ 'name' :_('Posts'),
140+ 'icon' :SVG_DIR+'group-installed.svg',
141+ 'renderer':Unity.CategoryRenderer.VERTICAL_TILE}
142+CATEGORIES = [c1]
143
144 FILTERS = []
145
146@@ -66,7 +54,16 @@
147 m2 = {'id' :'author',
148 'type' :'s',
149 'field':Unity.SchemaFieldType.OPTIONAL}
150-EXTRA_METADATA = [m1, m2]
151+m3 = {'id' :'domain',
152+ 'type' :'s',
153+ 'field':Unity.SchemaFieldType.OPTIONAL}
154+m4 = {'id' :'subreddit',
155+ 'type' :'s',
156+ 'field':Unity.SchemaFieldType.OPTIONAL}
157+m5 = {'id' :'comments',
158+ 'type' :'i',
159+ 'field':Unity.SchemaFieldType.OPTIONAL}
160+EXTRA_METADATA = [m1, m2, m3, m4, m5]
161
162 def search(search, filters):
163 '''
164@@ -83,36 +80,49 @@
165 extras metadata fields (variant)
166 '''
167 results = []
168+ uri = ''
169 if not search:
170- return results
171- search = urllib.parse.quote(search)
172- cats = ['hot', 'new', 'controversial', 'top']
173- for cat in cats:
174- uri = '%sr/%s/%s.json?limit=25' % (SEARCH_URI, search, cat)
175- print(uri)
176- data = None
177- try:
178- response = urllib.request.urlopen(uri).read()
179- data = json.loads(response.decode('utf-8'))
180- except Exception as error:
181- print(error)
182- if cat == 'hot':
183- return results
184+ uri = '%shot.json?limit=25' % (SEARCH_URI)
185+ elif len(search) < 3:
186+ return results
187+ else:
188+ search_cleaned = urllib.parse.quote(search.split('#')[0])
189+ uri = '%sr/%s/hot.json?limit=25' % (SEARCH_URI, search_cleaned)
190+ print(uri)
191+ data = None
192+ try:
193+ hdr = { 'User-Agent' : 'unity-scope-reddit' }
194+ req = urllib.request.Request(url=uri,
195+ headers=hdr)
196+ response = urllib.request.urlopen(req).read()
197+ data = json.loads(response.decode('utf-8'))
198+ except Exception as error:
199+ print(error)
200+ return results
201+ if not data or not 'data' in data:
202+ return results
203+ for d in data ['data']['children']:
204+ if d['data']['over_18'] is True and not '#nsfw' in search:
205+ ann_icon = Unity.AnnotatedIcon.new(Gio.ThemedIcon.new(DEFAULT_RESULT_ICON))
206+ ann_icon.props.ribbon = "NSFW"
207+ icon = ann_icon.to_string()
208+ target = ''
209+ else:
210+ if d['data']['thumbnail'] != 'self':
211+ icon = d['data']['thumbnail']
212 else:
213- continue
214- if not data or not 'data' in data:
215- return results
216- for d in data ['data']['children']:
217- if d['data']['over_18'] is True:
218 icon = None
219- else:
220- icon = d['data']['thumbnail']
221- results.append({'uri':'%s%s' % (SEARCH_URI, d['data']['permalink']),
222- 'title':d['data']['title'],
223- 'icon':icon,
224- 'target':GLib.Variant('s', d['data']['url']),
225- 'author':GLib.Variant('s', d['data']['author']),
226- 'category':cats.index(cat)})
227+ target = d['data']['url']
228+ comment = d['data']['selftext']
229+ results.append({'uri':'%s%s' % (SEARCH_URI, d['data']['permalink']),
230+ 'title':d['data']['title'],
231+ 'icon':icon,
232+ 'target':target,
233+ 'author':d['data']['author'],
234+ 'subreddit':d['data']['subreddit'],
235+ 'comment':comment,
236+ 'comments':d['data']['num_comments'],
237+ 'domain':d['data']['domain']})
238 return results
239
240
241@@ -149,22 +159,34 @@
242 i['comment'] = ''
243 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
244 i['dnd_uri'] = i['uri']
245- i['metadata'] = {}
246- if EXTRA_METADATA:
247- for e in i:
248- for m in EXTRA_METADATA:
249- if m['id'] == e:
250- i['metadata'][e] = i[e]
251- i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
252- result = Unity.ScopeResult.create(str(i['uri']), str(i['icon']),
253- i['category'], i['result_type'],
254- str(i['mimetype']), str(i['title']),
255- str(i['comment']), str(i['dnd_uri']),
256- i['metadata'])
257- result_set.add_result(result)
258+ result_set.add_result(**i)
259 except Exception as error:
260 print (error)
261
262+class Preview (Unity.ResultPreviewer):
263+
264+ def do_run(self):
265+ if self.result.metadata['target'].get_string().split('.')[-1] in ['jpg', 'png']:
266+ image = Gio.FileIcon.new (Gio.file_new_for_uri(self.result.metadata['target'].get_string()))
267+ else:
268+ image = Gio.FileIcon.new (Gio.file_new_for_uri(self.result.icon_hint))
269+ if self.result.comment != self.result.title and self.result.comment != '':
270+ description = self.result.comment
271+ elif len(self.result.title) > 23:
272+ description = self.result.title
273+ else:
274+ description = ''
275+ preview = Unity.GenericPreview.new(self.result.title, description, image)
276+ preview.add_info(Unity.InfoHint.new('comments', _('Comments'), None, str(self.result.metadata['comments'].get_int32())))
277+ preview.add_info(Unity.InfoHint.new('subreddit', _('Submitted to'), None, "r/%s" % (self.result.metadata['subreddit'].get_string())))
278+ if not self.result.metadata['domain'].get_string().startswith("self."):
279+ preview.add_info(Unity.InfoHint.new('domain', _('Source'), None, self.result.metadata['domain'].get_string()))
280+ preview.props.subtitle = self.result.metadata['author'].get_string()
281+ icon = Gio.FileIcon.new (Gio.file_new_for_path(PROVIDER_ICON))
282+ open_action = Unity.PreviewAction.new("open", _("View on Reddit"), icon)
283+ preview.add_action(open_action)
284+ return preview
285+
286 class Scope (Unity.AbstractScope):
287 def __init__(self):
288 Unity.AbstractScope.__init__(self)
289@@ -216,5 +238,11 @@
290 se = MySearch (search_context)
291 return se
292
293+ def do_create_previewer(self, result, metadata):
294+ rp = Preview()
295+ rp.set_scope_result(result)
296+ rp.set_search_metadata(metadata)
297+ return rp
298+
299 def load_scope():
300 return Scope()
301
302=== modified file 'tests/test_reddit.py'
303--- tests/test_reddit.py 2013-02-21 11:50:58 +0000
304+++ tests/test_reddit.py 2013-08-15 13:53:44 +0000
305@@ -41,7 +41,7 @@
306 def test_valid_searches(self):
307 self.scope_module.SEARCH_URI = 'file:tests/data/mock_reddit_pass#'
308 expected_results = ['Ubuntu for tablets hands-on video',
309- '/usr/share/icons/unity-icon-theme/places/svg/result-info.svg',
310+ '/usr/share/icons/unity-icon-theme/places/svg/service-reddit.svg',
311 'file:tests/data/mock_reddit_pass#/r/Ubuntu/comments/18wux7/ubuntu_for_tablets_handson_video/']
312 results = []
313 for s in ['ubuntu']:

Subscribers

People subscribed via source and target branches

to all changes: