~statik/ubuntuone-client/link-please

« back to all changes in this revision

Viewing changes to ubuntuone/syncdaemon/dbus_interface.py

  • Committer: Tarmac
  • Author(s): guillermo.gonzalez at canonical
  • Date: 2009-08-18 12:36:21 UTC
  • mfrom: (149.1.5 logging_note-is-not-error)
  • Revision ID: dobey@gnome.org-20090818123621-yhlaee9hnrtvjhqn
cleanup INFO logging and add DEBUG logs to DBusInterface

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
                   NM_STATE_DISCONNECTED: 'SYS_NET_DISCONNECTED'}
44
44
 
45
45
 
 
46
logger = logging.getLogger("ubuntuone.SyncDaemon.DBus")
 
47
 
 
48
 
46
49
class DBusExposedObject(dbus.service.Object):
47
50
    """ Base class that provides some helper methods to
48
51
    DBus exposed objects.
88
91
        """ return the current status of the system, one of: local_rescan,
89
92
        offline, trying_to_connect, server_rescan or online.
90
93
        """
 
94
        logger.debug('called current_status')
91
95
        state = self.dbus_iface.main.state.state
92
96
        self.emit_status_changed(state)
93
97
        state_dict = {'name':state.name,
100
104
    @dbus.service.method(DBUS_IFACE_STATUS_NAME, out_signature='aa{ss}')
101
105
    def current_downloads(self):
102
106
        """ return list of files with a download in progress. """
 
107
        logger.debug('called current_downloads')
103
108
        current_downloads = []
104
109
        for download in self.action_queue.downloading:
105
110
            try:
127
132
        """
128
133
        returns a list of files that are waiting to be up- or downloaded
129
134
        """
 
135
        logger.debug('called waiting_content')
130
136
        waiting_content = []
131
137
        for cmd in self.action_queue.content_queue.waiting:
132
138
            try:
152
158
        Make the command on the given share and node be next in the
153
159
        queue of waiting commands.
154
160
        """
 
161
        logger.debug('called schedule_next')
155
162
        self.action_queue.content_queue.schedule_next(share_id, node_id)
156
163
 
157
164
    @dbus.service.method(DBUS_IFACE_STATUS_NAME, out_signature='aa{ss}')
158
165
    def current_uploads(self):
159
166
        """ return a list of files with a upload in progress """
 
167
        logger.debug('called current_uploads')
160
168
        current_uploads = []
161
169
        for upload in self.action_queue.uploading:
162
170
            share_id, node_id = upload
264
272
    @dbus.service.method(DBUS_IFACE_EVENTS_NAME, in_signature='sas')
265
273
    def push_event(self, event_name, args):
266
274
        """ Push a event to the event queue """
 
275
        logger.debug('push_event: %r with %r', event_name, args)
267
276
        str_args = []
268
277
        for arg in args:
269
278
            str_args.append(str(arg))
418
427
                         in_signature='', out_signature='')
419
428
    def connect(self):
420
429
        """ Connect to the server. """
 
430
        logger.debug('connect requetsed')
421
431
        self.dbus_iface.connect()
422
432
 
423
433
    @dbus.service.method(DBUS_IFACE_SYNC_NAME,
424
434
                         in_signature='', out_signature='')
425
435
    def disconnect(self):
426
436
        """ Disconnect from the server. """
 
437
        logger.debug('disconnect requetsed')
427
438
        self.dbus_iface.disconnect()
428
439
 
429
440
    @dbus.service.method(DBUS_IFACE_SYNC_NAME,
430
441
                         in_signature='', out_signature='s')
431
442
    def get_rootdir(self):
432
443
        """ Returns the root dir/mount point. """
 
444
        logger.debug('called get_rootdir')
433
445
        return self.dbus_iface.main.get_rootdir()
434
446
 
435
447
    @dbus.service.method(DBUS_IFACE_SYNC_NAME,
440
452
        """ call the reply handler when there are no more
441
453
        events or transfers.
442
454
        """
 
455
        logger.debug('called wait_for_nirvana')
443
456
        d = self.dbus_iface.main.wait_for_nirvana(last_event_interval)
444
457
        d.addCallbacks(reply_handler, error_handler)
445
458
        return d
448
461
                         in_signature='s', out_signature='')
449
462
    def query_by_path(self, path):
450
463
        """  Request a query of the node identified by path. """
 
464
        logger.debug('query_by_path: %r', path)
451
465
        mdobj = self.dbus_iface.fs_manager.get_by_path(path.encode('utf-8'))
452
466
        items = [(mdobj.share_id, mdobj.node_id, "")]
453
467
        self.dbus_iface.action_queue.query(items)
457
471
                         async_callbacks=('reply_handler', 'error_handler'))
458
472
    def quit(self, reply_handler=None, error_handler=None):
459
473
        """ shutdown the syncdaemon. """
460
 
        self.dbus_iface.log.debug('Quit requested')
 
474
        logger.debug('Quit requested')
461
475
        if reply_handler:
462
476
            reply_handler()
463
477
        self.dbus_iface.quit()
478
492
        """ returns the dict with the attributes of the metadata
479
493
        for the specified path.
480
494
        """
 
495
        logger.debug('get_metadata: %r', path)
481
496
        mdobj = self.fs_manager.get_by_path(path.encode('utf-8'))
