~verterok/ubuntuone-client/volumemanager_udfs-2

« back to all changes in this revision

Viewing changes to ubuntuone/syncdaemon/tools.py

  • Committer: Tarmac
  • Author(s): guillermo.gonzalez at canonical
  • Date: 2009-12-17 13:06:24 UTC
  • mfrom: (288.2.7 u1sdtool-start)
  • Revision ID: john.lenton@canonical.com-20091217130624-l00g83qmhrd1zzvl
add the --start option to u1sdtool, also start syncdaemon before executing a command if it's not running.

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
        msg = MethodCallMessage(self.destination, self.path, self.interface,
66
66
                                method)
67
67
        msg.set_no_reply(True)
68
 
        msg.append(*args)
 
68
        # get the signature
 
69
        signature = kwargs.get('signature', None)
 
70
        if signature is not None:
 
71
            msg.append(signature=signature, *args)
 
72
        else:
 
73
            msg.append(*args)
 
74
        #gbet the reply/error handlers
69
75
        reply_handler = kwargs.get('reply_handler', None)
70
76
        error_handler = kwargs.get('error_handler', None)
71
77
        assert error_handler != None
397
403
        sd_client.call_method('quit',
398
404
                           reply_handler=d.callback,
399
405
                           error_handler=d.errback)
 
406
        def check(r):
 
407
            """wait 0.5 sec to return, to allow syncdaemon to shutdown"""
 
408
            d1 = defer.Deferred()
 
409
            reactor.callLater(0.5, d1.callback, r)
 
410
            return d1
 
411
        d.addCallback(check)
400
412
        return d
401
413
 
402
414
    def wait_for_signal(self, signal_name, filter):
410
422
        def signal_handler(result):
411
423
            """handle the signals and fires the call/errback"""
412
424
            try:
413
 
                if filter(result):
 
425
                if filter(result) and not d.called:
414
426
                    d.callback(result)
415
427
                # catch all exceptions, pylint: disable-msg=W0703
416
428
            except Exception, e:
482
494
                                  error_handler=d.errback)
483
495
        return d
484
496
 
 
497
    def start(self):
 
498
        """Start syncdaemon using the StartServiceByName method
 
499
        if it's not running.
 
500
        """
 
501
        if not is_running():
 
502
            wait_d = self.wait_for_signal('StatusChanged', lambda x: x)
 
503
            d = defer.Deferred()
 
504
            bus_client = DBusClient(self.bus, dbus.bus.BUS_DAEMON_PATH,
 
505
                                    dbus.bus.BUS_DAEMON_IFACE,
 
506
                                    dbus.bus.BUS_DAEMON_NAME)
 
507
            bus_client.call_method('StartServiceByName',
 
508
                                   DBUS_IFACE_NAME, 0,
 
509
                                   signature='su',
 
510
                                   reply_handler=d.callback,
 
511
                                   error_handler=d.errback)
 
512
            d.addCallback(lambda _: wait_d)
 
513
            return d
 
514
        else:
 
515
            return defer.succeed(None)
 
516
 
 
517
 
485
518
 
486
519
# callbacks used by u1sdtool script
487
520