Merge lp:~davidc3/unity-scope-github/use-mimetype-icons into lp:unity-scope-github
- use-mimetype-icons
- Merge into trunk
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 |
Related bugs: |
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://
http://
- 26. By David Callé
-
Fix tests for a theme-less setup
PS Jenkins bot (ps-jenkins) wrote : | # |
- 27. By David Callé
-
Add gtk deps
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:27
http://
Executed test runs:
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 28. By David Callé
-
Apply the same fix to people direct search
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:28
http://
Executed test runs:
SUCCESS: http://
Click here to trigger a rebuild:
http://
Michal Hruby (mhr3) wrote : | # |
50 + icon_exists = THEME.lookup_
This is a very expensive call, doing it for each result on each search is too much. A different way has to be found.
- 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
David Callé (davidc3) wrote : | # |
Trying something less expensive.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:29
http://
Executed test runs:
SUCCESS: http://
Click here to trigger a rebuild:
http://
Michal Hruby (mhr3) wrote : | # |
78 + if os.path.
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_
Michal Hruby (mhr3) wrote : | # |
Ie, as long as you need to import Gtk, it's probably not a fast solution.
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
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.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:30
http://
Executed test runs:
FAILURE: http://
Click here to trigger a rebuild:
http://
- 31. By David Callé
-
Don't forget to check for theme existence for builders
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:31
http://
Executed test runs:
SUCCESS: http://
Click here to trigger a rebuild:
http://
Michal Hruby (mhr3) wrote : | # |
43 + 'php':{
44 + 'java':
45 + 'javascript'
46 + 'c#':{'
These do not look like valid mimetypes, should be "text/x-java" etc.
63 + if theme.lookup_
Do we *really* need those lookups? The only thing they do is slow down startup of the scope.
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
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:32
http://
Executed test runs:
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 33. By David Callé
-
Remove GTK deps
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
- 34. By David Callé
-
Pyflakes fixes
Michal Hruby (mhr3) : | # |
Preview Diff
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 | 26 | gir1.2-unity-5.0 (>= 6.91), | 26 | gir1.2-unity-5.0 (>= 6.91), |
6 | 27 | gir1.2-dee-1.0, | 27 | gir1.2-dee-1.0, |
7 | 28 | unity-scopes-runner, | 28 | unity-scopes-runner, |
9 | 29 | gir1.2-glib-2.0 | 29 | gir1.2-glib-2.0, |
10 | 30 | Description: GitHub scope for Unity | 30 | Description: GitHub scope for Unity |
11 | 31 | This package contains the "github" scope which allows Unity | 31 | This package contains the "github" scope which allows Unity |
12 | 32 | to search for GitHub content. | 32 | to search for GitHub content. |
13 | 33 | 33 | ||
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 | 15 | # You should have received a copy of the GNU General Public License along | 15 | # You should have received a copy of the GNU General Public License along |
19 | 16 | # with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | 17 | 17 | ||
23 | 18 | from gi.repository import Unity, UnityExtras | 18 | from gi.repository import Unity |
24 | 19 | from gi.repository import Gio, GLib | 19 | from gi.repository import Gio |
25 | 20 | import json | 20 | import json |
26 | 21 | import urllib.parse | 21 | import urllib.parse |
27 | 22 | import urllib.request | 22 | import urllib.request |
28 | @@ -39,6 +39,25 @@ | |||
29 | 39 | DEFAULT_RESULT_ICON = SVG_DIR+'result-developer.svg' | 39 | DEFAULT_RESULT_ICON = SVG_DIR+'result-developer.svg' |
30 | 40 | DEFAULT_RESULT_MIMETYPE = 'text/html' | 40 | DEFAULT_RESULT_MIMETYPE = 'text/html' |
31 | 41 | DEFAULT_RESULT_TYPE = Unity.ResultType.DEFAULT | 41 | DEFAULT_RESULT_TYPE = Unity.ResultType.DEFAULT |
32 | 42 | ICON_MAP = {'python':{'mime':'text/x-python'}, | ||
33 | 43 | 'ruby':{'mime':'text/x-ruby'}, | ||
34 | 44 | 'php':{'mime':'text/x-php'}, | ||
35 | 45 | 'java':{'mime':'text/x-java'}, | ||
36 | 46 | 'javascript':{'mime':'text/x-javascript'}, | ||
37 | 47 | 'c#':{'mime':'text/x-csharp'}, | ||
38 | 48 | 'css':{'mime':'text/x-css'}, | ||
39 | 49 | 'html':{'mime':'text/x-html'}, | ||
40 | 50 | 'c':{'mime':'text/x-c'}, | ||
41 | 51 | 'shell':{'mime':'text/x-sh'}, | ||
42 | 52 | 'perl':{'mime':'text/x-perl'}, | ||
43 | 53 | 'lua':{'mime':'text/x-lua'}, | ||
44 | 54 | 'vala':{'mime':'text/x-vala'}, | ||
45 | 55 | 'html':{'mime':'text/html'}, | ||
46 | 56 | 'text':{'mime':'text', 'icon':'text'}} | ||
47 | 57 | for i in ICON_MAP: | ||
48 | 58 | icon_list = Gio.content_type_get_icon(ICON_MAP[i]['mime']) | ||
49 | 59 | if icon_list: | ||
50 | 60 | ICON_MAP[i]['icon'] = icon_list.to_string() | ||
51 | 42 | 61 | ||
52 | 43 | c1 = {'id' :'code', | 62 | c1 = {'id' :'code', |
53 | 44 | 'name' :_('Projects'), | 63 | 'name' :_('Projects'), |
54 | @@ -61,6 +80,7 @@ | |||
55 | 61 | 'field':Unity.SchemaFieldType.OPTIONAL} | 80 | 'field':Unity.SchemaFieldType.OPTIONAL} |
56 | 62 | EXTRA_METADATA = [m1, m2, m3] | 81 | EXTRA_METADATA = [m1, m2, m3] |
57 | 63 | 82 | ||
58 | 83 | |||
59 | 64 | def search(search, filters, cancellable): | 84 | def search(search, filters, cancellable): |
60 | 65 | ''' | 85 | ''' |
61 | 66 | Any search method returning results as a list of tuples. | 86 | Any search method returning results as a list of tuples. |
62 | @@ -105,22 +125,33 @@ | |||
63 | 105 | if 'repositories' in data: | 125 | if 'repositories' in data: |
64 | 106 | for d in data['repositories']: | 126 | for d in data['repositories']: |
65 | 107 | if len(results) < 25: | 127 | if len(results) < 25: |
66 | 128 | src = str(d['language']).lower() | ||
67 | 129 | icon = ICON_MAP['text']['icon'] | ||
68 | 130 | if src in ICON_MAP: | ||
69 | 131 | if 'icon' in ICON_MAP[src]: | ||
70 | 132 | icon = ICON_MAP[src]['icon'] | ||
71 | 108 | results.append({'uri':'https://github.com/%s/%s' % (d['owner'], d['name']), | 133 | results.append({'uri':'https://github.com/%s/%s' % (d['owner'], d['name']), |
72 | 109 | 'title':d['name'], | 134 | 'title':d['name'], |
73 | 110 | 'comment':d['description'], | 135 | 'comment':d['description'], |
74 | 111 | 'owner':d['owner'], | 136 | 'owner':d['owner'], |
75 | 112 | 'followers':d['watchers'], | 137 | 'followers':d['watchers'], |
77 | 113 | 'language':str(d['language'])}) | 138 | 'language':str(d['language']), |
78 | 139 | 'icon':icon}) | ||
79 | 114 | else: | 140 | else: |
80 | 115 | for d in data: | 141 | for d in data: |
81 | 116 | if len(results) < 25: | 142 | if len(results) < 25: |
82 | 143 | src = str(d['language']).lower() | ||
83 | 144 | icon = ICON_MAP['text']['icon'] | ||
84 | 145 | if src in ICON_MAP: | ||
85 | 146 | if 'icon' in ICON_MAP[src]: | ||
86 | 147 | icon = ICON_MAP[src]['icon'] | ||
87 | 117 | results.append({'uri':d['html_url'], | 148 | results.append({'uri':d['html_url'], |
88 | 118 | 'icon':d['owner']['avatar_url'], | ||
89 | 119 | 'title':d['name'], | 149 | 'title':d['name'], |
90 | 120 | 'comment':d['description'], | 150 | 'comment':d['description'], |
91 | 121 | 'owner':d['owner']['login'], | 151 | 'owner':d['owner']['login'], |
92 | 122 | 'followers':d['watchers'], | 152 | 'followers':d['watchers'], |
94 | 123 | 'language':str(d['language'])}) | 153 | 'language':str(d['language']), |
95 | 154 | 'icon':icon}) | ||
96 | 124 | return results | 155 | return results |
97 | 125 | 156 | ||
98 | 126 | 157 | ||
99 | 127 | 158 | ||
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 | 49 | result = result_set.results[0] | 49 | result = result_set.results[0] |
105 | 50 | self.assertEqual( | 50 | self.assertEqual( |
106 | 51 | result['uri'], 'https://github.com/tualatrix/ubuntu-tweak') | 51 | result['uri'], 'https://github.com/tualatrix/ubuntu-tweak') |
109 | 52 | self.assertEqual(result['icon'], '/usr/share/icons/unity-icon-theme' | 52 | self.assertEqual(result['icon'], '. GThemedIcon text-x-python gnome-mime-text-x-python text-x-generic') |
108 | 53 | '/places/svg/result-developer.svg') | ||
110 | 54 | self.assertEqual(result['title'], 'ubuntu-tweak') | 53 | self.assertEqual(result['title'], 'ubuntu-tweak') |
111 | 55 | self.assertEqual(result['comment'], 'Ubuntu Tweak is a tool that ' | 54 | self.assertEqual(result['comment'], 'Ubuntu Tweak is a tool that ' |
112 | 56 | 'makes it easy to configure your system and ' | 55 | 'makes it easy to configure your system and ' |
FAILED: Continuous integration, rev:26 jenkins. qa.ubuntu. com/job/ unity-scope- github- ci/4/ jenkins. qa.ubuntu. com/job/ unity-scope- github- raring- amd64-ci/ 4/console
http://
Executed test runs:
FAILURE: http://
Click here to trigger a rebuild: s-jenkins: 8080/job/ unity-scope- github- ci/4/rebuild
http://