Merge lp:~jelmer/bzr-gtk/already-running into lp:bzr-gtk/gtk2

Proposed by Jelmer Vernooij
Status: Merged
Merged at revision: not available
Proposed branch: lp:~jelmer/bzr-gtk/already-running
Merge into: lp:bzr-gtk/gtk2
Diff against target: 164 lines (+62/-55)
3 files modified
NEWS (+3/-0)
bzr-notify (+54/-55)
notify.py (+5/-0)
To merge this branch: bzr merge lp:~jelmer/bzr-gtk/already-running
Reviewer Review Type Date Requested Status
Vincent Ladeuil Approve
Review via email: mp+20549@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

This makes bzr-notify start correctly if there's already an instance running and lan-notify is available.

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

> This makes bzr-notify start correctly if there's already an instance running
> and lan-notify is available.
Oh, and some formatting cleanups in bzr-notify (contained tabs)

Revision history for this message
Vincent Ladeuil (vila) wrote :

Go ahead, land ! :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-03-01 08:52:45 +0000
3+++ NEWS 2010-03-03 14:16:19 +0000
4@@ -4,6 +4,9 @@
5
6 * Guard setup() call when not loaded as __main__. (Robert Collins)
7
8+ * Don't crash when there is already a lan-notify instance running.
9+ (Jelmer Vernooij, #339284)
10+
11 FEATURES
12
13 * Add support for Indicator Application (Sense Hofstede, Jelmer Vernooij,
14
15=== modified file 'bzr-notify'
16--- bzr-notify 2010-02-28 15:19:15 +0000
17+++ bzr-notify 2010-03-03 14:16:19 +0000
18@@ -25,69 +25,68 @@
19
20 menu = NotifyPopupMenu()
21 try:
22- import appindicator
23+ import appindicator
24 except ImportError:
25- icon = gtk.status_icon_new_from_file(icon_path("bzr-icon-64.png"))
26- icon.connect('popup-menu', menu.display)
27- icon.set_visible(False)
28- hide_icon = lambda: icon.set_visible(False)
29- show_icon = lambda: icon.set_visible(True)
30+ icon = gtk.status_icon_new_from_file(icon_path("bzr-icon-64.png"))
31+ icon.connect('popup-menu', menu.display)
32+ icon.set_visible(False)
33+ hide_icon = lambda: icon.set_visible(False)
34+ show_icon = lambda: icon.set_visible(True)
35 else:
36- indicator = appindicator.Indicator ("bzr-gtk-notify",
37- "bzr-icon-64",
38- appindicator.CATEGORY_APPLICATION_STATUS)
39- indicator.set_status (appindicator.STATUS_PASSIVE)
40- indicator.set_attention_icon("bzr-icon-64")
41- indicator.set_menu(menu)
42- hide_icon = lambda: indicator.set_status (appindicator.STATUS_PASSIVE)
43- show_icon = lambda: indicator.set_status (appindicator.STATUS_ATTENTION)
44+ indicator = appindicator.Indicator ("bzr-gtk-notify",
45+ "bzr-icon-64", appindicator.CATEGORY_APPLICATION_STATUS)
46+ indicator.set_status (appindicator.STATUS_PASSIVE)
47+ indicator.set_attention_icon("bzr-icon-64")
48+ indicator.set_menu(menu)
49+ hide_icon = lambda: indicator.set_status (appindicator.STATUS_PASSIVE)
50+ show_icon = lambda: indicator.set_status (appindicator.STATUS_ATTENTION)
51
52 if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
53- import dbus.glib
54+ import dbus.glib
55 BROADCAST_INTERFACE = "org.bazaarvcs.plugins.dbus.Broadcast"
56 bus = dbus.SessionBus()
57
58 def catch_branch(revision_id, urls):
59- # TODO: show all the urls, or perhaps choose the 'best'.
60- url = urls[0]
61- try:
62- if isinstance(revision_id, unicode):
63- revision_id = revision_id.encode('utf8')
64- transport = get_transport(url)
65- a_dir = BzrDir.open_from_transport(transport)
66- branch = a_dir.open_branch()
67- revno = branch.revision_id_to_revno(revision_id)
68- revision = branch.repository.get_revision(revision_id)
69- summary = 'New revision %d in %s' % (revno, url)
70- body = 'Committer: %s\n' % revision.committer
71- body += 'Date: %s\n' % format_date(revision.timestamp,
72- revision.timezone)
73- body += '\n'
74- body += revision.message
75- body = cgi.escape(body)
76- nw = pynotify.Notification(summary, body)
77- def start_viz(notification=None, action=None, data=None):
78- """Start the viz program."""
79- from bzrlib.plugins.gtk.commands import start_viz_window
80- pp = start_viz_window(branch, revision_id)
81- pp.show()
82- def start_branch(notification=None, action=None, data=None):
83- """Start a Branch dialog"""
84- from bzrlib.plugins.gtk.branch import BranchDialog
85- bd = BranchDialog(remote_path=url)
86- bd.run()
87- if "actions" in pynotify.get_server_caps():
88- nw.add_action("inspect", "Inspect", start_viz, None)
89- nw.add_action("branch", "Branch", start_branch, None)
90- show_icon()
91- gobject.timeout_add(5000, hide_icon)
92- nw.set_timeout(5000)
93- nw.show()
94- except Exception, e:
95- print e
96- raise
97+ # TODO: show all the urls, or perhaps choose the 'best'.
98+ url = urls[0]
99+ try:
100+ if isinstance(revision_id, unicode):
101+ revision_id = revision_id.encode('utf8')
102+ transport = get_transport(url)
103+ a_dir = BzrDir.open_from_transport(transport)
104+ branch = a_dir.open_branch()
105+ revno = branch.revision_id_to_revno(revision_id)
106+ revision = branch.repository.get_revision(revision_id)
107+ summary = 'New revision %d in %s' % (revno, url)
108+ body = 'Committer: %s\n' % revision.committer
109+ body += 'Date: %s\n' % format_date(revision.timestamp,
110+ revision.timezone)
111+ body += '\n'
112+ body += revision.message
113+ body = cgi.escape(body)
114+ nw = pynotify.Notification(summary, body)
115+ def start_viz(notification=None, action=None, data=None):
116+ """Start the viz program."""
117+ from bzrlib.plugins.gtk.commands import start_viz_window
118+ pp = start_viz_window(branch, revision_id)
119+ pp.show()
120+ def start_branch(notification=None, action=None, data=None):
121+ """Start a Branch dialog"""
122+ from bzrlib.plugins.gtk.branch import BranchDialog
123+ bd = BranchDialog(remote_path=url)
124+ bd.run()
125+ if "actions" in pynotify.get_server_caps():
126+ nw.add_action("inspect", "Inspect", start_viz, None)
127+ nw.add_action("branch", "Branch", start_branch, None)
128+ show_icon()
129+ gobject.timeout_add(5000, hide_icon)
130+ nw.set_timeout(5000)
131+ nw.show()
132+ except Exception, e:
133+ print e
134+ raise
135 bus.add_signal_receiver(catch_branch,
136- dbus_interface=BROADCAST_INTERFACE,
137- signal_name="Revision")
138+ dbus_interface=BROADCAST_INTERFACE,
139+ signal_name="Revision")
140 pynotify.init("bzr-notify")
141 gtk.main()
142
143=== modified file 'notify.py'
144--- notify.py 2009-01-29 10:06:26 +0000
145+++ notify.py 2010-03-03 14:16:19 +0000
146@@ -40,6 +40,7 @@
147 self.create_items()
148
149 def create_items(self):
150+ from bzrlib import errors
151 item = gtk.CheckMenuItem('_Gateway to LAN')
152 item.connect('toggled', self.toggle_lan_gateway)
153 self.append(item)
154@@ -49,6 +50,10 @@
155 self.langateway = LanGateway()
156 except ImportError:
157 item.set_sensitive(False)
158+ except errors.BzrError:
159+ # FIXME: Should only catch errors that indicate a lan-notify
160+ # process is already running.
161+ item.set_sensitive(False)
162
163 item = gtk.CheckMenuItem('Announce _branches on LAN')
164 item.connect('toggled', self.toggle_announce_branches)

Subscribers

People subscribed via source and target branches

to all changes: