Merge lp:~jelmer/zeitgeist-datasources/lazy-bzr into lp:zeitgeist-datasources/0.8

Proposed by Jelmer Vernooij
Status: Merged
Merged at revision: 160
Proposed branch: lp:~jelmer/zeitgeist-datasources/lazy-bzr
Merge into: lp:zeitgeist-datasources/0.8
Diff against target: 107 lines (+47/-27)
1 file modified
bzr/__init__.py (+47/-27)
To merge this branch: bzr merge lp:~jelmer/zeitgeist-datasources/lazy-bzr
Reviewer Review Type Date Requested Status
Manish Sinha (मनीष सिन्हा) Approve
Review via email: mp+73524@code.launchpad.net

Description of the change

Modify bzr plugin to only load zeitgeist when it is actually being used, and to use bzr's infrastructure for printing warnings.

This helps with the startup time overhead of bzr.

To post a comment you must log in.
Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

Approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzr/__init__.py'
2--- bzr/__init__.py 2010-11-01 16:32:39 +0000
3+++ bzr/__init__.py 2011-08-31 13:18:22 +0000
4@@ -23,6 +23,7 @@
5
6 Copyright (C) 2009, Markus Korn <thekorn@gmx.de>
7 Copyright (C) 2010, Stefano Candori <stefano.candori@gmail.com>
8+Copyright (C) 2011, Jelmer Vernooij <jelmer@samba.org>
9 Published under the GNU GPLv2 or later
10
11 Installation:
12@@ -30,28 +31,42 @@
13 """
14
15 import time
16-import logging
17-from bzrlib import branch
18-
19-logging.basicConfig(filename="/dev/null")
20-
21-install_hook = True
22-CLIENT = None
23-
24-try:
25- from zeitgeist.client import ZeitgeistClient
26- from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation
27-except ImportError:
28- install_hook = False
29-else:
30- try:
31- CLIENT = ZeitgeistClient()
32- except RuntimeError, e:
33- print "Unable to connect to Zeitgeist, won't send events. Reason: '%s'" %e
34- install_hook = False
35+from bzrlib import (
36+ branch,
37+ trace,
38+ )
39+
40+_client = None
41+_client_checked = None
42+
43+def get_client():
44+ global _client_checked, _client
45+ if _client_checked:
46+ return _client
47+ _client_checked = True
48+ try:
49+ from zeitgeist.client import ZeitgeistClient
50+ except ImportError:
51+ _client = None
52+ return _client
53+ import dbus
54+ try:
55+ _client = ZeitgeistClient()
56+ except dbus.DBusException, e:
57+ trace.warning("zeitgeist: %s. No events will be sent." % e.message)
58+ _client = None
59+ except Exception, e:
60+ trace.warning("Unable to connect to Zeitgeist, won't send events. "
61+ "Reason: '%s'" % e)
62+ _client = None
63+ return _client
64
65
66 def post_commit(local, master, old_revno, old_revid, new_revno, new_revid):
67+ client = get_client()
68+ if client is None:
69+ return
70+ from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation
71 revision = master.repository.get_revision(new_revid)
72 if new_revno == 1:
73 interpretation = Interpretation.CREATE_EVENT
74@@ -77,9 +92,14 @@
75 actor="application://bzr.desktop", #something usefull here, always olive-gtk?
76 subjects=[subject,]
77 )
78- CLIENT.insert_event(event)
79+ client.insert_event(event)
80+
81
82 def post_pull(pull_result):
83+ client = get_client()
84+ if client is None:
85+ return
86+ from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation
87 master = pull_result.master_branch
88 revision = master.repository.get_revision(pull_result.new_revid)
89 interpretation = Interpretation.RECEIVE_EVENT
90@@ -102,10 +122,10 @@
91 actor="application://bzr.desktop", #something usefull here, always olive-gtk?
92 subjects=[subject,]
93 )
94- CLIENT.insert_event(event)
95-
96-if install_hook:
97- branch.Branch.hooks.install_named_hook("post_commit", post_commit,
98- "Zeitgeist dataprovider for bzr")
99- branch.Branch.hooks.install_named_hook("post_pull", post_pull,
100- "Zeitgeist dataprovider for bzr")
101+ client.insert_event(event)
102+
103+
104+branch.Branch.hooks.install_named_hook("post_commit", post_commit,
105+ "Zeitgeist dataprovider for bzr")
106+branch.Branch.hooks.install_named_hook("post_pull", post_pull,
107+ "Zeitgeist dataprovider for bzr")

Subscribers

People subscribed via source and target branches