[pkg-fso-commits] [SCM] FSO frameworkd Debian packaging branch, master, updated. milestone4-368-g700ab82

Michael 'Mickey' Lauer mickey at vanille-media.de
Mon Feb 2 18:51:56 UTC 2009


The following commit has been merged in the master branch:
commit d56a275536f782e1fdd6a78bb634cb715025ac28
Author: Michael 'Mickey' Lauer <mickey at vanille-media.de>
Date:   Thu Jan 15 11:25:09 2009 +0100

    oeventsd: substitute super calls with the classic method of calling parent constructors
    super is considered harmful, at least in the present implementation. DO NOT USE IT, especially
    not not with multiple inheritance. Trust me, it's broken!

diff --git a/framework/subsystems/oeventsd/action.py b/framework/subsystems/oeventsd/action.py
index 6d7f827..f29ae61 100644
--- a/framework/subsystems/oeventsd/action.py
+++ b/framework/subsystems/oeventsd/action.py
@@ -11,60 +11,67 @@ Package: oeventsd
 Module: action
 """
 
+__version__ = "0.2.0"
+MODULE_NAME = "oeventsd.action"
+
 import dbus
 
 import logging
-logger = logging.getLogger('oeventsd')
+logger = logging.getLogger( MODULE_NAME )
 
 from parser import AutoFunction
 
-
 #============================================================================#
 class Action(AutoFunction):
 #============================================================================#
-    """Base class for Action objects
-    
+    """
+    Base class for Action objects
+
     An action has a `trigger` and `untrigger` methods.
-    By default the untirgger method will do nothing, but if it make sense, the action
+    By default the untrigger method will do nothing, but if it make sense, the action
     should define it.
     """
 
     def __init__(self):
-        pass
+        AutoFunction.__init__( self )
     def trigger(self, **kargs):
         """Perform the action"""
         pass
     def untrigger(self, **kargs):
-        """Undo anything that the action had performed""" 
+        """Undo anything that the action had performed"""
         pass
     def __repr__(self):
         return "unamed action"
-        
+
 #============================================================================#
 class ListAction(list, Action):
 #============================================================================#
-    """An action that will trigger a list of actions
-    
+    """
+    An action that will trigger a list of actions
+
     This is basicaly a script.
     """
     def __init__(self, actions):
         list.__init__(self, actions)
+        Action.__init__( self )
     def trigger(self, **kargs):
         for action in self:
             action.trigger(**kargs)
     def untrigger(self, **kargs):
         for action in self:
             action.untrigger(**kargs)
-            
+
 
 #============================================================================#
 class DebugAction(Action):
 #============================================================================#
-    """A special action for debugging purposes
+    """
+    A special action for debugging purposes
     """
     function_name = 'Debug'
 
     def __init__(self, msg):
+        Action.__init__( self )
         self.msg = msg
     def trigger(self, **kargs):
         logger.info("DebugAction : %s", self.msg)
@@ -74,10 +81,11 @@ class DebugAction(Action):
 #============================================================================#
 class DBusAction(Action):
 #============================================================================#
-    """A special action that will call a DBus method.
+    """
+    A special action that will call a DBus method.
     """
     def __init__(self, bus, service, obj, interface, method, *args):
-        super(DBusAction, self).__init__()
+        Action.__init__( self )
         self.bus = bus
         # some arguments checking
         assert isinstance(service, str)
diff --git a/framework/subsystems/oeventsd/filter.py b/framework/subsystems/oeventsd/filter.py
index 979dc9e..6e839b2 100644
--- a/framework/subsystems/oeventsd/filter.py
+++ b/framework/subsystems/oeventsd/filter.py
@@ -12,8 +12,11 @@ Module: filter
 
 """
 
+__version__ = "0.2.0"
+MODULE_NAME = "oeventsd.filter"
+
 import logging
-logger = logging.getLogger( "oeventsd" )
+logger = logging.getLogger( MODULE_NAME )
 
 #============================================================================#
 class Filter( object ):
