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
=== modified file 'src/unity_firefoxbookmarks_daemon.py'
--- src/unity_firefoxbookmarks_daemon.py 2013-03-14 12:27:56 +0000
+++ src/unity_firefoxbookmarks_daemon.py 2013-03-19 13:43:23 +0000
@@ -53,33 +53,39 @@
5353
54def get_bookmarks_from_firefox(path):54def get_bookmarks_from_firefox(path):
55 '''55 '''
56 Gets a list of bookmarks from the user's firefox profile56 Gets a list of bookmarks from the user's firefox profiles
57 '''57 '''
58 # Build Firefox's profile path58 # Build Firefox's profile paths
59 firefox_dbfile = ""59 firefox_dbfiles = []
60 bookmarks = []60 bookmarks = []
61 for folder in os.listdir(path):61 for folder in os.listdir(path):
62 if folder.endswith(".default"):62 if '.' in folder:
63 firefox_dbfile = path + folder + "/places.sqlite"63 firefox_dbfiles.append(path + folder + "/places.sqlite")
6464
65 if os.path.exists(firefox_dbfile):65 for dbfile in firefox_dbfiles:
66 try:66 if os.path.exists(dbfile):
67 sqlite_query = '''SELECT moz_bookmarks.title, moz_places.url, moz_favicons.url67 try:
68 FROM moz_bookmarks, moz_places, moz_favicons68 filename = dbfile.replace('/places.sqlite', '')
69 WHERE moz_places.id = moz_bookmarks.fk69 file_name, profile_name = os.path.splitext(filename)
70 AND moz_places.favicon_id = moz_favicons.id70 profile_name = profile_name[1:]
71 AND moz_bookmarks.title is not null71 sqlite_query = '''SELECT moz_bookmarks.title, moz_places.url, moz_favicons.url, '%s'
72 AND moz_places.favicon_id is not null72 FROM moz_bookmarks, moz_places, moz_favicons
73 AND moz_bookmarks.type = 173 WHERE moz_places.id = moz_bookmarks.fk
74 ORDER BY moz_bookmarks.lastModified;'''74 AND moz_places.favicon_id = moz_favicons.id
7575 AND moz_bookmarks.title is not null
76 conn = sqlite3.connect(firefox_dbfile)76 AND moz_places.favicon_id is not null
77 connection = conn.cursor()77 AND moz_bookmarks.type = 1
78 connection.execute(sqlite_query)78 ORDER BY moz_bookmarks.lastModified;''' % profile_name
79 bookmarks = connection.fetchall()79
80 connection.close()80 conn = sqlite3.connect(dbfile)
81 except:81 connection = conn.cursor()
82 pass82 connection.execute(sqlite_query)
83 profile_bookmarks = connection.fetchall()
84 for bookmark in profile_bookmarks:
85 bookmarks.append(bookmark)
86 connection.close()
87 except sqlite3.DatabaseError:
88 pass
83 return bookmarks89 return bookmarks
8490
8591
@@ -106,7 +112,8 @@
106 'icon': icon,112 'icon': icon,
107 'category': 0,113 'category': 0,
108 'title': bookmark[0],114 'title': bookmark[0],
109 'comment': bookmark[1]})115 'comment': bookmark[1],
116 'user':GLib.Variant('s', bookmark[3])})
110 continue117 continue
111118
112 # Search bookmark urls for matches119 # Search bookmark urls for matches
@@ -115,7 +122,8 @@
115 'icon': icon,122 'icon': icon,
116 'category': 0,123 'category': 0,
117 'title': bookmark[0],124 'title': bookmark[0],
118 'comment': bookmark[1]})125 'comment': bookmark[1],
126 'user':GLib.Variant('s', bookmark[3])})
119 return results127 return results
120128
121129

Subscribers

People subscribed via source and target branches

to all changes: