Merge lp://qastaging/~sil/desktopcouch/pick-or-listen-non-global-489925 into lp://qastaging/desktopcouch

Proposed by Stuart Langridge
Status: Merged
Approved by: Guillermo Gonzalez
Approved revision: not available
Merged at revision: not available
Proposed branch: lp://qastaging/~sil/desktopcouch/pick-or-listen-non-global-489925
Merge into: lp://qastaging/desktopcouch
Diff against target: 119 lines (+14/-14)
1 file modified
bin/desktopcouch-pair (+14/-14)
To merge this branch: bzr merge lp://qastaging/~sil/desktopcouch/pick-or-listen-non-global-489925
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
Chad Miller (community) Approve
Review via email: mp+15419@code.qastaging.launchpad.net

Commit message

Improve pairing tool reliability. Make pick_or_listen not be a global, which fixes a race condition in signals and initialization.

To post a comment you must log in.
Revision history for this message
Stuart Langridge (sil) wrote :

A patch from thomasvs to make pick_or_listen not be a global. See bug 489925.

Revision history for this message
Chad Miller (cmiller) wrote :

Looks good to me. I approve.

review: Approve
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

looks ok

review: Approve
Revision history for this message
Stuart Langridge (sil) wrote :

Please don't merge this yet, until we have the contributor agreement.

Revision history for this message
Stuart Langridge (sil) wrote :