@@ -24,7 +27,7 @@ class Filter( object ):
        will be called or not. When a rule is triggered, the trigger generate a dict
        of values, that can be later used by the filter.
 
-       All the filters need to implement the filter method, taking an arbitrary 
+       All the filters need to implement the filter method, taking an arbitrary
        number of keywords argument (**kargs) representing the event generated dict
        of values. The method returns True if the filter accept the event, False otherwise.
     """
@@ -38,23 +41,23 @@ class Filter( object ):
            The __invert__ method is called by the `~` operator.
         """
         return InvertFilter( self )
-        
+
     def __or__( self, f ):
         """Return a filter that is the logical OR operation between this filter and an other filter
         """
         return OrFilter( self, f )
-        
+
     def __and__( self, f ):
         return AndFilter( self, f )
-        
+
     def enable( self ):
         """enable the filter
-        
+
         This is used because some filter need to connect to external signals,
         e.g : WhileRule
         """
         pass
-        
+
     def disable( self ):
         """disable the filter"""
         pass
@@ -67,6 +70,7 @@ class AttributeFilter( Filter ):
     """
     def __init__( self, **kargs ):
         self.kargs = kargs
+
     def filter( self, **kargs ):
         return all( key in kargs and kargs[key] == value for (key, value) in self.kargs.items() )
 
@@ -78,37 +82,42 @@ class InvertFilter( Filter ):
 #============================================================================#
     """This filer returns the negation of the argument filter"""
     def __init__( self, filter ):
-        super( InvertFilter, self ).__init__()
+        Filter.__init__( self )
         self.__filter = filter
+
     def filter( self, **kargs ):
         return not self.__filter.filter( **kargs )
 
     def __repr__( self ):
         return "~(%s)" % self.__filter
-        
+
 #============================================================================#
 class AndFilter( Filter ):
 #============================================================================#
     """This filter returns the AND logical operation between a list of filters"""
     def __init__( self, *filters ):
-        super( AndFilter, self ).__init__()
+        Filter.__init__( self )
         assert all( isinstance( f, Filter ) for f in filters )
         self.filters = filters
+
     def filter( self, **kargs ):
         return all( f.filter( **kargs ) for f in self.filters )
+
     def __repr__( self ):
         return "And(%s)" % ','.join( str( f ) for f in self.filters )
-        
+
 #============================================================================#
 class OrFilter( Filter ):
 #============================================================================#
     """This filter returns the OR logical operation between a list of filters"""
     def __init__( self, *filters ):
-        super( OrFilter, self ).__init__()
+        Filter.__init__( self )
         assert all( isinstance( f, Filter ) for f in filters )
         self.filters = filters
+
     def filter( self, **kargs ):
         return any( f.filter( **kargs ) for f in self.filters )
+
     def __repr__( self ):
         return "Or(%s)" % ','.join( str( f ) for f in self.filters )
 
diff --git a/framework/subsystems/oeventsd/rule.py b/framework/subsystems/oeventsd/rule.py
index 90b5f09..1d00e13 100644
--- a/framework/subsystems/oeventsd/rule.py
+++ b/framework/subsystems/oeventsd/rule.py
@@ -20,26 +20,27 @@ from trigger import Trigger
 class Rule( Trigger, Action ):
 #============================================================================#
     """A Rule is a link betwen a trigger and an action, that can check for conditions
-    
+
     Using rule we can refine the behavior of a trigger by giving a filter.
     When the rule is triggered it will trigger the action only if its filter
     allow it.
     """
     def __init__( self, trigger, filter = Filter(), action = Action(), name = "" ):
         """Create a new rule given a trigger, a filter and an action
-        
+
         We can give a list of action or a list of filter instead of a single
         action or filter, in that case the actions will be turned into a ListAction
