summaryrefslogtreecommitdiff
path: root/bzr/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'bzr/__init__.py')
-rw-r--r--bzr/__init__.py141
1 files changed, 11 insertions, 130 deletions
diff --git a/bzr/__init__.py b/bzr/__init__.py
index 7ede025..8b57b47 100644
--- a/bzr/__init__.py
+++ b/bzr/__init__.py
@@ -30,133 +30,14 @@ Installation:
Copy this directory to ~/.bazaar/plugins/zeitgeist/*
"""
-from bzrlib import (
- branch,
- errors,
- trace,
- urlutils,
- )
-
-_client = None
-_client_checked = None
-
-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 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 subject_for_branch(branch):
- from zeitgeist.datamodel import Subject, Interpretation, Manifestation
- location = urlutils.unescape_for_display(branch.base, "utf-8").decode("utf-8")
- return Subject.new_for_values(
- uri=unicode(branch.base),
- interpretation=unicode(Interpretation.FOLDER),
- manifestation=unicode(Manifestation.FILE_DATA_OBJECT),
- text=u"Bazaar branch at %s" % location,
- origin=unicode(branch.base),
- mimetype="application/x-bzr",
- )
-
-
-def get_actor():
- # FIXME: Allow overriding this by e.g. qbzr and bzr-gtk
- return u"application://bzr.desktop"
-
-
-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, Interpretation, Manifestation
- revision = master.repository.get_revision(new_revid)
- if new_revno == 1:
- interpretation = Interpretation.CREATE_EVENT
- else:
- interpretation = Interpretation.MODIFY_EVENT
- _text = _(" Revision no. : ")
- _text += str(new_revno) + "\n"
- _text += revision.message.rstrip()
-
- subject = subject_for_branch(master)
- event = Event.new_for_values(
- timestamp=int(revision.timestamp*1000),
- interpretation=unicode(interpretation),
- manifestation=unicode(Manifestation.USER_ACTIVITY),
- actor=get_actor(),
- subjects=[subject,],
- )
- client.insert_event(event)
-
-
-def post_pull(pull_result):
- client = get_client()
- if client is None:
- return
- from zeitgeist.datamodel import Event, Interpretation, Manifestation
- try:
- revision = pull_result.master_branch.repository.get_revision(
- pull_result.new_revid)
- except errors.UnsupportedOperation:
- # Some remote repository formats (e.g. git) don't support looking at invidual
- # revisions
- revision = pull_result.source_branch.repository.get_revision(
- pull_result.new_revid)
- _text = _("Pulled to revision %s:\n %s") % (pull_result.new_revno,
- revision.get_summary())
- subject = subject_for_branch(pull_result.master_branch)
- event = Event.new_for_values(
- interpretation=unicode(Interpretation.RECEIVE_EVENT),
- manifestation=unicode(Manifestation.USER_ACTIVITY),
- actor=get_actor(),
- subjects=[subject,]
- )
- client.insert_event(event)
-
-
-def post_push(push_result):
- client = get_client()
- if client is None:
- return
- from zeitgeist.datamodel import Event, Interpretation, Manifestation
- try:
- revision = push_result.master_branch.repository.get_revision(
- push_result.new_revid)
- except errors.UnsupportedOperation:
- revision = push_result.source_branch.repository.get_revision(
- push_result.new_revid)
- _text = _("Pushed to revision %s:\n %s") % (push_result.new_revno,
- revision.get_summary())
- subject = subject_for_branch(push_result.master_branch)
- event = Event.new_for_values(
- interpretation=unicode(Interpretation.SEND_EVENT),
- manifestation=unicode(Manifestation.USER_ACTIVITY),
- actor=get_actor(),
- subjects=[subject,]
- )
- client.insert_event(event)
-
-
-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_push", post_push,
- "Zeitgeist dataprovider for bzr")
+from bzrlib import branch
+
+branch.Branch.hooks.install_lazy_named_hook("post_commit",
+ "bzrlib.plugins.zeitgeist.hooks", "post_commit",
+ "Zeitgeist dataprovider for bzr")
+branch.Branch.hooks.install_lazy_named_hook("post_pull",
+ "bzrlib.plugins.zeitgeist.hooks", "post_pull",
+ "Zeitgeist dataprovider for bzr")
+branch.Branch.hooks.install_lazy_named_hook("post_push",
+ "bzrlib.plugins.zeitgeist.hooks", "post_push",
+ "Zeitgeist dataprovider for bzr")