/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to mandos-monitor

* mandos-monitor: Speedup: Use properties from D-Bus
                  GetAllClientsWithProperties() call.  Also use
                  super() properly - only use keyword arguments and
                  strip them off as "kwargs" is passed on.
  (MandosClientPropertyCache.__init__): Take new "properties"
                                        argument; use it to skip
                                        calling D-Bus GetAll() method.
                                        Call super().  Bind self._
  (MandosClientPropertyCache._property_changed): New helper function.
  (MandosClientPropertyCache.property_changed): Changed to take
                                                keyword arguments.
  (MandosClientPropertyCache.delete): Bug fix: Don't call
                                      super().__init__().
  (MandosClientWidget.__init__): Don't take *args.  Strip used keyword
                                 arguments before calling super().
  (MandosClientWidget.property_changed): Removed dead code.
  (MandosClientWidget.delete): Don't take *args.
  (MandosClientWidget.property_changed): Don't take "value" argument,
                                         since it is not used.
  (ConstrainedListBox.keypress): Take *args, **kwargs and pass them on
                                 to super().

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
    properties and calls a hook function when any of them are
87
87
    changed.
88
88
    """
89
 
    def __init__(self, proxy_object=None, *args, **kwargs):
 
89
    def __init__(self, proxy_object=None, properties=None, **kwargs):
90
90
        self.proxy = proxy_object # Mandos Client proxy object
91
 
        
92
 
        self.properties = dict()
 
91
        self.properties = dict() if properties is None else properties
93
92
        self.property_changed_match = (
94
93
            self.proxy.connect_to_signal("PropertyChanged",
95
 
                                         self.property_changed,
 
94
                                         self._property_changed,
96
95
                                         client_interface,
97
96
                                         byte_arrays=True))
98
97
        
99
 
        self.properties.update(
100
 
            self.proxy.GetAll(client_interface,
101
 
                              dbus_interface = dbus.PROPERTIES_IFACE))
102
 
 
103
 
        #XXX This breaks good super behaviour
104
 
#        super(MandosClientPropertyCache, self).__init__(
105
 
#            *args, **kwargs)
 
98
        if properties is None:
 
99
            self.properties.update(
 
100
                self.proxy.GetAll(client_interface,
 
101
                                  dbus_interface
 
102
                                  = dbus.PROPERTIES_IFACE))
 
103
        
 
104
        super(MandosClientPropertyCache, self).__init__(**kwargs)
 
105
    
 
106
    def _property_changed(self, property, value):
 
107
        """Helper which takes positional arguments"""
 
108
        return self.property_changed(property=property, value=value)
106
109
    
107
110
    def property_changed(self, property=None, value=None):
108
111
        """This is called whenever we get a PropertyChanged signal
111
114
        # Update properties dict with new value
112
115
        self.properties[property] = value
113
116
    
114
 
    def delete(self, *args, **kwargs):
 
117
    def delete(self):
115
118
        self.property_changed_match.remove()
116
 
        super(MandosClientPropertyCache, self).__init__(
117
 
            *args, **kwargs)
118
119
 
119
120
 
120
121
class MandosClientWidget(urwid.FlowWidget, MandosClientPropertyCache):
122
123
    """
123
124
    
124
125
    def __init__(self, server_proxy_object=None, update_hook=None,
125
 
                 delete_hook=None, logger=None, *args, **kwargs):
 
126
                 delete_hook=None, logger=None, **kwargs):
126
127
        # Called on update
127
128
        self.update_hook = update_hook
128
129
        # Called on delete
139
140
        self._text_widget = urwid.Text("")
140
141
        # The widget shown when we have focus
141
142
        self._focus_text_widget = urwid.Text("")
142
 
        super(MandosClientWidget, self).__init__(
143
 
            update_hook=update_hook, delete_hook=delete_hook,
144
 
            *args, **kwargs)
 
143
        super(MandosClientWidget, self).__init__(**kwargs)
145
144
        self.update()
146
145
        self.opened = False
147
146
        
344
343
        self.update()
345
344
        return True             # Keep calling this
346
345
    
347
 
    def delete(self, *args, **kwargs):
 
346
    def delete(self, **kwargs):
348
347
        if self._update_timer_callback_tag is not None:
349
348
            gobject.source_remove(self._update_timer_callback_tag)
350
349
            self._update_timer_callback_tag = None
353
352
        self.match_objects = ()
354
353
        if self.delete_hook is not None:
355
354
            self.delete_hook(self)
356
 
        return super(MandosClientWidget, self).delete(*args, **kwargs)
 
355
        return super(MandosClientWidget, self).delete(**kwargs)
357
356
    
358
357
    def render(self, maxcolrow, focus=False):
359
358
        """Render differently if we have focus.
401
400
        else:
402
401
            return key
403
402
    
404
 
    def property_changed(self, property=None, value=None,
405
 
                         *args, **kwargs):
 
403
    def property_changed(self, property=None, **kwargs):
406
404
        """Call self.update() if old value is not new value.
407
405
        This overrides the method from MandosClientPropertyCache"""
408
406
        property_name = unicode(property)
409
407
        old_value = self.properties.get(property_name)
410
408
        super(MandosClientWidget, self).property_changed(
411
 
            property=property, value=value, *args, **kwargs)
 
409
            property=property, **kwargs)
412
410
        if self.properties.get(property_name) != old_value:
413
411
            self.update()
414
412
 
418
416
    "down" key presses, thus not allowing any containing widgets to
419
417
    use them as an excuse to shift focus away from this widget.
420
418
    """
421
 
    def keypress(self, maxcolrow, key):
422
 
        ret = super(ConstrainedListBox, self).keypress(maxcolrow, key)
 
419
    def keypress(self, *args, **kwargs):
 
420
        ret = super(ConstrainedListBox, self).keypress(*args, **kwargs)
423
421
        if ret in ("up", "down"):
424
422
            return
425
423
        return ret
640
638
                                               logger
641
639
                                               =self.log_message),
642
640
                            path=path)
643
 
 
 
641
        
644
642
        self.refresh()
645
643
        self._input_callback_tag = (gobject.io_add_watch
646
644
                                    (sys.stdin.fileno(),