-        and the filters into an AndFilter. 
+        and the filters into an AndFilter.
         """
-        super( Rule, self ).__init__()
-        
+        Trigger.__init__( self )
+        Action.__init__( self )
+
         # We accept list OR single value as argument
         if isinstance( filter, list ):
             filter = AndFilter( *filter )
         if isinstance( action, list ):
             action = ListAction( action )
-            
+
         assert isinstance(trigger, Trigger)
         assert isinstance(action, Action)
         assert isinstance(filter, Filter)
@@ -47,7 +48,7 @@ class Rule( Trigger, Action ):
         self.__trigger = trigger
         # The trigger will call this rule when triggered
         trigger.connect( self )
-        
+
         self.__filter = filter
         self.__action = action
         self.connect( action )
@@ -63,6 +64,7 @@ class Rule( Trigger, Action ):
         # First we check that ALL the filters match the signal
         if not self.__filter.filter( **kargs ):
             return False
+        # FIXME: _trigger ???
         self._trigger( **kargs )
         return True
 
@@ -71,45 +73,45 @@ class Rule( Trigger, Action ):
         logger.info( "enable rule : %s", self )
         self.__trigger.enable()
         self.__filter.enable()
-        
+
     def disable( self ):
         # It should be enough to disable the trigger and the filter
         logger.info( "disable rule : %s", self )
         self.__trigger.disable()
         self.__filter.disable()
-        
+
 #============================================================================#
 class WhileRule( Rule, Filter ):
 #============================================================================#
     """Special Rule that will also untrigger its action
-    
+
     We can also use a WhileRule as a filter, the condition is then true if the
-    rule is currently triggered. 
-    """ 
+    rule is currently triggered.
+    """
     def __init__( self, *args ):
-        super( WhileRule, self ).__init__( *args )
+        Rule.__init__( self, *args )
+        Filter.__init__( self, *args )
         self.triggered = False
+
     def trigger( self, **kargs ):
         if self.triggered:
             if not self._Rule__filter.filter( **kargs ):
                 self.untrigger( **kargs )
         else:
             self.triggered = super( WhileRule, self ).trigger( **kargs )
-                
+
     def untrigger( self, **kargs ):
         if not self.triggered:
             return
         self._untrigger( **kargs )
         self.triggered = False
-        
+
     def filter( self, **kargs ):
         """The filter is True if the rule is triggered"""
         return self.triggered
-        
+
     def __repr__( self ):
         if self.name:
             return "'%s'" % self.name
         return "While %s if %s then %s" % ( self._Rule__trigger, self._Rule__filter, self._Rule__action )
 
-
-
diff --git a/framework/subsystems/oeventsd/trigger.py b/framework/subsystems/oeventsd/trigger.py
index 840fbc8..cd5abf5 100644
--- a/framework/subsystems/oeventsd/trigger.py
+++ b/framework/subsystems/oeventsd/trigger.py
@@ -10,72 +10,87 @@ Package: oeventsd
 Module: trigger
 """
 
-import logging
-logger = logging.getLogger('oeventsd')
+__version__ = "0.2.0"
+MODULE_NAME = "oeventsd.trigger"
+
+from parser import AutoFunction
 
 import dbus
 
-from parser import AutoFunction
+import logging
+logger = logging.getLogger( MODULE_NAME )
 
 #============================================================================#
 class Trigger(AutoFunction):
 #============================================================================#
-    """A trigger is the initial event that can activate a rule.
-
-       When a trigger is activated, it call the rule `trigger` method,
-       giving a set of keywork arguments (the signal attributes to the method)
-       Then the rule can decide to start or not its actions.
-       
-       A trigger can also optionaly have a an `untrigger` method. This method will
-       call the `untrigger` method of the connected rules.
+    """
+    A trigger is the initial event that can activate a rule.
+
+    When a trigger is activated, it call the rule `trigger` method,
+    giving a set of keywork arguments (the signal attributes to the method)
+    Then the rule can decide to start or not its actions.
+
+    A trigger can also optionaly have a an `untrigger` method. This method will
+    call the `untrigger` method of the connected rules.
     """
 
     def __init__(self):
-        """Create a new trigger
+        """
+        Create a new trigger
 
