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

Proposed by Mark Tully
Status: Merged
Approved by: James Henstridge
Approved revision: 19
Merged at revision: 18
Proposed branch: lp:~submarine/ubuntu-scopes/firefoxbookmarks-multiple-profiles
Merge into: lp:~submarine/ubuntu-scopes/firefoxbookmarks
Diff against target: 85 lines (+34/-26)
1 file modified
src/unity_firefoxbookmarks_daemon.py (+34/-26)
To merge this branch: bzr merge lp:~submarine/ubuntu-scopes/firefoxbookmarks-multiple-profiles
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
James Henstridge Approve
Review via email: mp+153967@code.launchpad.net

Commit message

Parse bookmarks for all Firefox profiles

Description of the change

Iterate through all Firefox profiles when looking for bookmarks.

To post a comment you must log in.
Revision history for this message
James Henstridge (jamesh) wrote :

Is there any reason you've removed your name from the copyright header?

And while you haven't introduced it in this change, the bare except is bad practice since it can hide mistakes (e.g. if you mistyped a method name, it would swallow the AttributeError). It looks like it would be sufficient to catch sqlite3.DatabaseError here.

19. By Mark Tully

Readded copyright name
Specified sqlite.DatabaseError exception in get_bookmarks_from_firefox()

Revision history for this message
Mark Tully (markjtully) wrote :

I removed the name by mistake. It's readded now. I've also specified the exception type as suggested.

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

+1

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

Looks good.

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_firefoxbookmarks_daemon.py'
2--- src/unity_firefoxbookmarks_daemon.py 2013-03-14 12:27:56 +0000
3+++ src/unity_firefoxbookmarks_daemon.py 2013-03-19 13:43:23 +0000
4@@ -53,33 +53,39 @@
5
6 def get_bookmarks_from_firefox(path):
7 '''
8- Gets a list of bookmarks from the user's firefox profile
9+ Gets a list of bookmarks from the user's firefox profiles
10 '''
11- # Build Firefox's profile path
12- firefox_dbfile = ""
13+ # Build Firefox's profile paths
14+ firefox_dbfiles = []
15 bookmarks = []
16 for folder in os.listdir(path):
17- if folder.endswith(".default"):
18- firefox_dbfile = path + folder + "/places.sqlite"
19-
20- if os.path.exists(firefox_dbfile):
21- try:
22- sqlite_query = '''SELECT moz_bookmarks.title, moz_places.url, moz_favicons.url
23- FROM moz_bookmarks, moz_places, moz_favicons
24- WHERE moz_places.id = moz_bookmarks.fk
25- AND moz_places.favicon_id = moz_favicons.id
26- AND moz_bookmarks.title is not null
27- AND moz_places.favicon_id is not null
28- AND moz_bookmarks.type = 1
29- ORDER BY moz_bookmarks.lastModified;'''
30-
31- conn = sqlite3.connect(firefox_dbfile)
32- connection = conn.cursor()
33- connection.execute(sqlite_query)
34- bookmarks = connection.fetchall()
35- connection.close()
36- except:
37- pass
38+ if '.' in folder:
39+ firefox_dbfiles.append(path + folder + "/places.sqlite")
40+
41+ for dbfile in firefox_dbfiles:
42+ if os.path.exists(dbfile):
43+ try:
44+ filename = dbfile.replace('/places.sqlite', '')
45+ file_name, profile_name = os.path.splitext(filename)
46+ profile_name = profile_name[1:]
47+ sqlite_query = '''SELECT moz_bookmarks.title, moz_places.url, moz_favicons.url, '%s'
48+ FROM moz_bookmarks, moz_places, moz_favicons
49+ WHERE moz_places.id = moz_bookmarks.fk
50+ AND moz_places.favicon_id = moz_favicons.id
51+ AND moz_bookmarks.title is not null
52+ AND moz_places.favicon_id is not null
53+ AND moz_bookmarks.type = 1
54+ ORDER BY moz_bookmarks.lastModified;''' % profile_name
55+
56+ conn = sqlite3.connect(dbfile)
57+ connection = conn.cursor()
58+ connection.execute(sqlite_query)
59+ profile_bookmarks = connection.fetchall()
60+ for bookmark in profile_bookmarks:
61+ bookmarks.append(bookmark)
62+ connection.close()
63+ except sqlite3.DatabaseError:
64+ pass
65 return bookmarks
66
67
68@@ -106,7 +112,8 @@
69 'icon': icon,
70 'category': 0,
71 'title': bookmark[0],
72- 'comment': bookmark[1]})
73+ 'comment': bookmark[1],
74+ 'user':GLib.Variant('s', bookmark[3])})
75 continue
76
77 # Search bookmark urls for matches
78@@ -115,7 +122,8 @@
79 'icon': icon,
80 'category': 0,
81 'title': bookmark[0],
82- 'comment': bookmark[1]})
83+ 'comment': bookmark[1],
84+ 'user':GLib.Variant('s', bookmark[3])})
85 return results
86
87

Subscribers

People subscribed via source and target branches

to all changes: