Merge lp:~amanica/bzr-notification/with_commit_hook into lp:bzr-notification

Proposed by Marius Kruger
Status: Needs review
Proposed branch: lp:~amanica/bzr-notification/with_commit_hook
Merge into: lp:bzr-notification
Diff against target: None lines
To merge this branch: bzr merge lp:~amanica/bzr-notification/with_commit_hook
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
jhs Pending
Review via email: mp+8166@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Marius Kruger (amanica) wrote :

This adds a commit hook which shows a notification after a commit to a checkout succeeds (which can also take a while).
Other minor changes:
* I factored out a notify send method
* I changed the timeout to 9000 (we should probably make that configurable)

You are welcome to merge this as is or copy&paste any parts of it you like.

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

This looks ok to me, though I'm not a committer on bzr-notification. It does seem strictly redundant on the bzr-dbus+bzr-gtk notifications though.

review: Approve

Unmerged revisions

14. By Marius Kruger

* add post_commit_hook which shows a notification after a commit to a checkout succeeds.
* rather pass the branch base to notify_send so we can factor out more formatting.

13. By Marius Kruger

factor out notify_send function

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 2008-05-14 06:15:18 +0000
3+++ __init__.py 2009-07-03 00:11:04 +0000
4@@ -5,7 +5,16 @@
5 """GUI Notification plugin for bzr"""
6
7 import os
8-from bzrlib import branch
9+from bzrlib import branch, errors
10+
11+
12+cmd = 'notify-send --expire-time=9000 --icon=gtk-network --category=transfer'
13+
14+
15+def notify_send(summary, base, message):
16+ body = '%s (%s)' % (base, message)
17+ os.system('%s "%s" "%s"' % (cmd, summary, body))
18+
19
20 def post_push_hook(push_result):
21 old = push_result.old_revno
22@@ -16,11 +25,9 @@
23 else:
24 message = '%d to %d' % (old, new)
25
26- cmd = 'notify-send --expire-time=3000 --icon=gtk-network'
27 summary = 'Bzr Push'
28- body = '%s (%s)' % (push_result.target_branch.base, message)
29+ notify_send(summary, push_result.target_branch.base, message)
30
31- os.system('%s "%s" "%s"' % (cmd, summary, body))
32
33 def post_pull_hook(pull_result):
34 old = pull_result.old_revno
35@@ -31,22 +38,34 @@
36 else:
37 message = '%d to %d' % (old, new)
38
39- cmd = 'notify-send --expire-time=3000 --icon=gtk-network'
40 summary = 'Bzr Pull'
41- body = '%s (%s)' % (pull_result.source_branch.base, message)
42-
43- os.system('%s "%s" "%s"' % (cmd, summary, body))
44+ notify_send(summary, pull_result.source_branch.base, message)
45+
46+
47+def post_commit_hook(local, master, old_revno, old_revid, new_revno,
48+ new_revid):
49+ #only notify when we have a local branch
50+ if local:
51+ summary = 'Bzr Commit'
52+ message = 'New revno %d' % new_revno
53+ notify_send(summary, local.base, message)
54+
55
56 def install_named_hook_compat(hook_symbol, hook_callback, hook_name):
57 """Implements the bzr 1.5 interface for compatibility with lesser versions."""
58 branch.Branch.hooks.install_hook(hook_symbol, hook_callback)
59 branch.Branch.hooks.name_hook(hook_callback, hook_name)
60
61+
62 install_named_hook = getattr(branch.Branch.hooks, 'install_named_hook', install_named_hook_compat)
63
64+
65 try:
66 install_named_hook('post_push', post_push_hook, 'Notification post push hook')
67 install_named_hook('post_pull', post_pull_hook, 'Notification post pull hook')
68+ install_named_hook('post_commit', post_commit_hook,
69+ 'Notification post commit hook')
70 except errors.UnknownHook:
71 # Doesn't work with this old version of bzr
72 pass
73+

Subscribers

People subscribed via source and target branches

to all changes: