Merge lp:~davidc3/unity-scope-github/use-mimetype-icons into lp:unity-scope-github

Proposed by David Callé
Status: Merged
Approved by: Michal Hruby
Approved revision: 34
Merged at revision: 26
Proposed branch: lp:~davidc3/unity-scope-github/use-mimetype-icons
Merge into: lp:unity-scope-github
Diff against target: 112 lines (+38/-8)
3 files modified
debian/control (+1/-1)
src/unity_github_daemon.py (+36/-5)
tests/test_github.py (+1/-2)
To merge this branch: bzr merge lp:~davidc3/unity-scope-github/use-mimetype-icons
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+161430@code.launchpad.net

Commit message

Use the language used in a github result as its icon

Description of the change

Use the main language of a github project as its result icon

http://ubuntuone.com/4iDuWvr52DDG5yLT01q80u
http://ubuntuone.com/0oHJRkin0Qc1OyxS7CukDu

To post a comment you must log in.
26. By David Callé

Fix tests for a theme-less setup

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

Add gtk deps

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

Apply the same fix to people direct search

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

50 + icon_exists = THEME.lookup_icon(icon_ext, 64, 0)

This is a very expensive call, doing it for each result on each search is too much. A different way has to be found.

review: Needs Fixing
29. By David Callé

Don't use icon lookup for each result. Lookup the theme path and extension for mimetype icons only once at startup

Revision history for this message
David Callé (davidc3) wrote :

Trying something less expensive.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

78 + if os.path.isfile("%s/%s.%s" % (THEME_PATH, potential_icon, ICON_EXTENSION)):

This is still a fstat() for each result, and that's expensive. How about just having a static dict that would map the languages to a mimetype(/content type), doing a lookup in that dict and using g_content_type_get_icon().

review: Needs Fixing
Revision history for this message
Michal Hruby (mhr3) wrote :

Ie, as long as you need to import Gtk, it's probably not a fast solution.

Revision history for this message
James Henstridge (jamesh) wrote :

Rather than searching for icons in the same directory as the "text-x-python" one, why not have a dictionary mapping language => icon_name and cache the lookup_icon result?

While it might be expensive to perform the lookup on every search, it should be okay if you amortise the result over many requests (and will probably be faster than the stat system call os.path.isfile() does).

30. By David Callé

Generate icon map at scope startup

Revision history for this message
David Callé (davidc3) wrote :

Added icon map creation at scope startup with fallback on generic if icon not present and fallback on 'text' if language not mapped.

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

Don't forget to check for theme existence for builders

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

43 + 'php':{'mime':'text/x/php'},
44 + 'java':{'mime':'text/x/java'},
45 + 'javascript':{'mime':'text/x/javascript'},
46 + 'c#':{'mime':'text/x/csharp'},

These do not look like valid mimetypes, should be "text/x-java" etc.

63 + if theme.lookup_icon(icon, 64, 0):

Do we *really* need those lookups? The only thing they do is slow down startup of the scope.

Revision history for this message
David Callé (davidc3) wrote :

This was in a "work with any theme" spirit and avoid blank result icons in some cases, but we don't really need them.

32. By David Callé

Fix mimetypes, don't do extra checks for each specific icon. Unity does it and fallbacks for us

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

Remove GTK deps

Revision history for this message
Michal Hruby (mhr3) wrote :

8 - gir1.2-glib-2.0
9 + gir1.2-glib-2.0,

I guess the comma shouldn't be there.

21 +import os

Doesn't seem to be used anywhere

review: Needs Fixing
34. By David Callé

Pyflakes fixes

