Merge lp:~davidc3/unity-scope-chromiumbookmarks/icons-n-dups into lp:unity-scope-chromiumbookmarks

Proposed by David Callé
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 30
Merged at revision: 28
Proposed branch: lp:~davidc3/unity-scope-chromiumbookmarks/icons-n-dups
Merge into: lp:unity-scope-chromiumbookmarks
Diff against target: 106 lines (+20/-19)
1 file modified
src/unity_chromiumbookmarks_daemon.py (+20/-19)
To merge this branch: bzr merge lp:~davidc3/unity-scope-chromiumbookmarks/icons-n-dups
Reviewer Review Type Date Requested Status
Paweł Stołowski (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+164055@code.launchpad.net

Commit message

Fix icons and duplicated results

Description of the change

This branch:
- deduplicates results by ensuring that profiles are only added once to the parsing list.
- prevents an unrelated icon to be used for the next result.
- Cleans the result set creation

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Paweł Stołowski (stolowski) wrote :

48 + open('/tmp/unity-scope-chromiumbookmarks/' + thumbname , 'wb').write(imageinfo)
49 + icon = '/tmp/unity-scope-chromiumbookmarks/' + thumbname

This doesn't seem to be multi-session friendly and also can easily be abused on a multi-user system. Can you generate a true temporary name on startup?

review: Needs Fixing
29. By David Callé

Create a true temporary folder

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

Updated

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Paweł Stołowski (stolowski) wrote :

45 + if not os.path.exists(TMP):
46 + tmp_folder = tempfile.mkdtemp()

shouldn't it also set TMP = tmp_folder? Otherwise, if TMP doesn't exist, it will create a new tmp folder on each search?

review: Needs Information
30. By David Callé

Set the correct TMP value for each search

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Paweł Stołowski (stolowski) wrote :

Looks good now. +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/unity_chromiumbookmarks_daemon.py'
--- src/unity_chromiumbookmarks_daemon.py 2013-05-01 23:49:30 +0000
+++ src/unity_chromiumbookmarks_daemon.py 2013-05-16 14:38:30 +0000
@@ -22,6 +22,7 @@
22import json22import json
23import re23import re
24import sqlite324import sqlite3
25import tempfile
2526
26APP_NAME = 'unity-scope-chromiumbookmarks'27APP_NAME = 'unity-scope-chromiumbookmarks'
27LOCAL_PATH = '/usr/share/locale/'28LOCAL_PATH = '/usr/share/locale/'
@@ -37,13 +38,14 @@
37PROVIDER_CREDITS = _('')38PROVIDER_CREDITS = _('')
38SVG_DIR = '/usr/share/icons/unity-icon-theme/places/svg/'39SVG_DIR = '/usr/share/icons/unity-icon-theme/places/svg/'
39PROVIDER_ICON = SVG_DIR + 'service-chromiumbookmarks.svg'40PROVIDER_ICON = SVG_DIR + 'service-chromiumbookmarks.svg'
40DEFAULT_RESULT_ICON = SVG_DIR + 'result-help.svg'41DEFAULT_RESULT_ICON = 'gtk-about'
41DEFAULT_RESULT_MIMETYPE = 'text/html'42DEFAULT_RESULT_MIMETYPE = 'text/html'
42DEFAULT_RESULT_TYPE = Unity.ResultType.DEFAULT43DEFAULT_RESULT_TYPE = Unity.ResultType.DEFAULT
43DEFAULT_BOOKMARKS = os.getenv("HOME") + "/.config/chromium/Default/Bookmarks"44DEFAULT_BOOKMARKS = os.getenv("HOME") + "/.config/chromium/Default/Bookmarks"
44DEFAULT_TOP_SITES = ''45DEFAULT_TOP_SITES = ''
45PARSE_ALL_PROFILES = True46PARSE_ALL_PROFILES = True
46CHROMIUM_EXECUTABLE = '/usr/bin/chromium-browser'47CHROMIUM_EXECUTABLE = '/usr/bin/chromium-browser'
48TMP = tempfile.mkdtemp()
4749
48c1 = {'id': 'bookmarks',50c1 = {'id': 'bookmarks',
49 'name': _('Bookmarks'),51 'name': _('Bookmarks'),
@@ -63,7 +65,9 @@
63 try:65 try:
64 for f in os.listdir(os.getenv("HOME") + "/.config/chromium/"):66 for f in os.listdir(os.getenv("HOME") + "/.config/chromium/"):
65 if f == "Default" or f.startswith('Profile '):67 if f == "Default" or f.startswith('Profile '):
66 BOOKMARKS_PATH.append(os.getenv("HOME") + "/.config/chromium/"+f+"/Bookmarks")68 profile_path = os.getenv("HOME") + "/.config/chromium/"+f+"/Bookmarks"
69 if not profile_path in BOOKMARKS_PATH:
70 BOOKMARKS_PATH.append(profile_path)
67 except Exception as error:71 except Exception as error:
68 print(error)72 print(error)
69 return BOOKMARKS_PATH73 return BOOKMARKS_PATH
@@ -130,8 +134,12 @@
130 Search for help documents matching the search string134 Search for help documents matching the search string
131 '''135 '''
132 results = []136 results = []
133 if not os.path.exists('/tmp/unity-scope-chromiumbookmarks'):137 global TMP
134 os.mkdir('/tmp/unity-scope-chromiumbookmarks')138 if not os.path.exists(TMP):
139 tmp_folder = tempfile.mkdtemp()
140 TMP = tmp_folder
141 else:
142 tmp_folder = TMP
135143
136 for path in get_chromium_profiles():144 for path in get_chromium_profiles():
137 user = path.split('/')[-2]145 user = path.split('/')[-2]
@@ -141,9 +149,6 @@
141 thumbnail_path = DEFAULT_TOP_SITES149 thumbnail_path = DEFAULT_TOP_SITES
142 else:150 else:
143 thumbnail_path = path.replace('Bookmarks', 'Top Sites')151 thumbnail_path = path.replace('Bookmarks', 'Top Sites')
144
145 icon = 'gtk-about'
146
147 conn = sqlite3.connect(thumbnail_path)152 conn = sqlite3.connect(thumbnail_path)
148 connection = conn.cursor()153 connection = conn.cursor()
149154
@@ -151,22 +156,23 @@
151 # Search bookmark names for matches156 # Search bookmark names for matches
152 if search.lower() in bookmark[0].lower() or search.lower() in bookmark[1].lower():157 if search.lower() in bookmark[0].lower() or search.lower() in bookmark[1].lower():
153 sqlite_query = '''SELECT thumbnail FROM thumbnails WHERE url = "%s"''' % bookmark[1]158 sqlite_query = '''SELECT thumbnail FROM thumbnails WHERE url = "%s"''' % bookmark[1]
154 159 icon = None
155 connection.execute(sqlite_query)160 connection.execute(sqlite_query)
156 thumb = connection.fetchall()161 thumb = connection.fetchall()
157 thumbname = bookmark[1].replace('/', '')162 thumbname = bookmark[1].replace('/', '')
158 if thumb:163 if thumb:
159 imageinfo = thumb[0][0]164 imageinfo = thumb[0][0]
160 open('/tmp/unity-scope-chromiumbookmarks/' + thumbname , 'wb').write(imageinfo)165 if imageinfo:
161 icon = '/tmp/unity-scope-chromiumbookmarks/' + thumbname166 open('%s/%s' % (tmp_folder, thumbname) , 'wb').write(imageinfo)
167 icon = '%s/%s' % (tmp_folder, thumbname)
162 else:168 else:
163 if os.path.exists('/tmp/unity-scope-chromiumbookmarks/' + thumbname):169 if os.path.exists('%s/%s' % (tmp_folder, thumbname)):
164 os.remove('/tmp/unity-scope-chromiumbookmarks/' + thumbname)170 os.remove('%s/%s' % (tmp_folder, thumbname))
165 results.append({'uri': bookmark[1],171 results.append({'uri': bookmark[1],
166 'icon': icon,172 'icon': icon,
167 'category': 0,173 'category': 0,
168 'title': bookmark[0],174 'title': bookmark[0],
169 'user':GLib.Variant('s',user)})175 'user':user})
170 connection.close()176 connection.close()
171 return results177 return results
172178
@@ -240,12 +246,7 @@
240 if m['id'] == e:246 if m['id'] == e:
241 i['metadata'][e] = i[e]247 i['metadata'][e] = i[e]
242 i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)248 i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
243 result = Unity.ScopeResult.create(str(i['uri']), str(i['icon']),249 result_set.add_result(**i)
244 i['category'], i['result_type'],
245 str(i['mimetype']), str(i['title']),
246 str(i['comment']), str(i['dnd_uri']),
247 i['metadata'])
248 result_set.add_result(result)
249 except Exception as error:250 except Exception as error:
250 print(error)251 print(error)
251252

Subscribers

People subscribed via source and target branches

to all changes: