Merge lp:~severinh/gnome-zeitgeist/firefox_profiles_fix into lp:gnome-zeitgeist

Proposed by Severin Heiniger
Status: Merged
Merged at revision: not available
Proposed branch: lp:~severinh/gnome-zeitgeist/firefox_profiles_fix
Merge into: lp:gnome-zeitgeist
Diff against target: None lines
To merge this branch: bzr merge lp:~severinh/gnome-zeitgeist/firefox_profiles_fix
Reviewer Review Type Date Requested Status
Seif Lotfy Approve
Review via email: mp+6428@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Severin Heiniger (severinh) wrote :

This branch features a fix for bug #374918 as well as a minor cleanup in zeitgeist_firefox.py.

Revision history for this message
Severin Heiniger (severinh) wrote :

I guess I don't need to tell you that it would be wise to give the branch a try before merging it into main. ;-)

565. By Severin Heiniger

zeitgeist_firefox.py:

Typo in get_profile_dirs fixed.

Don't crash if no Firefox profile can be found.

Revision history for this message
Seif Lotfy (seif) wrote :

Ok i tested it and it looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/zeitgeist_engine/zeitgeist_firefox.py'
2--- src/zeitgeist_engine/zeitgeist_firefox.py 2009-05-10 18:55:04 +0000
3+++ src/zeitgeist_engine/zeitgeist_firefox.py 2009-05-11 15:54:30 +0000
4@@ -1,38 +1,49 @@
5 # -.- encoding: utf-8 -.-
6
7-import os
8-import glob
9 import shutil
10 import sqlite3 as db
11 import gettext
12
13+from os.path import join, expanduser, isfile
14+from ConfigParser import ConfigParser, NoOptionError
15+
16 from zeitgeist_engine.zeitgeist_util import FileMonitor
17 from zeitgeist_engine.zeitgeist_base import DataProvider
18
19-
20 class FirefoxSource(DataProvider):
21+ FIREFOX_DIR = expanduser("~/.mozilla/firefox")
22+ PROFILE_FILE = join(FIREFOX_DIR, "profiles.ini")
23+ LOCATION = expanduser("~/.zeitgeist/firefox.sqlite")
24
25- def __init__(self, name="Firefox History", icon="gnome-globe", uri="gzg/firefox"):
26-
27- DataProvider.__init__(self, name=name, icon=icon, uri = uri)
28- self.name = "Firefox History"
29- self.icon="gnome-globe"
30- self.type = self.name
31- self.comment = "websites visited with Firefox"
32-
33- self.historydb = glob.glob(os.path.expanduser("~/.mozilla/firefox/*/places.sqlite"))
34-
35- # TODO: Be more sensible about: a) old profiles being present
36- # (look at profiles.ini to find the correct one), and b) more
37- # than one Firefox version being used (eg., current and alpha).
38+ def __init__(self):
39+ DataProvider.__init__(self,
40+ name=_(u"Firefox History"),
41+ icon="gnome-globe",
42+ uri="gzg/firefox",
43+ comment=_(u"Websites visited with Firefox"))
44+
45+ self.type = "Firefox History"
46+
47+ # Holds a list of all places.sqlite files. The file that belongs to the
48+ # default profile will be the at the top of the list.
49+ self.history_dbs = []
50+
51+ for profile_dir in self.get_profile_dirs():
52+ db_file = join(profile_dir, "places.sqlite")
53+
54+ # Make sure that this particular places.sqlite file exists.
55+ if isfile(db_file):
56+ self.history_dbs.append(db_file)
57+
58+ # TODO: Handle more than one Firefox profile.
59 try:
60- self.note_path_monitor = FileMonitor(self.historydb[0])
61+ self.note_path_monitor = FileMonitor(self.history_dbs[0])
62 self.note_path_monitor.connect("event", self.reload_proxy)
63 self.note_path_monitor.open()
64 except Exception:
65 print "Are you using Firefox?"
66 else:
67- print 'Reading from', self.historydb[0]
68+ print 'Reading from', self.history_dbs[0]
69
70 if not hasattr(self, "cursor"):
71 self.cursor = None
72@@ -41,10 +52,49 @@
73 else:
74 self.last_timestamp = 0.0
75
76- self.loc = os.path.expanduser("~/.zeitgeist/firefox.sqlite")
77-
78 self.__copy_sqlite()
79
80+ @classmethod
81+ def get_profile_dirs(cls):
82+ """
83+ Returns a list of all Firefox profile directories.
84+
85+ The default profile is located at the top of the list.
86+ """
87+
88+ profiles = []
89+
90+ # Parse the profiles.ini file to get the location of all Firefox
91+ # profiles.
92+ profile_parser = ConfigParser()
93+
94+ # Doesn't raise an exception if the file doesn't exist.
95+ profile_parser.read(cls.PROFILE_FILE)
96+
97+ for section in profile_parser.sections():
98+ try:
99+ is_relative = profile_parser.getboolean(section, "isRelative")
100+ path = profile_parser.get(section, "Path")
101+ except NoOptionError:
102+ # This section does not represent a profile (for example the
103+ # `General` section).
104+ pass
105+ else:
106+ try:
107+ is_default = profile_parser.getboolean(section, "Default")
108+ except (NoOptionError, ValueError):
109+ is_default = False
110+
111+ if is_relative:
112+ path = join(cls.FIREFOX_DIR, path)
113+
114+ if is_default:
115+ profiles.insert(0, path)
116+ else:
117+ profile.append(path)
118+
119+ return profiles
120+
121 def get_latest_timestamp(self):
122
123 contents = "visit_date"
124@@ -98,6 +148,6 @@
125 '''
126 if self.cursor:
127 self.cursor.close()
128- shutil.copy2(self.historydb[0], self.loc)
129- self.connection = db.connect(self.loc, True)
130+ shutil.copy2(self.history_dbs[0], self.LOCATION)
131+ self.connection = db.connect(self.LOCATION, True)
132 self.cursor = self.connection.cursor()

Subscribers

People subscribed via source and target branches