Contributor agreement arrived. Thanks!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/desktopcouch-pair'
--- bin/desktopcouch-pair 2009-10-14 14:48:25 +0000
+++ bin/desktopcouch-pair 2009-11-30 13:20:24 +0000
@@ -1,4 +1,5 @@
1#!/usr/bin/python1#!/usr/bin/python
2# vi:si:et:sw=4:sts=4:ts=4
2# Copyright 2009 Canonical Ltd.3# Copyright 2009 Canonical Ltd.
3#4#
4# This file is part of desktopcouch.5# This file is part of desktopcouch.
@@ -138,18 +139,19 @@
138139
139 def auth_completed(self, remote_host, remote_id, remote_oauth):140 def auth_completed(self, remote_host, remote_id, remote_oauth):
140 """The auth stage is finished. Now pair with the remote host."""141 """The auth stage is finished. Now pair with the remote host."""
141 pair_with_host(remote_host, remote_id, remote_oauth)142 pair_with_host(remote_host, remote_id, remote_oauth, self.parent)
142 self.window.destroy()143 self.window.destroy()
143144
144 def on_close(self):145 def on_close(self):
145 """When a socket is closed, we should stop inviting. (?)"""146 """When a socket is closed, we should stop inviting. (?)"""
146 self.window.destroy()147 self.window.destroy()
147148
148 def __init__(self, service, hostname, port):149 def __init__(self, service, hostname, port, parent):
149 self.logging = logging.getLogger(self.__class__.__name__)150 self.logging = logging.getLogger(self.__class__.__name__)
150151
151 self.hostname = hostname152 self.hostname = hostname
152 self.port = port153 self.port = port
154 self.parent = parent
153155
154 self.window = gtk.Window()156 self.window = gtk.Window()
155 self.window.set_border_width(6)157 self.window.set_border_width(6)
@@ -510,7 +512,7 @@
510 512
511 if service_name:513 if service_name:
512 # Pairing with a cloud service, which doesn't do key exchange514 # Pairing with a cloud service, which doesn't do key exchange
513 pair_with_cloud_service(service_name)515 pair_with_cloud_service(service_name, self.window)
514 # remove from listening list516 # remove from listening list
515 self.listening_hosts.remove(iter)517 self.listening_hosts.remove(iter)
516 # add to already-paired list518 # add to already-paired list
@@ -523,7 +525,7 @@
523 hostname, port)525 hostname, port)
524 if self.inviting != None:526 if self.inviting != None:
525 self.inviting.window.destroy()527 self.inviting.window.destroy()
526 self.inviting = Inviting(service, hostname, port)528 self.inviting = Inviting(service, hostname, port, self)
527 self.inviting.window.connect("destroy",529 self.inviting.window.connect("destroy",
528 lambda *args: setattr(self, "inviting_window", None))530 lambda *args: setattr(self, "inviting_window", None))
529531
@@ -779,7 +781,7 @@
779 self.window.show()781 self.window.show()
780782
781783
782def pair_with_host(hostname, hostid, oauth_data):784def pair_with_host(hostname, hostid, oauth_data, parent):
783 """We've verified all is correct and authorized, so now we pair785 """We've verified all is correct and authorized, so now we pair
784 the databases."""786 the databases."""
785 logging.info("verified host %s/%s. Done!", hostname, hostid)787 logging.info("verified host %s/%s. Done!", hostname, hostid)
@@ -790,7 +792,7 @@
790 except Exception, e:792 except Exception, e:
791 logging.exception("failure writing record for %s", hostname)793 logging.exception("failure writing record for %s", hostname)
792 fail_note = gtk.MessageDialog(794 fail_note = gtk.MessageDialog(
793 parent=pick_or_listen.window,795 parent=parent,
794 flags=gtk.DIALOG_DESTROY_WITH_PARENT,796 flags=gtk.DIALOG_DESTROY_WITH_PARENT,
795 buttons=gtk.BUTTONS_OK,797 buttons=gtk.BUTTONS_OK,
796 type=gtk.MESSAGE_ERROR,798 type=gtk.MESSAGE_ERROR,
@@ -800,7 +802,7 @@
800 return802 return
801 803
802 success_note = gtk.Dialog(title=_("Paired with %(hostname)s") % locals(), 804 success_note = gtk.Dialog(title=_("Paired with %(hostname)s") % locals(),
803 parent=pick_or_listen.window,805 parent=parent,
804 flags=gtk.DIALOG_DESTROY_WITH_PARENT,806 flags=gtk.DIALOG_DESTROY_WITH_PARENT,
805 buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,))807 buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,))
806 text = gtk.Label(808 text = gtk.Label(
@@ -809,13 +811,13 @@
809 content_box = success_note.get_content_area()811 content_box = success_note.get_content_area()
810 content_box.pack_start(text, True, True, 20)812 content_box.pack_start(text, True, True, 20)
811 success_note.connect("close",813 success_note.connect("close",
812 lambda *args: pick_or_listen.window.destroy())814 lambda *args: parent.destroy())
813 success_note.connect("response",815 success_note.connect("response",
814 lambda *args: pick_or_listen.window.destroy())816 lambda *args: parent.destroy())
815 success_note.show()817 success_note.show()
816818
817819
818def pair_with_cloud_service(service_name):820def pair_with_cloud_service(service_name, parent):
819 """Write a paired server record for the selected cloud service."""821 """Write a paired server record for the selected cloud service."""
820 try:822 try:
821 import desktopcouch.replication_services as services823 import desktopcouch.replication_services as services
@@ -826,7 +828,7 @@
826 except Exception, e:828 except Exception, e:
827 logging.exception("failure in module for service %r", service_name)829 logging.exception("failure in module for service %r", service_name)
828 fail_note = gtk.MessageDialog(830 fail_note = gtk.MessageDialog(
829 parent=pick_or_listen.window,831 parent=parent,
830 flags=gtk.DIALOG_DESTROY_WITH_PARENT,832 flags=gtk.DIALOG_DESTROY_WITH_PARENT,
831 buttons=gtk.BUTTONS_OK,833 buttons=gtk.BUTTONS_OK,
832 type=gtk.MESSAGE_ERROR,834 type=gtk.MESSAGE_ERROR,
@@ -836,7 +838,7 @@
836 return838 return
837 839
838 success_note = gtk.MessageDialog(840 success_note = gtk.MessageDialog(
839 parent=pick_or_listen.window,841 parent=parent,
840 flags=gtk.DIALOG_DESTROY_WITH_PARENT,842 flags=gtk.DIALOG_DESTROY_WITH_PARENT,
841 buttons=gtk.BUTTONS_OK,843 buttons=gtk.BUTTONS_OK,
842 type=gtk.MESSAGE_INFO,844 type=gtk.MESSAGE_INFO,
@@ -885,8 +887,6 @@
885 import gobject887 import gobject
886 gobject.set_application_name("desktopcouch pairing tool")888 gobject.set_application_name("desktopcouch pairing tool")
887889
888 global pick_or_listen # pylint: disable-msg=W0601
889
890 logging.basicConfig(level=logging.DEBUG, format=890 logging.basicConfig(level=logging.DEBUG, format=
891 "%(asctime)s [%(process)d] %(name)s:%(levelname)s: %(message)s")891 "%(asctime)s [%(process)d] %(name)s:%(levelname)s: %(message)s")
892892

Subscribers

People subscribed via source and target branches