Merge lp:~jelmer/bzr-dbus/zeitgeist into lp:bzr-dbus

Proposed by Jelmer Vernooij
Status: Merged
Merged at revision: not available
Proposed branch: lp:~jelmer/bzr-dbus/zeitgeist
Merge into: lp:bzr-dbus
Prerequisite: lp:~jelmer/bzr-dbus/lazy
Diff against target: 99 lines (+65/-4)
2 files modified
__init__.py (+1/-1)
hook.py (+64/-3)
To merge this branch: bzr merge lp:~jelmer/bzr-dbus/zeitgeist
Reviewer Review Type Date Requested Status
Robert Collins (community) Needs Fixing
Review via email: mp+19120@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

This adds support for providing events to zeitgeist to the dbus plugin. Talking to zeitgeist is done through a small Python wrapper around the dbus Python module, but that python module should always be installed when zeitgeist itself is installed.

This allows showing bzr commits in gnome-activity-journal.

It's based on Markus Korn's initial plugin that is living in a separate Bazaar branch, but is not packaged. He is fine with moving this code into bzr-dbus.

Revision history for this message
Robert Collins (lifeless) wrote :

bzr-dbus is part of the canonical maintained plugins for bzr, so it needs copyright assignment.

I don't see that you need the commit hook, as bzr-dbus is already connected to tip changes, which all commits are. I'd like you to have a look at that ;).

Other than that conceptually sure its fine to have this live in -dbus.

review: Needs Fixing
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

> bzr-dbus is part of the canonical maintained plugins for bzr, so it needs
> copyright assignment.
>
> I don't see that you need the commit hook, as bzr-dbus is already connected to
> tip changes, which all commits are. I'd like you to have a look at that ;).
>
> Other than that conceptually sure its fine to have this live in -dbus.
I've updated the copyright - Markus told me he's already signed the contributor assignment.

I think we should just support notifications of commits that were made by the local user for now and possibly supporti the notification of pull/push on branches later on

Revision history for this message
Robert Collins (lifeless) wrote :

On Thu, 2010-02-18 at 02:38 +0000, Jelmer Vernooij wrote:
> > bzr-dbus is part of the canonical maintained plugins for bzr, so it needs
> > copyright assignment.
> >
> > I don't see that you need the commit hook, as bzr-dbus is already connected to
> > tip changes, which all commits are. I'd like you to have a look at that ;).
> >
> > Other than that conceptually sure its fine to have this live in -dbus.
> I've updated the copyright - Markus told me he's already signed the contributor assignment.
>
> I think we should just support notifications of commits that were made by the local user for now and possibly supporti the notification of pull/push on branches later on

I'd really rather not have duplicate code in the codebase, and it sure
looks like that is what it is at the moment.

Have you tried just logging what it grabs with the current hook - you
might like it!

-Rob

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

On Thu, 2010-02-18 at 02:54 +0000, Robert Collins wrote:
> On Thu, 2010-02-18 at 02:38 +0000, Jelmer Vernooij wrote:
> > > bzr-dbus is part of the canonical maintained plugins for bzr, so it needs
> > > copyright assignment.
> > >
> > > I don't see that you need the commit hook, as bzr-dbus is already connected to
> > > tip changes, which all commits are. I'd like you to have a look at that ;).
> > >
> > > Other than that conceptually sure its fine to have this live in -dbus.
> > I've updated the copyright - Markus told me he's already signed the contributor assignment.
> >
> > I think we should just support notifications of commits that were made by the local user for now and possibly supporti the notification of pull/push on branches later on
>
> I'd really rather not have duplicate code in the codebase, and it sure
> looks like that is what it is at the moment.
>
> Have you tried just logging what it grabs with the current hook - you
> might like it!
The 'duplication' is an extra hook, one line for the registration and
one line for the actual hook.

The alternative is filtering out commits in the current hook and only
calling the zeitgeist code in that case - that's still one or two lines
of code.

Using the post_branch_change_tip hook logs waaay too much data and
delutes gnome-activity-journal significantly at least for me, but I do a
lot of pulls.

Cheers,

