/mandos/trunk

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

« back to all changes in this revision

Viewing changes to mandos

  • Committer: Björn Påhlsson
  • Date: 2011-10-02 19:18:24 UTC
  • mto: This revision was merged to the branch mainline in revision 505.
  • Revision ID: belorn@fukt.bsnet.se-20111002191824-eweh4pvneeg3qzia
transitional stuff actually working
documented change to D-Bus API

Show diffs side-by-side

added added

removed removed

Lines of Context:
627
627
    def _get_all_dbus_properties(self):
628
628
        """Returns a generator of (name, attribute) pairs
629
629
        """
630
 
        return ((prop._dbus_name, prop)
631
 
                for name, prop in
632
 
                inspect.getmembers(self, self._is_dbus_property))
 
630
        return ((prop.__get__(self)._dbus_name, prop.__get__(self))
 
631
                for cls in self.__class__.__mro__
 
632
                for name, prop in inspect.getmembers(cls, self._is_dbus_property))
633
633
    
634
 
#    def _get_dbus_property(self, interface_name, property_name):
635
 
#        """Returns a bound method if one exists which is a D-Bus
636
 
#        property with the specified name and interface.
637
 
#        """
638
 
#        print("get_property({0!r}, {1!r}".format(interface_name, property_name),file=sys.stderr)
639
 
#        print(dir(self), sys.stderr)
640
 
#        for name in (property_name,
641
 
#                     property_name + "_dbus_property"):
642
 
#            prop = getattr(self, name, None)
643
 
#            if (prop is None
644
 
#                or not self._is_dbus_property(prop)
645
 
#                or prop._dbus_name != property_name
646
 
#                or (interface_name and prop._dbus_interface
647
 
#                    and interface_name != prop._dbus_interface)):
648
 
#                continue
649
 
#            return prop
650
 
#        # No such property
651
 
#        raise DBusPropertyNotFound(self.dbus_object_path + ":"
652
 
#                                   + interface_name + "."
653
 
#                                   + property_name)
654
 
 
655
634
    def _get_dbus_property(self, interface_name, property_name):
656
635
        """Returns a bound method if one exists which is a D-Bus
657
636
        property with the specified name and interface.
658
637
        """
659
 
        for name, value in inspect.getmembers(self, self._is_dbus_property):
660
 
            if value._dbus_name == property_name and value._dbus_interface == interface_name:
661
 
                return value
 
638
        for cls in  self.__class__.__mro__:
 
639
            for name, value in inspect.getmembers(cls, self._is_dbus_property):
 
640
                if value._dbus_name == property_name and value._dbus_interface == interface_name:
 
641
                    return value.__get__(self)
662
642
        
663
643
        # No such property
