Merge lp:~chipaca/unity-lens-video/remote-videos-misc-fixes into lp:unity-lens-video

Proposed by John Lenton
Status: Superseded
Proposed branch: lp:~chipaca/unity-lens-video/remote-videos-misc-fixes
Merge into: lp:unity-lens-video
Diff against target: 321 lines (+260/-0) (has conflicts)
11 files modified
MANIFEST.in (+3/-0)
debian/changelog (+6/-0)
debian/compat (+1/-0)
debian/control (+20/-0)
debian/copyright (+29/-0)
debian/rules (+6/-0)
debian/source/format (+1/-0)
setup.py (+16/-0)
src/unity-scope-video-remote (+172/-0)
unity-scope-video-remote.service (+3/-0)
video-remote.scope (+3/-0)
Conflict adding file MANIFEST.in.  Moved existing file to MANIFEST.in.moved.
Conflict adding file debian.  Moved existing file to debian.moved.
Conflict adding file setup.py.  Moved existing file to setup.py.moved.
Conflict adding file src.  Moved existing file to src.moved.
To merge this branch: bzr merge lp:~chipaca/unity-lens-video/remote-videos-misc-fixes
Reviewer Review Type Date Requested Status
David Callé Approve
Review via email: mp+92062@code.launchpad.net

This proposal has been superseded by a proposal from 2012-02-08.

Description of the change

Some generic cleanups / improvements to the pythonicity, readability and robustness of the code.

To post a comment you must log in.
Revision history for this message
David Callé (davidc3) :
review: Approve

Unmerged revisions

13. By John Lenton

some generic cleanups / improvements to the pythonicity, readability and robustness of the code

12. By David Callé

Merge pep8 and lint fixes from Roberto Alsina

11. By David Callé

A bit of cleaning

10. By David Callé

Move the first server query inside the loop and check for a list of sources after each error. Don't assume we have a network connexion at startup.

9. By David Callé

Don't fail on network error

8. By David Callé

* Use the shiny new v0 API
* Get a real list of sources to create the filter options

7. By David Callé

Generate source internal id

6. By David Callé

Simplify sources management

5. By David Callé

Add sources, search both to test the sources filters, don't thread for now

4. By David Callé