Jelmer

Revision history for this message
Robert Collins (lifeless) wrote :

If you've actually tried it [branch tip change] and didn't like it, then
merging the post commit hook is fine. Please open a bug to make more
capturing possible.

-Rob

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '__init__.py'
2--- __init__.py 2010-02-10 13:03:00 +0000
3+++ __init__.py 2010-02-18 02:34:09 +0000
4@@ -66,7 +66,7 @@
5
6 from bzrlib import commands
7
8-from hook import install_hooks
9+from bzrlib.plugins.dbus.hook import install_hooks
10
11
12 def test_suite():
13
14=== modified file 'hook.py'
15--- hook.py 2010-02-16 21:40:36 +0000
16+++ hook.py 2010-02-18 02:34:09 +0000
17@@ -1,7 +1,8 @@
18 # bzr-dbus: dbus support for bzr/bzrlib.
19-# Copyright (C) 2007 Canonical Limited.
20-# Author: Robert Collins.
21-#
22+# Copyright (C) 2007,2009 Canonical Limited.
23+# Author: Robert Collins
24+# Author: Markus Korn (zeitgeist support)
25+#
26 # This program is free software; you can redistribute it and/or modify
27 # it under the terms of the GNU General Public License as published by
28 # the Free Software Foundation; version 2 of the License.
29@@ -27,6 +28,9 @@
30 Branch.hooks.install_named_hook(
31 'post_change_branch_tip', on_post_change_branch_tip,
32 'Announcing on branch change on D-Bus')
33+ Branch.hooks.install_named_hook(
34+ 'post_commit', on_post_commit,
35+ 'Zeitgeist dataprovider')
36 SmartTCPServer.hooks.install_named_hook(
37 'server_started', on_server_start,
38 'Registering server URL mapping')
39@@ -68,3 +72,60 @@
40 return
41 for local_url in local_urls:
42 activity.remove_url_map(local_url, public_url)
43+
44+
45+_checked_zeitgeist_client = False
46+_zeitgeist_client = None
47+
48+
49+def get_zeitgeist_client():
50+ global _zeitgeist_client, _checked_zeitgeist_client
51+ if _checked_zeitgeist_client:
52+ return _zeitgeist_client
53+ _checked_zeitgeist_client = True
54+ from bzrlib import trace
55+ try:
56+ from zeitgeist.client import ZeitgeistClient
57+ except ImportError, e:
58+ trace.mutter("Zeitgeist not present: %s" % e)
59+ return None
60+ try:
61+ _zeitgeist_client = ZeitgeistClient()
62+ except RuntimeError, e:
63+ trace.warn("Unable to connect to Zeitgeist, won't send events."
64+ "Reason: '%s'" % e)
65+ return None
66+ else:
67+ return _zeitgeist_client
68+
69+
70+def on_post_commit(local, master, old_revno, old_revid, new_revno, new_revid):
71+ """A commit was done. Inform zeitgeist if possible."""
72+ client = get_zeitgeist_client()
73+ if client is None:
74+ return
75+ import time
76+ from zeitgeist.datamodel import (Event, Subject, Interpretation,
77+ Manifestation)
78+ revision = master.repository.get_revision(new_revid)
79+ if new_revno == 1:
80+ interpretation = Interpretation.CREATE_EVENT
81+ else:
82+ interpretation = Interpretation.MODIFY_EVENT
83+ subject = Subject.new_for_values(
84+ uri=unicode(master.base),
85+ interpretation=unicode(Interpretation.SOURCECODE),
86+ manifestation=unicode(Manifestation.FILE),
87+ text=unicode(revision.message),
88+ origin=unicode(master.base),
89+ )
90+ event = Event.new_for_values(
91+ timestamp=int(time.time()*1000),
92+ interpretation=unicode(interpretation),
93+ manifestation=unicode(Manifestation.USER_ACTIVITY),
94+ actor="application://bzr.desktop", #something usefull here, always olive-gtk?
95+ subjects=[subject,]
96+ )
97+ client.insert_event(event)
98+
99+

Subscribers

People subscribed via source and target branches