/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to bzr-notify

  • Committer: Vincent Ladeuil
  • Date: 2008-06-10 15:25:47 UTC
  • mto: This revision was merged to the branch mainline in revision 504.
  • Revision ID: v.ladeuil+lp@free.fr-20080610152547-dwmil1p8pd0mfpnl
Fix third failing test (thanks to jam).

* tests/test_commit.py:
(TestPendingRevisions.test_pending_revisions_multi_merge): Fix
provided by jam: bzr we now filter the pending merges so that only
the 'heads()' are included. We just ensure that the pending merges
contain the unique tips for the ancestries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
"""Run the bzr tray icon.
4
 
 
5
 
This is a background program which will pop up a notification on the users
6
 
screen when a commit occurs.
7
 
"""
8
 
 
9
 
from bzrlib.plugin import load_plugins
10
 
load_plugins()
11
 
 
12
 
from bzrlib.plugins.gtk import open_display, icon_path
13
 
 
14
 
from bzrlib.plugins.gtk.notify import NotifyPopupMenu
15
 
gtk = open_display()
16
 
menu = NotifyPopupMenu()
17
 
icon = gtk.status_icon_new_from_file(icon_path("bzr-icon-64.png"))
18
 
icon.connect('popup-menu', menu.display)
19
 
 
20
 
import cgi
21
 
import dbus
22
 
import dbus.service
23
 
import pynotify
24
 
from bzrlib.bzrdir import BzrDir
25
 
from bzrlib import errors
26
 
from bzrlib.osutils import format_date
27
 
from bzrlib.transport import get_transport
28
 
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
29
 
        import dbus.glib
30
 
BROADCAST_INTERFACE = "org.bazaarvcs.plugins.dbus.Broadcast"
31
 
bus = dbus.SessionBus()
32
 
 
33
 
def catch_branch(revision_id, urls):
34
 
        # TODO: show all the urls, or perhaps choose the 'best'.
35
 
        url = urls[0]
36
 
        try:
37
 
                if isinstance(revision_id, unicode):
38
 
                        revision_id = revision_id.encode('utf8')
39
 
                transport = get_transport(url)
40
 
                a_dir = BzrDir.open_from_transport(transport)
41
 
                branch = a_dir.open_branch()
42
 
                revno = branch.revision_id_to_revno(revision_id)
43
 
                revision = branch.repository.get_revision(revision_id)
44
 
                summary = 'New revision %d in %s' % (revno, url)
45
 
                body  = 'Committer: %s\n' % revision.committer
46
 
                body += 'Date: %s\n' % format_date(revision.timestamp,
47
 
                        revision.timezone)
48
 
                body += '\n'
49
 
                body += revision.message
50
 
                body = cgi.escape(body)
51
 
                nw = pynotify.Notification(summary, body)
52
 
                def start_viz(notification=None, action=None, data=None):
53
 
                        """Start the viz program."""
54
 
                        pp = start_viz_window(branch, revision_id)
55
 
                        pp.show()
56
 
                def start_branch(notification=None, action=None, data=None):
57
 
                        """Start a Branch dialog"""
58
 
                        from bzrlib.plugins.gtk.branch import BranchDialog
59
 
                        bd = BranchDialog(remote_path=url)
60
 
                        bd.run()
61
 
                nw.add_action("inspect", "Inspect", start_viz, None)
62
 
                nw.add_action("branch", "Branch", start_branch, None)
63
 
                nw.set_timeout(5000)
64
 
                nw.show()
65
 
        except Exception, e:
66
 
                print e
67
 
                raise
68
 
bus.add_signal_receiver(catch_branch,
69
 
                                                dbus_interface=BROADCAST_INTERFACE,
70
 
                                                signal_name="Revision")
71
 
pynotify.init("bzr-notify")
72
 
gtk.main()