Avoid global search

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'MANIFEST.in'
2--- MANIFEST.in 1970-01-01 00:00:00 +0000
3+++ MANIFEST.in 2012-02-08 16:12:18 +0000
4@@ -0,0 +1,3 @@
5+include unity-scope-video-remote.service
6+include video-remote.scope
7+include src/unity-scope-video-remote
8
9=== renamed file 'MANIFEST.in' => 'MANIFEST.in.moved'
10=== added directory 'debian'
11=== renamed directory 'debian' => 'debian.moved'
12=== added file 'debian/changelog'
13--- debian/changelog 1970-01-01 00:00:00 +0000
14+++ debian/changelog 2012-02-08 16:12:18 +0000
15@@ -0,0 +1,6 @@
16+unity-scope-video-remote (0.1) precise; urgency=low
17+
18+ [ David Callé ]
19+ * First release of the remote video scope
20+
21+ -- David Callé <davidc@framli.eu> Tue, 31 Jan 2012 15:55:00 +0200
22
23=== added file 'debian/compat'
24--- debian/compat 1970-01-01 00:00:00 +0000
25+++ debian/compat 2012-02-08 16:12:18 +0000
26@@ -0,0 +1,1 @@
27+7
28
29=== added file 'debian/control'
30--- debian/control 1970-01-01 00:00:00 +0000
31+++ debian/control 2012-02-08 16:12:18 +0000
32@@ -0,0 +1,20 @@
33+Source: unity-scope-video-remote
34+Section: gnome
35+Priority: optional
36+Maintainer: David Calle <davidc@framli.eu>
37+Build-Depends: debhelper (>= 7.0.50~), python, python-distutils-extra
38+Standards-Version: 3.9.1
39+Homepage: https://launchpad.net/~davidc3
40+
41+Package: unity-scope-video-remote
42+Architecture: all
43+Depends: ${shlibs:Depends},
44+ ${misc:Depends},
45+ ${python:Depends},
46+ gir1.2-unity-5.0,
47+ gir1.2-dee-1.0,
48+ unity-lens-video
49+Enhances: unity-lens-video
50+Description: Remote videos engine
51+ This scope adds a remote videos search engine to the Video lens.
52+
53
54=== added file 'debian/copyright'
55--- debian/copyright 1970-01-01 00:00:00 +0000
56+++ debian/copyright 2012-02-08 16:12:18 +0000
57@@ -0,0 +1,29 @@
58+This package was debianized by David Calle <davidc@framli.eu> on
59+Tue, 31 Jan 2012 16:00:00 +0200.
60+
61+It was downloaded from <https://code.launchpad.net/~davidc3>
62+
63+Upstream Author:
64+
65+ David Calle <davidc@framli.eu>
66+
67+Copyright:
68+
69+ Copyright (c) 2012 David Calle <davidc@framli.eu>
70+
71+License:
72+
73+ This program is free software: you can redistribute it and/or modify
74+ it under the terms of the GNU General Public License version 3 as
75+ published by the Free Software Foundation.
76+
77+ This program is distributed in the hope that it will be useful,
78+ but WITHOUT ANY WARRANTY; without even the implied warranty of
79+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
80+ GNU General Public License for more details.
81+
82+On Debian systems, the complete text of the GNU General Public License
83+can be found in `/usr/share/common-licenses/GPL-3'
84+
85+The Debian packaging is licensed under the GPL version 3,
86+see `/usr/share/common-licenses/GPL-3'.
87
88=== added file 'debian/rules'
89--- debian/rules 1970-01-01 00:00:00 +0000
90+++ debian/rules 2012-02-08 16:12:18 +0000
91@@ -0,0 +1,6 @@
92+#!/usr/bin/make -f
93+# -*- makefile -*-
94+
95+
96+%:
97+ dh $@ --with python2
98
99=== added directory 'debian/source'
100=== added file 'debian/source/format'
101--- debian/source/format 1970-01-01 00:00:00 +0000
102+++ debian/source/format 2012-02-08 16:12:18 +0000
103@@ -0,0 +1,1 @@
104+3.0 (native)
105
106=== added file 'setup.py'
107--- setup.py 1970-01-01 00:00:00 +0000
108+++ setup.py 2012-02-08 16:12:18 +0000
109@@ -0,0 +1,16 @@
110+#!/usr/bin/env python
111+#
112+from distutils.core import setup
113+from DistUtilsExtra.command import *
114+
115+setup(name="unity-scope-video-remote",
116+ version="0.1",
117+ author="David Calle",
118+ author_email="davidc@framli.eu",
119+ url="http://launchpad.net/onehundredscopes",
120+ license="GNU General Public License (GPL)",
121+ data_files=[
122+ ('lib/unity-scope-video-remote', ['src/unity-scope-video-remote']),
123+ ('share/dbus-1/services', ['unity-scope-video-remote.service']),
124+ ('share/unity/lenses/video', ['video-remote.scope']),
125+ ], cmdclass={"build": build_extra.build_extra, })
126
127=== renamed file 'setup.py' => 'setup.py.moved'
128=== added directory 'src'
129=== renamed directory 'src' => 'src.moved'
130=== added file 'src/unity-scope-video-remote'
131--- src/unity-scope-video-remote 1970-01-01 00:00:00 +0000
132+++ src/unity-scope-video-remote 2012-02-08 16:12:18 +0000
133@@ -0,0 +1,172 @@
134+#! /usr/bin/python
135+# -*- coding: utf-8 -*-
136+
137+# Copyright (c) 2011 David Calle <davidc@framli.eu>
138+
139+# This program is free software: you can redistribute it and/or modify
140+# it under the terms of the GNU General Public License as published by
141+# the Free Software Foundation, either version 3 of the License, or
142+# (at your option) any later version.
143+
144+# This program is distributed in the hope that it will be useful,
145+# but WITHOUT ANY WARRANTY; without even the implied warranty of
146+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
147+# GNU General Public License for more details.
148+
149+# You should have received a copy of the GNU General Public License
150+# along with this program. If not, see <http://www.gnu.org/licenses/>.
151+
152+"""FIXME: add docstring."""
153+
154+import json
155+import sys
156+import urllib
157+import urllib2
158+
159+
160+#pylint: disable=E0611
161+from gi.repository import (
162+ GLib,
163+ GObject,
164+ Gio,
165+ Unity,
166+)
167+#pylint: enable=E0611
168+
169+BUS_NAME = "net.launchpad.scope.video.remote"
170+SERVER = "http://video.u1.to/v0"
171+
172+
173+class Daemon:
174+
175+ """FIXME Add docstring."""
176+
177+ def __init__(self):
178+ self.sources_list = None
179+ self.scope = Unity.Scope.new("/net/launchpad/scope/video/remote")
180+ self.scope.search_in_global = False
181+ self.scope.connect("search-changed", self.on_search_changed)
182+ self.scope.connect("filters-changed",
183+ lambda scope:
184+ self.scope.queue_search_changed(Unity.SearchType.DEFAULT))
185+ self.scope.props.sources.connect("notify::filtering",
186+ self.on_filtering_changed)
187+ self.query_list_of_sources()
188+ self.scope.export()
189+
190+ def query_list_of_sources(self):
191+ """FIXME Add docstring."""
192+ try:
193+ self.sources_list = json.load(urllib2.urlopen("%s/sources"
194+ % (SERVER,)))
195+ print "Got a list of sources from the server."
196+ except (IOError,
197+ KeyError,
198+ urllib2.URLError,
199+ urllib2.HTTPError,
200+ ValueError):
201+ self.sources_list = []
202+ print "Error: Unable to query the server for a list of sources"
203+ else:
204+ for n, source in enumerate(self.sources_list):
205+ self.scope.props.sources.add_option(str(n), source, None)
206+
207+ def on_filtering_changed(self, *_):
208+ """FIXME Add docstring."""
209+ self.scope.queue_search_changed(Unity.SearchType.DEFAULT)
210+
211+ # FIXME: if scope is not used, rename it _
212+ def source_activated(self, scope, source):
213+ """FIXME Add docstring."""
214+ # This is currently the only way to get the state of
215+ # the filter option with certainty
216+ active = self.scope.props.sources.get_option(source).props.active
217+ filtering = self.scope.props.sources.props.filtering
218+ # equivalent to "return not (active ^ filtering)", but more readable
219+ if (active and filtering) or (not active and not filtering):
220+ return True
221+ else:
222+ return False
223+
224+ # FIXME: if cancellable is not used, rename it _
225+ def on_search_changed(self, scope, search, search_type, cancellable):
226+ """FIXME Add docstring."""
227+ search_string = search.props.search_string.strip()
228+ # note search_string is a utf-8 encoded string, now:
229+ print "Search changed to %r" % search_string
230+ model = search.props.results_model
231+ model.clear()
232+ # Create a list of activated sources
233+ sources = [source for n, source in enumerate(self.sources_list)
234+ if self.source_activated(scope, str(n))]
235+ # If all the sources are activated, don't bother
236+ # passing them as arguments
237+ if len(sources) == len(self.sources_list):
238+ sources = ''
239+ else:
240+ sources = ','.join(sources)
241+ # Ensure that we are not in Global search
242+ if search_type is Unity.SearchType.DEFAULT:
243+ self.update_results_model(search_string, model, sources)
244+ model.flush_revision_queue()
245+ if search:
246+ search.finished()
247+
248+ def update_results_model(self, search, model, sources):
249+ """FIXME Add docstring."""
250+ self.pyvore(search, model, sources)
251+ if self.sources_list == []:
252+ self.query_list_of_sources()
253+
254+ def pyvore_search(self, search, sources):
255+ """FIXME Add docstring."""
256+ try:
257+ query = dict(q=search)
258+ if sources:
259+ query['sources'] = sources
260+ query = urllib.urlencode(query)
261+ url = "%s/search?%s" % (SERVER, query)
262+ print "Querying the server:", url
263+ return json.load(urllib2.urlopen(url))
264+ except (IOError,
265+ KeyError,
266+ urllib2.URLError,
267+ urllib2.HTTPError,
268+ ValueError):
269+ print "Error: Unable to get results from the server"
270+ return []
271+
272+ def pyvore(self, search, model, sources):
273+ """FIXME Add docstring."""
274+ for i in self.pyvore_search(search, sources):
275+ uri = i['url']
276+ title = i['title']
277+ icon = i['img']
278+ comment = i['source']
279+ if uri.startswith('http'):
280+ model.append(uri, icon, 1, "text/html", title, comment, uri)
281+
282+
283+def main():
284+ """DAVID: insert reasonable docstring here."""
285+ session_bus_connection = Gio.bus_get_sync(Gio.BusType.SESSION, None)
286+ session_bus = Gio.DBusProxy.new_sync(session_bus_connection, 0, None,
287+ 'org.freedesktop.DBus',
288+ '/org/freedesktop/DBus',
289+ 'org.freedesktop.DBus', None)
290+ result = session_bus.call_sync('RequestName',
291+ GLib.Variant("(su)", (BUS_NAME, 0x4)),
292+ 0, -1, None)
293+
294+ # Unpack variant response with signature "(u)". 1 means we got it.
295+ result = result.unpack()[0]
296+
297+ if result != 1:
298+ print >> sys.stderr, "Failed to own name %s. Bailing out." % BUS_NAME
299+ raise SystemExit(1)
300+
301+ Daemon()
302+ GObject.MainLoop().run()
303+
304+if __name__ == "__main__":
305+ main()
306
307=== added file 'unity-scope-video-remote.service'
308--- unity-scope-video-remote.service 1970-01-01 00:00:00 +0000
309+++ unity-scope-video-remote.service 2012-02-08 16:12:18 +0000
310@@ -0,0 +1,3 @@
311+[D-BUS Service]
312+Name=net.launchpad.scope.video.remote
313+Exec=/usr/lib/unity-scope-video-remote/unity-scope-video-remote
314
315=== added file 'video-remote.scope'
316--- video-remote.scope 1970-01-01 00:00:00 +0000
317+++ video-remote.scope 2012-02-08 16:12:18 +0000
318@@ -0,0 +1,3 @@
319+[Scope]
320+DBusName=net.launchpad.scope.video.remote
321+DBusPath=/net/launchpad/scope/video/remote

Subscribers

People subscribed via source and target branches