Revision history for this message
Michal Hruby (mhr3) :
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 2013-03-21 19:07:16 +0000
3+++ debian/control 2013-05-08 13:25:29 +0000
4@@ -26,7 +26,7 @@
5 gir1.2-unity-5.0 (>= 6.91),
6 gir1.2-dee-1.0,
7 unity-scopes-runner,
8- gir1.2-glib-2.0
9+ gir1.2-glib-2.0,
10 Description: GitHub scope for Unity
11 This package contains the "github" scope which allows Unity
12 to search for GitHub content.
13
14=== modified file 'src/unity_github_daemon.py'
15--- src/unity_github_daemon.py 2013-04-25 13:41:34 +0000
16+++ src/unity_github_daemon.py 2013-05-08 13:25:29 +0000
17@@ -15,8 +15,8 @@
18 # You should have received a copy of the GNU General Public License along
19 # with this program. If not, see <http://www.gnu.org/licenses/>.
20
21-from gi.repository import Unity, UnityExtras
22-from gi.repository import Gio, GLib
23+from gi.repository import Unity
24+from gi.repository import Gio
25 import json
26 import urllib.parse
27 import urllib.request
28@@ -39,6 +39,25 @@
29 DEFAULT_RESULT_ICON = SVG_DIR+'result-developer.svg'
30 DEFAULT_RESULT_MIMETYPE = 'text/html'
31 DEFAULT_RESULT_TYPE = Unity.ResultType.DEFAULT
32+ICON_MAP = {'python':{'mime':'text/x-python'},
33+ 'ruby':{'mime':'text/x-ruby'},
34+ 'php':{'mime':'text/x-php'},
35+ 'java':{'mime':'text/x-java'},
36+ 'javascript':{'mime':'text/x-javascript'},
37+ 'c#':{'mime':'text/x-csharp'},
38+ 'css':{'mime':'text/x-css'},
39+ 'html':{'mime':'text/x-html'},
40+ 'c':{'mime':'text/x-c'},
41+ 'shell':{'mime':'text/x-sh'},
42+ 'perl':{'mime':'text/x-perl'},
43+ 'lua':{'mime':'text/x-lua'},
44+ 'vala':{'mime':'text/x-vala'},
45+ 'html':{'mime':'text/html'},
46+ 'text':{'mime':'text', 'icon':'text'}}
47+for i in ICON_MAP:
48+ icon_list = Gio.content_type_get_icon(ICON_MAP[i]['mime'])
49+ if icon_list:
50+ ICON_MAP[i]['icon'] = icon_list.to_string()
51
52 c1 = {'id' :'code',
53 'name' :_('Projects'),
54@@ -61,6 +80,7 @@
55 'field':Unity.SchemaFieldType.OPTIONAL}
56 EXTRA_METADATA = [m1, m2, m3]
57
58+
59 def search(search, filters, cancellable):
60 '''
61 Any search method returning results as a list of tuples.
62@@ -105,22 +125,33 @@
63 if 'repositories' in data:
64 for d in data['repositories']:
65 if len(results) < 25:
66+ src = str(d['language']).lower()
67+ icon = ICON_MAP['text']['icon']
68+ if src in ICON_MAP:
69+ if 'icon' in ICON_MAP[src]:
70+ icon = ICON_MAP[src]['icon']
71 results.append({'uri':'https://github.com/%s/%s' % (d['owner'], d['name']),
72 'title':d['name'],
73 'comment':d['description'],
74 'owner':d['owner'],
75 'followers':d['watchers'],
76- 'language':str(d['language'])})
77+ 'language':str(d['language']),
78+ 'icon':icon})
79 else:
80 for d in data:
81 if len(results) < 25:
82+ src = str(d['language']).lower()
83+ icon = ICON_MAP['text']['icon']
84+ if src in ICON_MAP:
85+ if 'icon' in ICON_MAP[src]:
86+ icon = ICON_MAP[src]['icon']
87 results.append({'uri':d['html_url'],
88- 'icon':d['owner']['avatar_url'],
89 'title':d['name'],
90 'comment':d['description'],
91 'owner':d['owner']['login'],
92 'followers':d['watchers'],
93- 'language':str(d['language'])})
94+ 'language':str(d['language']),
95+ 'icon':icon})
96 return results
97
98
99
100=== modified file 'tests/test_github.py'
101--- tests/test_github.py 2013-04-25 13:41:34 +0000
102+++ tests/test_github.py 2013-05-08 13:25:29 +0000
103@@ -49,8 +49,7 @@
104 result = result_set.results[0]
105 self.assertEqual(
106 result['uri'], 'https://github.com/tualatrix/ubuntu-tweak')
107- self.assertEqual(result['icon'], '/usr/share/icons/unity-icon-theme'
108- '/places/svg/result-developer.svg')
109+ self.assertEqual(result['icon'], '. GThemedIcon text-x-python gnome-mime-text-x-python text-x-generic')
110 self.assertEqual(result['title'], 'ubuntu-tweak')
111 self.assertEqual(result['comment'], 'Ubuntu Tweak is a tool that '
112 'makes it easy to configure your system and '

Subscribers

People subscribed via source and target branches

to all changes: