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
=== modified file '__init__.py'
--- __init__.py 2010-02-10 13:03:00 +0000
+++ __init__.py 2010-02-18 02:34:09 +0000
@@ -66,7 +66,7 @@
6666
67from bzrlib import commands67from bzrlib import commands
6868
69from hook import install_hooks69from bzrlib.plugins.dbus.hook import install_hooks
7070
7171
72def test_suite():72def test_suite():
7373
=== modified file 'hook.py'
--- hook.py 2010-02-16 21:40:36 +0000
+++ hook.py 2010-02-18 02:34:09 +0000
@@ -1,7 +1,8 @@
1# bzr-dbus: dbus support for bzr/bzrlib.1# bzr-dbus: dbus support for bzr/bzrlib.
2# Copyright (C) 2007 Canonical Limited.2# Copyright (C) 2007,2009 Canonical Limited.
3# Author: Robert Collins.3# Author: Robert Collins
4# 4# Author: Markus Korn (zeitgeist support)
5#
5# This program is free software; you can redistribute it and/or modify6# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by7# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; version 2 of the License.8# the Free Software Foundation; version 2 of the License.
@@ -27,6 +28,9 @@
27 Branch.hooks.install_named_hook(28 Branch.hooks.install_named_hook(
28 'post_change_branch_tip', on_post_change_branch_tip,29 'post_change_branch_tip', on_post_change_branch_tip,
29 'Announcing on branch change on D-Bus')30 'Announcing on branch change on D-Bus')
31 Branch.hooks.install_named_hook(
32 'post_commit', on_post_commit,
33 'Zeitgeist dataprovider')
30 SmartTCPServer.hooks.install_named_hook(34 SmartTCPServer.hooks.install_named_hook(
31 'server_started', on_server_start,35 'server_started', on_server_start,
32 'Registering server URL mapping')36 'Registering server URL mapping')
@@ -68,3 +72,60 @@
68 return72 return
69 for local_url in local_urls:73 for local_url in local_urls:
70 activity.remove_url_map(local_url, public_url)74 activity.remove_url_map(local_url, public_url)
75
76
77_checked_zeitgeist_client = False
78_zeitgeist_client = None
79
80
81def get_zeitgeist_client():
82 global _zeitgeist_client, _checked_zeitgeist_client
83 if _checked_zeitgeist_client:
84 return _zeitgeist_client
85 _checked_zeitgeist_client = True
86 from bzrlib import trace
87 try:
88 from zeitgeist.client import ZeitgeistClient
89 except ImportError, e:
90 trace.mutter("Zeitgeist not present: %s" % e)
91 return None
92 try:
93 _zeitgeist_client = ZeitgeistClient()
94 except RuntimeError, e:
95 trace.warn("Unable to connect to Zeitgeist, won't send events."
96 "Reason: '%s'" % e)
97 return None
98 else:
99 return _zeitgeist_client
100
101
102def on_post_commit(local, master, old_revno, old_revid, new_revno, new_revid):
103 """A commit was done. Inform zeitgeist if possible."""
104 client = get_zeitgeist_client()
105 if client is None:
106 return
107 import time
108 from zeitgeist.datamodel import (Event, Subject, Interpretation,
109 Manifestation)
110 revision = master.repository.get_revision(new_revid)
111 if new_revno == 1:
112 interpretation = Interpretation.CREATE_EVENT
113 else:
114 interpretation = Interpretation.MODIFY_EVENT
115 subject = Subject.new_for_values(
116 uri=unicode(master.base),
117 interpretation=unicode(Interpretation.SOURCECODE),
118 manifestation=unicode(Manifestation.FILE),
119 text=unicode(revision.message),
120 origin=unicode(master.base),
121 )
122 event = Event.new_for_values(
123 timestamp=int(time.time()*1000),
124 interpretation=unicode(interpretation),
125 manifestation=unicode(Manifestation.USER_ACTIVITY),
126 actor="application://bzr.desktop", #something usefull here, always olive-gtk?
127 subjects=[subject,]
128 )
129 client.insert_event(event)
130
131

Subscribers

People subscribed via source and target branches