~ubuntu-branches/debian/squeeze/desktopcouch/squeeze

« back to all changes in this revision

Viewing changes to bin/desktopcouch-pair

  • Committer: Bazaar Package Importer
  • Author(s): David Paleino
  • Date: 2010-03-04 19:11:48 UTC
  • mfrom: (1.5.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100304191148-zcwp3rffruwkalvc
Tags: 0.6.2-1
* New upstream version
* debian/patches/01-use_simplejson.patch removed, better handled
  upstream (simplejson for py2.5 and json for py2.6)
* debian/rules: chmod desktop-stop to 755, since it's intended as
  an executable script
* debian/control: bump debhelper dependency to >= 7.0.50~ to use
  overridden rules in debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
 
2
# vi:si:et:sw=4:sts=4:ts=4
2
3
# Copyright 2009 Canonical Ltd.
3
4
#
4
5
# This file is part of desktopcouch.
138
139
 
139
140
    def auth_completed(self, remote_host, remote_id, remote_oauth):
140
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
143
        self.window.destroy()
143
144
 
144
145
    def on_close(self):
145
146
        """When a socket is closed, we should stop inviting.  (?)"""
146
147
        self.window.destroy()
147
148
 
148
 
    def __init__(self, service, hostname, port):
 
149
    def __init__(self, service, hostname, port, parent):
149
150
        self.logging = logging.getLogger(self.__class__.__name__)
150
151
 
151
152
        self.hostname = hostname
152
153
        self.port = port
 
154
        self.parent = parent
153
155
 
154
156
        self.window = gtk.Window()
155
157
        self.window.set_border_width(6)
510
512
            
511
513
            if service_name:
512
514
                # 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
516
                # remove from listening list
515
517
                self.listening_hosts.remove(iter)
516
518
                # add to already-paired list
523
525
                    hostname, port)
524
526
            if self.inviting != None:
525
527
                self.inviting.window.destroy()
526
 
            self.inviting = Inviting(service, hostname, port)
 
528
            self.inviting = Inviting(service, hostname, port, self)
527
529
            self.inviting.window.connect("destroy",
528
530
                    lambda *args: setattr(self, "inviting_window", None))
529
531
 
779
781
        self.window.show()
780
782
 
781
783
 
782
 
def pair_with_host(hostname, hostid, oauth_data):
 
784
def pair_with_host(hostname, hostid, oauth_data, parent):
783
785
    """We've verified all is correct and authorized, so now we pair
784
786
    the databases."""
785
787
    logging.info("verified host %s/%s.  Done!", hostname, hostid)
790
792
    except Exception, e:
791
793
        logging.exception("failure writing record for %s", hostname)
792
794
        fail_note = gtk.MessageDialog(
793
 
                parent=pick_or_listen.window,
 
795
                parent=parent,
794
796
                flags=gtk.DIALOG_DESTROY_WITH_PARENT,
795
797
                buttons=gtk.BUTTONS_OK,
796
798
                type=gtk.MESSAGE_ERROR,
800
802
        return
801
803
    
802
804
    success_note = gtk.Dialog(title=_("Paired with %(hostname)s") % locals(), 
803
 
            parent=pick_or_listen.window,
 
805
            parent=parent,
804
806
            flags=gtk.DIALOG_DESTROY_WITH_PARENT,
805
807
            buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,))
806
808
    text = gtk.Label(
809
811
    content_box = success_note.get_content_area()
810
812
    content_box.pack_start(text, True, True, 20)
811
813
    success_note.connect("close",
812
 
            lambda *args: pick_or_listen.window.destroy())
 
814
            lambda *args: parent.destroy())
813
815
    success_note.connect("response",
814
 
            lambda *args: pick_or_listen.window.destroy())
 
816
            lambda *args: parent.destroy())
815
817
    success_note.show()
816
818
 
817
819
 
818
 
def pair_with_cloud_service(service_name):
 
820
def pair_with_cloud_service(service_name, parent):
819
821
    """Write a paired server record for the selected cloud service."""
820
822
    try:
821
823
        import desktopcouch.replication_services as services
826
828
    except Exception, e:
827
829
        logging.exception("failure in module for service %r", service_name)
828
830
        fail_note = gtk.MessageDialog(
829
 
                parent=pick_or_listen.window,
 
831
                parent=parent,
830
832
                flags=gtk.DIALOG_DESTROY_WITH_PARENT,
831
833
                buttons=gtk.BUTTONS_OK,
832
834
                type=gtk.MESSAGE_ERROR,
836
838
        return
837
839
    
838
840
    success_note = gtk.MessageDialog(
839
 
            parent=pick_or_listen.window,
 
841
            parent=parent,
840
842
            flags=gtk.DIALOG_DESTROY_WITH_PARENT,
841
843
            buttons=gtk.BUTTONS_OK,
842
844
            type=gtk.MESSAGE_INFO,
885
887
    import gobject
886
888
    gobject.set_application_name("desktopcouch pairing tool")
887
889
 
888
 
    global pick_or_listen  # pylint: disable-msg=W0601
889
 
 
890
890
    logging.basicConfig(level=logging.DEBUG, format=
891
891
            "%(asctime)s [%(process)d] %(name)s:%(levelname)s:  %(message)s")
892
892