Merge lp:~submarine/ubuntu-scopes/chromiumbookmarks-multiple-profiles into lp:~submarine/ubuntu-scopes/chromiumbookmarks

Proposed by David Callé
Status: Merged
Approved by: James Henstridge
Approved revision: 23
Merged at revision: 20
Proposed branch: lp:~submarine/ubuntu-scopes/chromiumbookmarks-multiple-profiles
Merge into: lp:~submarine/ubuntu-scopes/chromiumbookmarks
Diff against target: 100 lines (+34/-24)
2 files modified
src/unity_chromiumbookmarks_daemon.py (+29/-21)
tests/test_chromiumbookmarks.py (+5/-3)
To merge this branch: bzr merge lp:~submarine/ubuntu-scopes/chromiumbookmarks-multiple-profiles
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
James Henstridge Approve
Review via email: mp+153928@code.launchpad.net

Commit message

Parse bookmarks for all Chromium profiles

Description of the change

Iterate through all Chromium profiles when looking for bookmarks.

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

Prepare for adding activation for a specific Chromium profile

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

This seems to make the test suite dependent on the user's local bookmarks. While it is unlikely the user might have a bookmark named 'upnriitnyt', it would seem better for the test not to depend on that being the case.

22. By David Callé

Don't parse user profiles when running tests

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

I hadn't considered the test in the context of running on a user machine, thanks.

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

The other issue is that you are extending BOOKMARKS_PATH every time a search runs. This means each successive search will do more work.

How about something like this:

    BOOKMARKS_PATH = None

    def get_chromium_profiles():
        if BOOKMARKS_PATH is not None:
            return [BOOKMARKS_PATH]
        # Otherwise, build up and return the list of profile directories

This should give you the testing hook, and avoid the above problem.

23. By David Callé

Don't extend the list of bookmarks paths on each run

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

Indeed. I've fixed it another way, to catch new chromium profiles while running. (Since we are not shutting daemons down atm)

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

Looks good. It seems a bit weird to use the "About" stock icon to represent bookmarks, but that is a pre-existing issue, so I won't block the merge on that point.

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

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-03-14 12:27:26 +0000
3+++ src/unity_chromiumbookmarks_daemon.py 2013-03-19 08:55:25 +0000
4@@ -39,9 +39,10 @@
5 DEFAULT_RESULT_ICON = SVG_DIR + 'result-help.svg'
6 DEFAULT_RESULT_MIMETYPE = 'text/html'
7 DEFAULT_RESULT_TYPE = Unity.ResultType.DEFAULT
8-BOOKMARKS_PATH = os.getenv("HOME") + "/.config/chromium/Default/Bookmarks"
9+DEFAULT_BOOKMARKS = os.getenv("HOME") + "/.config/chromium/Default/Bookmarks"
10+PARSE_ALL_PROFILES = True
11
12-c1 = {'id': 'bookamrks',
13+c1 = {'id': 'bookmarks',
14 'name': _('Bookmarks'),
15 'icon': SVG_DIR + 'group-installed.svg',
16 'renderer': Unity.CategoryRenderer.VERTICAL_TILE}
17@@ -52,6 +53,19 @@
18 EXTRA_METADATA = []
19
20
21+def get_chromium_profiles():
22+ BOOKMARKS_PATH = [DEFAULT_BOOKMARKS]
23+ if not PARSE_ALL_PROFILES:
24+ return BOOKMARKS_PATH
25+ try:
26+ for f in os.listdir(os.getenv("HOME") + "/.config/chromium/"):
27+ if f == "Default" or f.startswith('Profile '):
28+ BOOKMARKS_PATH.append(os.getenv("HOME") + "/.config/chromium/"+f+"/Bookmarks")
29+ except Exception as error:
30+ print(error)
31+ return BOOKMARKS_PATH
32+
33+
34 def get_bookmarks_from_chromium(path):
35 '''
36 Gets a list of bookmarks from the user's chromium profile
37@@ -113,25 +127,19 @@
38 Search for help documents matching the search string
39 '''
40 results = []
41- bookmarks = get_bookmarks_from_chromium(BOOKMARKS_PATH)
42- icon = Gio.ThemedIcon.new("gtk-about").to_string()
43- for bookmark in bookmarks:
44- # Search bookmark names for matches
45- if not bookmark[0].lower().find(search.lower()) == -1:
46- results.append({'uri': bookmark[1],
47- 'icon': icon,
48- 'category': 0,
49- 'title': bookmark[0],
50- 'comment': bookmark[1]})
51- continue
52-
53- # Search bookmark urls for matches
54- if not bookmark[1].lower().find(search.lower()) == -1:
55- results.append({'uri': bookmark[1],
56- 'icon': icon,
57- 'category': 0,
58- 'title': bookmark[0],
59- 'comment': bookmark[1]})
60+ for path in get_chromium_profiles():
61+ user = path.split('/')[-2]
62+ bookmarks = get_bookmarks_from_chromium(path)
63+ icon = Gio.ThemedIcon.new("gtk-about").to_string()
64+ for bookmark in bookmarks:
65+ # Search bookmark names for matches
66+ if not bookmark[0].lower().find(search.lower()) == -1 or not bookmark[1].lower().find(search.lower()) == -1:
67+ results.append({'uri': bookmark[1],
68+ 'icon': icon,
69+ 'category': 0,
70+ 'title': bookmark[0],
71+ 'comment': bookmark[1],
72+ 'user':GLib.Variant('s',user)})
73 return results
74
75
76
77=== modified file 'tests/test_chromiumbookmarks.py'
78--- tests/test_chromiumbookmarks.py 2013-02-18 01:37:22 +0000
79+++ tests/test_chromiumbookmarks.py 2013-03-19 08:55:25 +0000
80@@ -39,7 +39,8 @@
81 self.scope_module = None
82
83 def test_questions_search(self):
84- self.scope_module.BOOKMARKS_PATH = 'tests/data/mock_chromiumbookmarks_pass'
85+ self.scope_module.DEFAULT_BOOKMARKS = 'tests/data/mock_chromiumbookmarks_pass'
86+ self.scope_module.PARSE_ALL_PROFILES = False
87 expected_results = ["http://www.ubuntu.com/",
88 "Test Bookmark"]
89 results = []
90@@ -51,8 +52,9 @@
91
92
93 def test_questions_failing_search(self):
94- self.scope_module.BOOKMARKS_PATH = 'tests/data/mock_chromiumbookmarks_fail'
95- for s in ['upnriitnyt']:
96+ self.scope_module.DEFAULT_BOOKMARKS = 'tests/data/mock_chromiumbookmarks_fail'
97+ self.scope_module.PARSE_ALL_PROFILES = False
98+ for s in ['ubuntu']:
99 result_set = self.perform_query(s)
100 self.assertEqual(len(result_set.results), 0)
101

Subscribers

People subscribed via source and target branches

to all changes: