summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2011-10-27 23:45:50 +0530
committerManish Sinha <manishsinha@ubuntu.com>2011-10-27 23:45:50 +0530
commit1ff2b2bb0f3e7fa4ab8e6f7a5fda0b22255ecf5d (patch)
tree41230aee21046933e66bae5b8428998f9a4d77fe
parent397827e6a6ce09298841fdcef9ce2e1a0e22a9c0 (diff)
parent06647385086ef3a2b31d647bb61e98d7f2086b48 (diff)
Lazily load zeitgeist module in bazaar datasource
-rw-r--r--MAINTAINERS3
-rw-r--r--bzr/__init__.py66
2 files changed, 45 insertions, 24 deletions
diff --git a/MAINTAINERS b/MAINTAINERS
index ce15d58..9137279 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -14,6 +14,7 @@ Please thank our Contributers:
* Jonathan Lambrechts
* Martin Pool - mbp
* Martin Dengler
-
+* Patrick McEvoy
+* Jelmer Vernooij - jelmer
If you name is not here, please let us know
diff --git a/bzr/__init__.py b/bzr/__init__.py
index f9a6de3..0d73b16 100644
--- a/bzr/__init__.py
+++ b/bzr/__init__.py
@@ -23,6 +23,7 @@ Requires bzr 0.15 or higher.
Copyright (C) 2009, Markus Korn <thekorn@gmx.de>
Copyright (C) 2010, Stefano Candori <stefano.candori@gmail.com>
+Copyright (C) 2011, Jelmer Vernooij <jelmer@samba.org>
Published under the GNU GPLv2 or later
Installation:
@@ -30,28 +31,42 @@ Copy this directory to ~/.bazaar/plugins/zeitgeist/*
"""
import time
-import logging
-from bzrlib import branch
-
-logging.basicConfig(filename="/dev/null")
+from bzrlib import (
+ branch,
+ trace,
+ )
-install_hook = True
-CLIENT = None
+_client = None
+_client_checked = None
-try:
- from zeitgeist.client import ZeitgeistClient
- from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation
-except ImportError:
- install_hook = False
-else:
+def get_client():
+ global _client_checked, _client
+ if _client_checked:
+ return _client
+ _client_checked = True
+ try:
+ from zeitgeist.client import ZeitgeistClient
+ except ImportError:
+ _client = None
+ return _client
+ import dbus
try:
- CLIENT = ZeitgeistClient()
- except RuntimeError, e:
- print "Unable to connect to Zeitgeist, won't send events. Reason: '%s'" %e
- install_hook = False
+ _client = ZeitgeistClient()
+ except dbus.DBusException, e:
+ trace.warning("zeitgeist: %s. No events will be sent." % e.message)
+ _client = None
+ except Exception, e:
+ trace.warning("Unable to connect to Zeitgeist, won't send events. "
+ "Reason: '%s'" % e)
+ _client = None
+ return _client
def post_commit(local, master, old_revno, old_revid, new_revno, new_revid):
+ client = get_client()
+ if client is None:
+ return
+ from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation
revision = master.repository.get_revision(new_revid)
if new_revno == 1:
interpretation = Interpretation.CREATE_EVENT
@@ -77,9 +92,14 @@ def post_commit(local, master, old_revno, old_revid, new_revno, new_revid):
actor="application://bzr.desktop", #something usefull here, always olive-gtk?
subjects=[subject,]
)
- CLIENT.insert_event(event)
+ client.insert_event(event)
+
def post_pull(pull_result):
+ client = get_client()
+ if client is None:
+ return
+ from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation
master = pull_result.master_branch
revision = master.repository.get_revision(pull_result.new_revid)
interpretation = Interpretation.RECEIVE_EVENT
@@ -102,10 +122,10 @@ def post_pull(pull_result):
actor="application://bzr.desktop", #something usefull here, always olive-gtk?
subjects=[subject,]
)
- CLIENT.insert_event(event)
+ client.insert_event(event)
+
-if install_hook:
- branch.Branch.hooks.install_named_hook("post_commit", post_commit,
- "Zeitgeist dataprovider for bzr")
- branch.Branch.hooks.install_named_hook("post_pull", post_pull,
- "Zeitgeist dataprovider for bzr")
+branch.Branch.hooks.install_named_hook("post_commit", post_commit,
+ "Zeitgeist dataprovider for bzr")
+branch.Branch.hooks.install_named_hook("post_pull", post_pull,
+ "Zeitgeist dataprovider for bzr")