482
497
        md_dict = {}
483
498
        for k, v in mdobj.__dict__.items():
505
520
                         in_signature='', out_signature='aa{ss}')
506
521
    def get_shares(self):
507
522
        """ returns a list of dicts, each dict represents a share """
 
523
        logger.debug('called get_shares')
508
524
        shares = []
509
525
        for share_id, share in self.vm.shares.items():
510
526
            if share_id == '':
520
536
        """ Accepts a share, a ShareAnswerOk|Error signal will be fired in the
521
537
        future as a success/failure indicator.
522
538
        """
 
539
        logger.debug('accept_share: %r', share_id)
523
540
        if str(share_id) in self.vm.shares:
524
541
            self.vm.accept_share(str(share_id), True)
525
542
            reply_handler()
532
549
                         async_callbacks=('reply_handler', 'error_handler'))
533
550
    def reject_share(self, share_id, reply_handler=None, error_handler=None):
534
551
        """ Rejects a share. """
 
552
        logger.debug('reject_share: %r', share_id)
535
553
        if str(share_id) in self.vm.shares:
536
554
            self.vm.accept_share(str(share_id), False)
537
555
            reply_handler()
584
602
        @param name: the name of the share
585
603
        @param access_level: 'View' or 'Modify'
586
604
        """
 
605
        logger.debug('create share: %r, %r, %r, %r',
 
606
                     path, username, name, access_level)
587
607
        path = path.encode("utf8")
588
608
        username = unicode(username)
589
609
        name = unicode(name)
627
647
        A share might not have the path set, as we might be still fetching the
628
648
        nodes from the server. In this cases the path is ''
629
649
        """
 
650
        logger.debug('called get_shared')
630
651
        shares = []
631
652
        for share_id, share in self.vm.shared.items():
632
653
            if share_id == '':
657
678
        """ Create the instance and add the exposed object to the
658
679
        specified bus.
659
680
        """
660
 
        self.log = logging.getLogger("ubuntuone.SyncDaemon.DBus")
661
681
        self.bus = bus
662
682
        self.main = main
663
683
        self.event_queue = main.event_q
674
694
        self.shares = Shares(self.busName, self.fs_manager,
675
695
                             self.volume_manager)
676
696
        if system_bus is None and not DBusInterface.test:
677
 
            self.log.debug('using the real system bus')
 
697
            logger.debug('using the real system bus')
678
698
            self.system_bus = self.bus.get_system()
679
699
        elif system_bus is None and DBusInterface.test:
680
700
            # this is just for the case when test_sync instatiate Main for
681
701
            # running it's tests as pqm don't have a system bus running
682
 
            self.log.debug('using the session bus as system bus')
 
702
            logger.debug('using the session bus as system bus')
683
703
            self.system_bus = self.bus
684
704
        else:
685
705
            self.system_bus = system_bus
688
708
            # on initialization, fake a SYS_NET_CONNECTED if appropriate
689
709
            if DBusInterface.test:
690
710
                # testing under sync; just do it
691
 
                self.log.debug('using the fake NetworkManager')
 
711
                logger.debug('using the fake NetworkManager')
692
712
                self.connection_state_changed(NM_STATE_CONNECTED)
693
713
            else:
694
714
                def error_handler(error):
695
715
                    """
696
716
                    Handle errors from NM
697
717
                    """
698
 
                    self.log.error(
 
718
                    logger.error(
699
719
                        "Error while getting the NetworkManager state %s",
700
720
                        error)
701
721
                    # If we get an error back from NetworkManager, we should
710
730
                    if e.get_dbus_name() == \
711
731
                        'org.freedesktop.DBus.Error.ServiceUnknown':
712
732
                        # NetworkManager isn't running.
713
 
                        self.log.warn("Unable to connect to NetworkManager. "
 
733
                        logger.warn("Unable to connect to NetworkManager. "
714
734
                                      "Assuming we have network.")
715
735
                        self.connection_state_changed(NM_STATE_CONNECTED)
716
736
                    else:
725
745
                               signal_name='StateChanged',
726
746
                               dbus_interface='org.freedesktop.NetworkManager',
727
747
                               path='/org/freedesktop/NetworkManager')
 
748
        logger.info('DBusInterface initialized.')
728
749
 
729
750
    def shutdown(self, with_restart=False):
730
751
        """ remove the registered object from the bus and unsubscribe from the
731
752
        event queue.
732
753
        """
733
 
        self.log.debug('Shuttingdown DBusInterface!')
 
754
        logger.info('Shuttingdown DBusInterface!')
734
755
        self.status.remove_from_connection()
735
756
        self.events.remove_from_connection()
736
757
        self.sync.remove_from_connection()
778
799
            access_token = self.main.get_access_token()
779
800
            self.event_queue.push('SYS_CONNECT', access_token)
780
801
        except NoAccessToken, e:
781
 
            self.log.exception("Can't get the auth token")
 
802
            logger.exception("Can't get the auth token")
782
803
 
783
804
    def disconnect(self):
784
805
        """ Push the SYS_DISCONNECT event. """
786
807
 
787
808
    def quit(self):
788
809
        """ calls Main.quit. """
789
 
        self.log.debug('Calling Main.quit')
 
810
        logger.debug('Calling Main.quit')
790
811
        self.main.quit()