/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 13:45:45 UTC
  • mto: This revision was merged to the branch mainline in revision 505.
  • Revision ID: belorn@fukt.bsnet.se-20111002134545-oytmfbl15r8lsm6p
working transition code for going between se.bsnet.fukt to se.recompile

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