664
644
        raise DBusPropertyNotFound(self.dbus_object_path + ":"
775
755
    return dbus.String(dt.isoformat(),
776
756
                       variant_level=variant_level)
777
757
 
778
 
class transitional_clientdbus(DBusObjectWithProperties.__metaclass__):
 
758
class transitional_dbus_metaclass(DBusObjectWithProperties.__metaclass__):
779
759
    def __new__(mcs, name, bases, attr):
780
 
        for key, old_dbusobj in attr.items():
 
760
        for attrname, old_dbusobj in inspect.getmembers(bases[0]):
781
761
            new_interface = getattr(old_dbusobj, "_dbus_interface", "").replace("se.bsnet.fukt.", "se.recompile.")
782
 
            if getattr(old_dbusobj, "_dbus_is_signal", False):
 
762
            if (getattr(old_dbusobj, "_dbus_is_signal", False)
 
763
                and old_dbusobj._dbus_interface.startswith("se.bsnet.fukt.Mandos")):
783
764
                unwrappedfunc = dict(zip(old_dbusobj.func_code.co_freevars,
784
765
                                    old_dbusobj.__closure__))["func"].cell_contents
785
766
                newfunc = types.FunctionType(unwrappedfunc.func_code,
789
770
                                             unwrappedfunc.func_closure)
790
771
                new_dbusfunc = dbus.service.signal(
791
772
                    new_interface, old_dbusobj._dbus_signature)(newfunc)            
792
 
                attr["_transitional_{0}_1".format(key)] = new_dbusfunc
793
 
                attr["_transitional_{0}_0".format(key)] = old_dbusobj                
 
773
                attr["_transitional_" + attrname] = new_dbusfunc
 
774
 
794
775
                def fixscope(func1, func2):
795
776
                    def newcall(*args, **kwargs):
796
777
                        func1(*args, **kwargs)
797
778
                        func2(*args, **kwargs)
798
779
                    return newcall
799
780
 
800
 
                attr[key] = fixscope(
801
 
                    old_dbusobj, attr["_transitional_{0}_1".format(key)])
 
781
                attr[attrname] = fixscope(old_dbusobj, new_dbusfunc)
802
782
            
803
 
            if getattr(old_dbusobj, "_dbus_is_method", False):
 
783
            elif (getattr(old_dbusobj, "_dbus_is_method", False)
 
784
                and old_dbusobj._dbus_interface.startswith("se.bsnet.fukt.Mandos")):
804
785
                new_dbusfunc = (dbus.service.method
805
786
                                (new_interface,
806
787
                                 old_dbusobj._dbus_in_signature,
812
793
                                  old_dbusobj.func_defaults,
813
794
                                  old_dbusobj.func_closure)))
814
795
 
815
 
                attr["_transitional_{0}".format(key)] = new_dbusfunc
816
 
            if getattr(old_dbusobj, "_dbus_is_property", False):
 
796
                attr[attrname] = new_dbusfunc
 
797
            elif (getattr(old_dbusobj, "_dbus_is_property", False)
 
798
                  and old_dbusobj._dbus_interface.startswith("se.bsnet.fukt.Mandos")):
817
799
                new_dbusfunc = (dbus_service_property
818
800
                                (new_interface,
819
801
                                 old_dbusobj._dbus_signature,
826
808
                                  old_dbusobj.func_defaults,
827
809
                                  old_dbusobj.func_closure)))
828
810
 
829
 
                attr["_transitional_{0}".format(key)] = new_dbusfunc
 
811
                attr[attrname] = new_dbusfunc
830
812
        return type.__new__(mcs, name, bases, attr)
831
813
 
832
814
class ClientDBus(Client, DBusObjectWithProperties):
839
821
    
840
822
    runtime_expansions = (Client.runtime_expansions
841
823
                          + ("dbus_object_path",))
842
 
 
843
 
    __metaclass__ = transitional_clientdbus
844
824
    
845
825
    # dbus.service.Object doesn't use super(), so we can't either.
846
826
    
1246
1226
            return super(ProxyClient, self).__setattr__(name, value)
1247
1227
        self._pipe.send(('setattr', name, value))
1248
1228
 
 
1229
class ClientDBusTransitional(ClientDBus):
 
1230
    __metaclass__ = transitional_dbus_metaclass
1249
1231
 
1250
1232
class ClientHandler(socketserver.BaseRequestHandler, object):
1251
1233
    """A class to handle client connections.
1975
1957
    
1976
1958
    client_class = Client
1977
1959
    if use_dbus:
1978
 
        client_class = functools.partial(ClientDBus, bus = bus)
 
1960
        client_class = functools.partial(ClientDBusTransitional, bus = bus)        
1979
1961
    def client_config_items(config, section):
1980
1962
        special_settings = {
1981
1963
            "approved_by_default":
2068
2050
            
2069
2051
            del _interface
2070
2052
        
2071
 
        mandos_dbus_service = MandosDBusService()
 
2053
        class MandosDBusServiceTransitional(MandosDBusService):
 
2054
            __metaclass__ = transitional_dbus_metaclass
 
2055
        mandos_dbus_service = MandosDBusServiceTransitional()
2072
2056
    
2073
2057
    def cleanup():
2074
2058
        "Cleanup function; run on exit"