-           The trigger need to be initialized with the `init` method before
-           it can trigger the connected rules
+        The trigger need to be initialized with the `init` method before
+        it can trigger the connected rules
         """
         self.__listeners = []     # List of rules that are triggered by this trigger
 
     def connect(self, action):
-        """Connect the trigger to an action
+        """
+        Connect the trigger to an action
 
-           This method should only be called by the Rule class
+        This method should only be called by the Rule class
         """
         self.__listeners.append(action)
 
     def _trigger(self, **kargs):
-        """Trigger all the connected rules"""
+        """
+        Trigger all the connected rules
+        """
         logger.debug("trigger %s", self)
         for action in self.__listeners:
-            action.trigger(**kargs)
-            
+            action._trigger(**kargs)
+
     def _untrigger(self, **kargs):
-        """untrigger all the connected rules"""
+        """
+        Untrigger all the connected rules
+        """
         logger.debug("untrigger %s", self)
         for action in self.__listeners:
-            action.untrigger(**kargs)
+            action._untrigger(**kargs)
 
     def enable(self):
-        """Enable the trigger
+        """
+        Enable the trigger
 
-           The trigger won't trigger the connect rules before this
-           method has been called
+        The trigger won't trigger the connect rules before this
+        method has been called
         """
         pass
-        
+
     def disable(self):
-        """Disable the trigger"""
+        """
+        Disable the trigger
+        """
         pass
 
 
 #============================================================================#
 class DBusTrigger(Trigger):
 #============================================================================#
-    """A special trigger that waits for a given DBus signal to trigger its rules"""
+    """
+    A special trigger that waits for a given DBus signal to trigger its rules
+    """
     function_name = 'DbusTrigger'
-    
+
     def __init__(self, bus, service, obj, interface, signal):
         """Create the DBus trigger
 
@@ -87,7 +102,7 @@ class DBusTrigger(Trigger):
         - signal    the DBus name of the signal
 
         """
-        super(DBusTrigger, self).__init__()
+        Trigger.__init__( self )
         # some arguments checking
         if isinstance(bus, str):
             if bus == 'system':
@@ -98,7 +113,7 @@ class DBusTrigger(Trigger):
                 raise TypeError("Bad dbus bus : %s" % bus)
         if not obj:
             obj = None
-            
+
         assert isinstance(service, str), "service is not str"
         assert obj is None or isinstance(obj, str), "obj is not str or None"
         assert isinstance(interface, str), "interface is not str"
@@ -109,12 +124,12 @@ class DBusTrigger(Trigger):
         self.interface = interface
         self.signal = signal
         self.dbus_match = None
-        
+
     def __repr__(self):
         return "DBusTrigger(%s %s.%s)" % (self.service, self.obj, self.signal)
 
     def enable(self):
-        if self.dbus_match is not None: # if the rule is already enabled we do nothing 
+        if self.dbus_match is not None: # if the rule is already enabled we do nothing
             return
         # Connect to the DBus signal
         logger.debug("connect trigger to dbus signal %s %s", self.obj, self.signal)
@@ -123,9 +138,9 @@ class DBusTrigger(Trigger):
             dbus_interface=self.interface,
             signal_name=self.signal
         )
-        
+
     def disable(self):
-        if self.dbus_match is None: # if the rule is already disabled we do nothing 
+        if self.dbus_match is None: # if the rule is already disabled we do nothing
             return
         self.dbus_match.remove()
         self.dbus_match = None
@@ -137,16 +152,17 @@ class DBusTrigger(Trigger):
 #============================================================================#
 class TestTrigger( Trigger ):
 #============================================================================#
-    """This trigger can be used ot debug the events system.
-    
+    """
+    This trigger can be used ot debug the events system.
+
     It is triggered when oeventsd.TriggerTest method is called
     """
     function_name = "Test"
-    
+
     def __init__( self, name ):
-        super( TestTrigger, self ).__init__()
+        Trigger.__init__( self )
         self.name = name
-        
+
     def __repr__( self ):
         return "Test(%s)" % self.name
-    
+

-- 
FSO frameworkd Debian packaging



More information about the pkg-fso-commits mailing list