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
1=== modified file 'src/unity_chromiumbookmarks_daemon.py'
2--- src/unity_chromiumbookmarks_daemon.py 2013-05-01 23:49:30 +0000
3+++ src/unity_chromiumbookmarks_daemon.py 2013-05-16 14:38:30 +0000
4@@ -22,6 +22,7 @@
5 import json
6 import re
7 import sqlite3
8+import tempfile
9
10 APP_NAME = 'unity-scope-chromiumbookmarks'
11 LOCAL_PATH = '/usr/share/locale/'
12@@ -37,13 +38,14 @@
13 PROVIDER_CREDITS = _('')
14 SVG_DIR = '/usr/share/icons/unity-icon-theme/places/svg/'
15 PROVIDER_ICON = SVG_DIR + 'service-chromiumbookmarks.svg'
16-DEFAULT_RESULT_ICON = SVG_DIR + 'result-help.svg'
17+DEFAULT_RESULT_ICON = 'gtk-about'
18 DEFAULT_RESULT_MIMETYPE = 'text/html'
19 DEFAULT_RESULT_TYPE = Unity.ResultType.DEFAULT
20 DEFAULT_BOOKMARKS = os.getenv("HOME") + "/.config/chromium/Default/Bookmarks"
21 DEFAULT_TOP_SITES = ''
22 PARSE_ALL_PROFILES = True
23 CHROMIUM_EXECUTABLE = '/usr/bin/chromium-browser'
24+TMP = tempfile.mkdtemp()
25
26 c1 = {'id': 'bookmarks',
27 'name': _('Bookmarks'),
28@@ -63,7 +65,9 @@
29 try:
30 for f in os.listdir(os.getenv("HOME") + "/.config/chromium/"):
31 if f == "Default" or f.startswith('Profile '):
32- BOOKMARKS_PATH.append(os.getenv("HOME") + "/.config/chromium/"+f+"/Bookmarks")
33+ profile_path = os.getenv("HOME") + "/.config/chromium/"+f+"/Bookmarks"
34+ if not profile_path in BOOKMARKS_PATH:
35+ BOOKMARKS_PATH.append(profile_path)
36 except Exception as error:
37 print(error)
38 return BOOKMARKS_PATH
39@@ -130,8 +134,12 @@
40 Search for help documents matching the search string
41 '''
42 results = []
43- if not os.path.exists('/tmp/unity-scope-chromiumbookmarks'):
44- os.mkdir('/tmp/unity-scope-chromiumbookmarks')
45+ global TMP
46+ if not os.path.exists(TMP):
47+ tmp_folder = tempfile.mkdtemp()
48+ TMP = tmp_folder
49+ else:
50+ tmp_folder = TMP
51
52 for path in get_chromium_profiles():
53 user = path.split('/')[-2]
54@@ -141,9 +149,6 @@
55 thumbnail_path = DEFAULT_TOP_SITES
56 else:
57 thumbnail_path = path.replace('Bookmarks', 'Top Sites')
58-
59- icon = 'gtk-about'
60-
61 conn = sqlite3.connect(thumbnail_path)
62 connection = conn.cursor()
63
64@@ -151,22 +156,23 @@
65 # Search bookmark names for matches
66 if search.lower() in bookmark[0].lower() or search.lower() in bookmark[1].lower():
67 sqlite_query = '''SELECT thumbnail FROM thumbnails WHERE url = "%s"''' % bookmark[1]
68-
69+ icon = None
70 connection.execute(sqlite_query)
71 thumb = connection.fetchall()
72 thumbname = bookmark[1].replace('/', '')
73 if thumb:
74 imageinfo = thumb[0][0]
75- open('/tmp/unity-scope-chromiumbookmarks/' + thumbname , 'wb').write(imageinfo)
76- icon = '/tmp/unity-scope-chromiumbookmarks/' + thumbname
77+ if imageinfo:
78+ open('%s/%s' % (tmp_folder, thumbname) , 'wb').write(imageinfo)
79+ icon = '%s/%s' % (tmp_folder, thumbname)
80 else:
81- if os.path.exists('/tmp/unity-scope-chromiumbookmarks/' + thumbname):
82- os.remove('/tmp/unity-scope-chromiumbookmarks/' + thumbname)
83+ if os.path.exists('%s/%s' % (tmp_folder, thumbname)):
84+ os.remove('%s/%s' % (tmp_folder, thumbname))
85 results.append({'uri': bookmark[1],
86 'icon': icon,
87 'category': 0,
88 'title': bookmark[0],
89- 'user':GLib.Variant('s',user)})
90+ 'user':user})
91 connection.close()
92 return results
93
94@@ -240,12 +246,7 @@
95 if m['id'] == e:
96 i['metadata'][e] = i[e]
97 i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
98- result = Unity.ScopeResult.create(str(i['uri']), str(i['icon']),
99- i['category'], i['result_type'],
100- str(i['mimetype']), str(i['title']),
101- str(i['comment']), str(i['dnd_uri']),
102- i['metadata'])
103- result_set.add_result(result)
104+ result_set.add_result(**i)
105 except Exception as error:
106 print(error)
107

Subscribers

People subscribed via source and target branches

to all changes: