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

Subscribers

People subscribed via source and target branches