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

Subscribers

People subscribed via source and target branches

to all changes: