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

Proposed by Jelmer Vernooij
Status: Merged
Merged at revision: 173
Proposed branch: lp:~jelmer/zeitgeist-datasources/bzr-plugin-improvements
Merge into: lp:zeitgeist-datasources/0.8
Diff against target: 268 lines (+157/-99)
2 files modified
bzr/__init__.py (+13/-99)
bzr/hooks.py (+144/-0)
To merge this branch: bzr merge lp:~jelmer/zeitgeist-datasources/bzr-plugin-improvements
Reviewer Review Type Date Requested Status
Seif Lotfy Needs Fixing
Manish Sinha (मनीष सिन्हा) desktop file Needs Fixing
Review via email: mp+83758@code.launchpad.net

Description of the change

Various improvements to the bzr plugin:

 * use standard functionality for pretty formatting URLs: prevents stripping off first 7 characters off non-local URLs
 * track push events
 * don't include location information in events - that data is already present in the subject
 * factor out branch

To post a comment you must log in.
Revision history for this message
Seif Lotfy (seif) wrote :
Download full text (6.3 KiB)

Dude that is awesome
Thanks alot

On Tue, Nov 29, 2011 at 12:18 PM, Jelmer Vernooij <email address hidden> wrote:

> Jelmer Vernooij has proposed merging
> lp:~jelmer/zeitgeist-datasources/bzr-plugin-improvements into
> lp:zeitgeist-datasources.
>
> Requested reviews:
> Zeitgeist Data-Sources Team (zeitgeist-dataproviders)
>
> For more details, see:
>
> https://code.launchpad.net/~jelmer/zeitgeist-datasources/bzr-plugin-improvements/+merge/83758
>
> Various improvements to the bzr plugin:
>
> * use standard functionality for pretty formatting URLs: prevents
> stripping off first 7 characters off non-local URLs
> * track push events
> * don't include location information in events - that data is already
> present in the subject
> * factor out branch
> --
>
> https://code.launchpad.net/~jelmer/zeitgeist-datasources/bzr-plugin-improvements/+merge/83758
> Your team Zeitgeist Data-Sources Team is requested to review the proposed
> merge of lp:~jelmer/zeitgeist-datasources/bzr-plugin-improvements into
> lp:zeitgeist-datasources.
>
> === modified file 'bzr/__init__.py'
> --- bzr/__init__.py 2011-08-31 13:13:33 +0000
> +++ bzr/__init__.py 2011-11-29 11:17:28 +0000
> @@ -30,10 +30,10 @@
> Copy this directory to ~/.bazaar/plugins/zeitgeist/*
> """
>
> -import time
> from bzrlib import (
> branch,
> trace,
> + urlutils,
> )
>
> _client = None
> @@ -62,35 +62,45 @@
> 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, Subject, Interpretation,
> Manifestation
> + 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 = _("Commited on: ")
> - _text += master.base[7:-1] #don't considere file://
> - _text += _(" Revision no. : ")
> + _text = _(" Revision no. : ")
> _text += str(new_revno) + "\n"
> _text += revision.message.rstrip()
>
> - subject = Subject.new_for_values(
> - uri=unicode(master.base),
> - interpretation=unicode(Interpretation.FOLDER),
> - manifestation=unicode(Manifestation.FILE_DATA_OBJECT),
> - text=unicode(_text),
> - origin=unicode(master.base),
> - )
> + subject = subject_for_branch(...

Read more...

162. By Jelmer Vernooij

m

163. By Jelmer Vernooij

Cope with some repository formats not supporting .get_revisions().

164. By Jelmer Vernooij

Lazily load hooks.

165. By Jelmer Vernooij

Use absolute imports.

Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

I had to do some more changes

1) branch.Branch.hooks.install_lazy_named_hook does not exist.
Changed it to branch.Branch.hooks.install_lazy_named_hook

2) hooks.py was not added to Makefile.am

Rest everything is fine

review: Approve
Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

Another thing I noticed is that bzr.desktop does not exist. I could only find
bzr-explorer.desktop
bzr-handle-patch.desktop
bzr-notify.desktop

$ dpkg -S /usr/share/applications/bzr-*
bzr-explorer: /usr/share/applications/bzr-explorer.desktop
bzr-gtk: /usr/share/applications/bzr-handle-patch.desktop
bzr-gtk: /usr/share/applications/bzr-notify.desktop

So shall the datasource install the .desktop file?

Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

I have made some changed which includes the ones I mentioned above and also changed post_pull to use WORLD_ACTIVITY instead of USER_ACTIVITY and bzr.desktop to bzr-notify.desktop

Should we add bzr.desktop file with the datasource of prefer to use the ones already present?

review: Needs Fixing (desktop file)
Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Hi Manish,

Thanks for those fixes. I think they're all good with the exception of the change from bzr.desktop to bzr-notify.desktop. bzr-notify is a tool that just displays notification windows, it's not an appropriate tool for opening branches.

Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

I would prefer this datasource to ship with a desktop file which opens nautilus as Exec and path as the argument. Jelmer, your suggestion?

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

Using nautilus seems reasonable to me too.

Revision history for this message
Michal Hruby (mhr3) wrote :

> I would prefer this datasource to ship with a desktop file which opens
> nautilus as Exec and path as the argument. Jelmer, your suggestion?

What if nautilus is not installed?

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

> > I would prefer this datasource to ship with a desktop file which opens
> > nautilus as Exec and path as the argument. Jelmer, your suggestion?
> What if nautilus is not installed?
Isn't that an issue with all of the actors? bzr-notify also isn't necessarily installed.

Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

> What if nautilus is not installed?

We can't fix all the situations.

Other option would be to make nautilus a hard dependency of this datasource. I don't think that would be good.

Revision history for this message
Michal Hruby (mhr3) wrote :

> > > I would prefer this datasource to ship with a desktop file which opens
> > > nautilus as Exec and path as the argument. Jelmer, your suggestion?
> > What if nautilus is not installed?
> Isn't that an issue with all of the actors? bzr-notify also isn't necessarily
> installed.

My point was that such resolution doesn't actually solve anything, and arguably shipping an "invalid" desktop file is worse than having an actor that's not a real desktop file.

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

Right, ideally we wouldn't be setting an actor at all because the actor is unknown. It's something that just happens to be using bzrlib.

Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

I made some changes which are in
lp:~manishsinha/zeitgeist-datasources/bzr-plugin-improvements-manish

In this, I have created a bzr-logger.desktop file along with bzr-logger-icon-64.png
The actor is set as bzr-logger.desktop and the desktop file contains

Name=Bazaar Logger
Comment=Logs bazaar activities
Exec=nautilus %U
Icon=bzr-logger-icon-64.png

This looks like the best compromise from all ends. It shows up as Bazaar icon and when you click on it (say from GAJ) it will open that folder using nautilus which contains the files for that branch

Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

Right now our bazaar datasource logs are not being used apart from GAJ (which is broken half of the time). I have a plan in mind to use the logs to create a dashboard kind of application. That was the reason I needed the revision number to be stored somewhere (now it is stored in text filed) and also the mimetype and actor fields.

Creating our own desktop and pixmap file is the only way to fill the actor field without introducing a new dependency on a bigger (not installed) application like bzr-gtk or bzr-explorer.

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

On Wed, Mar 21, 2012 at 07:55:20PM -0000, Manish Sinha (मनीष सिन्हा) wrote:
> I made some changes which are in
> lp:~manishsinha/zeitgeist-datasources/bzr-plugin-improvements-manish
>
> In this, I have created a bzr-logger.desktop file along with bzr-logger-icon-64.png
> The actor is set as bzr-logger.desktop and the desktop file contains
>
> Name=Bazaar Logger
> Comment=Logs bazaar activities
> Exec=nautilus %U
> Icon=bzr-logger-icon-64.png
>
> This looks like the best compromise from all ends. It shows up as Bazaar icon and when you click on it (say from GAJ) it will open that folder using nautilus which contains the files for that branch
This seems a bit odd - nautilus doesn't actually display or record bzr activities.

Isn't actor supposed to be the application that actually was
responsible for the event, rather than some application for viewing it?

Would it be an option to just not set an actor at all?

Cheers,

Jelmer

Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

It can be a way to not set the actor at all, but how will be find out that it is bazaar event?

Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

My desktop thing was a workaround to make the events more usable for applications esp GAJ. Without that GAJ and other applications have to do more work on their side to display events

Revision history for this message
Seif Lotfy (seif) wrote :

OK so here is my issue. It looks great however please fix subject_for_branch

You should return a list of subjects
the first subject being the folder and then another subject for each of the files that were edited or created

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

Am 21/03/12 23:40, schrieb Seif Lotfy:
> Review: Needs Fixing
>
> OK so here is my issue. It looks great however please fix subject_for_branch
>
> You should return a list of subjects
> the first subject being the folder and then another subject for each of the files that were edited or created
For the commit hook, I think that the only subject really is the branch
(not even the working tree). The files that are committed aren't being
changed themselves. Or am I misunderstanding the data model?

For push/pull/merge/update operations we are changing the working tree
so it does indeed make sense to take those items as subjects too.

Cheers,

Jelmer

Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

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 2011-08-31 13:13:33 +0000
3+++ bzr/__init__.py 2011-12-19 21:02:23 +0000
4@@ -30,102 +30,16 @@
5 Copy this directory to ~/.bazaar/plugins/zeitgeist/*
6 """
7
8-import time
9-from bzrlib import (
10- branch,
11- trace,
12- )
13-
14-_client = None
15-_client_checked = None
16-
17-def get_client():
18- global _client_checked, _client
19- if _client_checked:
20- return _client
21- _client_checked = True
22- try:
23- from zeitgeist.client import ZeitgeistClient
24- except ImportError:
25- _client = None
26- return _client
27- import dbus
28- try:
29- _client = ZeitgeistClient()
30- except dbus.DBusException, e:
31- trace.warning("zeitgeist: %s. No events will be sent." % e.message)
32- _client = None
33- except Exception, e:
34- trace.warning("Unable to connect to Zeitgeist, won't send events. "
35- "Reason: '%s'" % e)
36- _client = None
37- return _client
38-
39-
40-def post_commit(local, master, old_revno, old_revid, new_revno, new_revid):
41- client = get_client()
42- if client is None:
43- return
44- from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation
45- revision = master.repository.get_revision(new_revid)
46- if new_revno == 1:
47- interpretation = Interpretation.CREATE_EVENT
48- else:
49- interpretation = Interpretation.MODIFY_EVENT
50- _text = _("Commited on: ")
51- _text += master.base[7:-1] #don't considere file://
52- _text += _(" Revision no. : ")
53- _text += str(new_revno) + "\n"
54- _text += revision.message.rstrip()
55-
56- subject = Subject.new_for_values(
57- uri=unicode(master.base),
58- interpretation=unicode(Interpretation.FOLDER),
59- manifestation=unicode(Manifestation.FILE_DATA_OBJECT),
60- text=unicode(_text),
61- origin=unicode(master.base),
62- )
63- event = Event.new_for_values(
64- timestamp=int(time.time()*1000),
65- interpretation=unicode(interpretation),
66- manifestation=unicode(Manifestation.USER_ACTIVITY),
67- actor="application://bzr.desktop", #something usefull here, always olive-gtk?
68- subjects=[subject,]
69- )
70- client.insert_event(event)
71-
72-
73-def post_pull(pull_result):
74- client = get_client()
75- if client is None:
76- return
77- from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation
78- master = pull_result.master_branch
79- revision = master.repository.get_revision(pull_result.new_revid)
80- interpretation = Interpretation.RECEIVE_EVENT
81- _text = _("Pulled ")
82- _text += master.base[7:-1] #don't considere file://
83- _text += (" to revision ")
84- _text += str(master.revno())+":\n"
85- _text += revision.get_summary()
86- subject = Subject.new_for_values(
87- uri=unicode(master.base),
88- interpretation=unicode(Interpretation.FOLDER),
89- manifestation=unicode(Manifestation.FILE_DATA_OBJECT),
90- text=unicode(_text),
91- origin=unicode(master.base),
92- )
93- event = Event.new_for_values(
94- timestamp=int(time.time()*1000),
95- interpretation=unicode(interpretation),
96- manifestation=unicode(Manifestation.USER_ACTIVITY),
97- actor="application://bzr.desktop", #something usefull here, always olive-gtk?
98- subjects=[subject,]
99- )
100- client.insert_event(event)
101-
102-
103-branch.Branch.hooks.install_named_hook("post_commit", post_commit,
104- "Zeitgeist dataprovider for bzr")
105-branch.Branch.hooks.install_named_hook("post_pull", post_pull,
106- "Zeitgeist dataprovider for bzr")
107+from __future__ import absolute_import
108+
109+from bzrlib import branch
110+
111+branch.Branch.hooks.install_lazy_named_hook("post_commit",
112+ "bzrlib.plugins.zeitgeist.hooks", "post_commit",
113+ "Zeitgeist dataprovider for bzr")
114+branch.Branch.hooks.install_lazy_named_hook("post_pull",
115+ "bzrlib.plugins.zeitgeist.hooks", "post_pull",
116+ "Zeitgeist dataprovider for bzr")
117+branch.Branch.hooks.install_lazy_named_hook("post_push",
118+ "bzrlib.plugins.zeitgeist.hooks", "post_push",
119+ "Zeitgeist dataprovider for bzr")
120
121=== added file 'bzr/hooks.py'
122--- bzr/hooks.py 1970-01-01 00:00:00 +0000
123+++ bzr/hooks.py 2011-12-19 21:02:23 +0000
124@@ -0,0 +1,144 @@
125+# -.- coding: utf-8 -.-
126+
127+# Zeitgeist
128+#
129+# Copyright © 2009 Markus Korn <thekorn@gmx.de>
130+#
131+# This program is free software: you can redistribute it and/or modify
132+# it under the terms of the GNU Lesser General Public License as published by
133+# the Free Software Foundation, either version 3 of the License, or
134+# (at your option) any later version.
135+#
136+# This program is distributed in the hope that it will be useful,
137+# but WITHOUT ANY WARRANTY; without even the implied warranty of
138+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
139+# GNU Lesser General Public License for more details.
140+#
141+# You should have received a copy of the GNU Lesser General Public License
142+# along with this program. If not, see <http://www.gnu.org/licenses/>.
143+
144+from bzrlib import (
145+ branch,
146+ errors,
147+ trace,
148+ urlutils,
149+ )
150+
151+_client = None
152+_client_checked = None
153+
154+def get_client():
155+ global _client_checked, _client
156+ if _client_checked:
157+ return _client
158+ _client_checked = True
159+ try:
160+ from zeitgeist.client import ZeitgeistClient
161+ except ImportError:
162+ _client = None
163+ return _client
164+ import dbus
165+ try:
166+ _client = ZeitgeistClient()
167+ except dbus.DBusException, e:
168+ trace.warning("zeitgeist: %s. No events will be sent." % e.message)
169+ _client = None
170+ except Exception, e:
171+ trace.warning("Unable to connect to Zeitgeist, won't send events. "
172+ "Reason: '%s'" % e)
173+ _client = None
174+ return _client
175+
176+
177+def subject_for_branch(branch):
178+ from zeitgeist.datamodel import Subject, Interpretation, Manifestation
179+ location = urlutils.unescape_for_display(branch.base, "utf-8").decode("utf-8")
180+ return Subject.new_for_values(
181+ uri=unicode(branch.base),
182+ interpretation=unicode(Interpretation.FOLDER),
183+ manifestation=unicode(Manifestation.FILE_DATA_OBJECT),
184+ text=u"Bazaar branch at %s" % location,
185+ origin=unicode(branch.base),
186+ mimetype="application/x-bzr",
187+ )
188+
189+
190+def get_actor():
191+ # FIXME: Allow overriding this by e.g. qbzr and bzr-gtk
192+ return u"application://bzr.desktop"
193+
194+
195+def post_commit(local, master, old_revno, old_revid, new_revno, new_revid):
196+ client = get_client()
197+ if client is None:
198+ return
199+ from zeitgeist.datamodel import Event, Interpretation, Manifestation
200+ revision = master.repository.get_revision(new_revid)
201+ if new_revno == 1:
202+ interpretation = Interpretation.CREATE_EVENT
203+ else:
204+ interpretation = Interpretation.MODIFY_EVENT
205+ _text = _(" Revision no. : ")
206+ _text += str(new_revno) + "\n"
207+ _text += revision.message.rstrip()
208+
209+ subject = subject_for_branch(master)
210+ event = Event.new_for_values(
211+ timestamp=int(revision.timestamp*1000),
212+ interpretation=unicode(interpretation),
213+ manifestation=unicode(Manifestation.USER_ACTIVITY),
214+ actor=get_actor(),
215+ subjects=[subject,],
216+ )
217+ client.insert_event(event)
218+
219+
220+def post_pull(pull_result):
221+ client = get_client()
222+ if client is None:
223+ return
224+ from zeitgeist.datamodel import Event, Interpretation, Manifestation
225+ try:
226+ revision = pull_result.master_branch.repository.get_revision(
227+ pull_result.new_revid)
228+ except errors.UnsupportedOperation:
229+ # Some remote repository formats (e.g. git) don't support looking at invidual
230+ # revisions
231+ revision = pull_result.source_branch.repository.get_revision(
232+ pull_result.new_revid)
233+ _text = _("Pulled to revision %s:\n %s") % (pull_result.new_revno,
234+ revision.get_summary())
235+ subject = subject_for_branch(pull_result.master_branch)
236+ event = Event.new_for_values(
237+ interpretation=unicode(Interpretation.RECEIVE_EVENT),
238+ manifestation=unicode(Manifestation.USER_ACTIVITY),
239+ actor=get_actor(),
240+ subjects=[subject,]
241+ )
242+ client.insert_event(event)
243+
244+
245+def post_push(push_result):
246+ client = get_client()
247+ if client is None:
248+ return
249+ from zeitgeist.datamodel import Event, Interpretation, Manifestation
250+ try:
251+ revision = push_result.master_branch.repository.get_revision(
252+ push_result.new_revid)
253+ except errors.UnsupportedOperation:
254+ revision = push_result.source_branch.repository.get_revision(
255+ push_result.new_revid)
256+ _text = _("Pushed to revision %s:\n %s") % (push_result.new_revno,
257+ revision.get_summary())
258+ subject = subject_for_branch(push_result.master_branch)
259+ event = Event.new_for_values(
260+ interpretation=unicode(Interpretation.SEND_EVENT),
261+ manifestation=unicode(Manifestation.USER_ACTIVITY),
262+ actor=get_actor(),
263+ subjects=[subject,]
264+ )
265+ client.insert_event(event)
266+
267+
268+

Subscribers

People subscribed via source and target branches