[pkg-fso-commits] [SCM] framworkd debian packageing branch, master, updated. milestone2-89-geb27523
Michael 'Mickey' Lauer
mickey at vanille-media.de
Sat Aug 23 14:06:17 UTC 2008
The following commit has been merged in the master branch:
commit ab36a303e7429d790c2f38e3ea3f3a8dc97f33b1
Author: Michael 'Mickey' Lauer <mickey at vanille-media.de>
Date: Sun Aug 17 16:12:59 2008 +0200
license whitespace changes
diff --git a/framework/subsystems/oeventsd/action.py b/framework/subsystems/oeventsd/action.py
index a1fdb72..ce7774a 100644
--- a/framework/subsystems/oeventsd/action.py
+++ b/framework/subsystems/oeventsd/action.py
@@ -1,4 +1,3 @@
-
# -*- coding: UTF-8 -*-
"""
The freesmartphone Events Module - Python Implementation
@@ -21,7 +20,7 @@ class Action(object):
pass
def __call__(self, **kargs):
logger.info('%s called', self)
-
+
class DBusAction(Action):
"""A spetial action that will call a DBus method"""
@@ -39,7 +38,7 @@ class DBusAction(Action):
self.interface = interface
self.method = method
self.args = args
-
+
def __call__(self, **kargs):
# Get the Dbus object
object = self.bus.get_object(self.service, self.obj)
@@ -50,17 +49,17 @@ class DBusAction(Action):
# We make the call asynchronous, cause we don't want to block the main loop
kargs = {'reply_handler':self.on_reply, 'error_handler':self.on_error}
method(*self.args, **kargs)
-
+
def on_reply(self, *args):
# We don't pass the reply to anything
logger.info("signal %s responded : %s", self.method, args)
-
+
def on_error(self, error):
logger.error("signal %s emited an error %s", self.method, error)
-
+
def __repr__(self):
return "%s(%s)" % (self.method, self.args)
-
+
class AudioAction(DBusAction):
def __init__(self, file = None, action = 'play'):
bus = dbus.SystemBus()
@@ -69,7 +68,7 @@ class AudioAction(DBusAction):
interface = 'org.freesmartphone.Device.Audio'
method = 'PlaySound' if action == 'play' else 'StopSound'
super(AudioAction, self).__init__(bus, service, obj, interface, method, file)
-
+
class VibratorAction(DBusAction):
def __init__(self, target = 'neo1973_vibrator', action = 'start'):
bus = dbus.SystemBus()
diff --git a/framework/subsystems/oeventsd/filter.py b/framework/subsystems/oeventsd/filter.py
index fb939ab..8add43b 100644
--- a/framework/subsystems/oeventsd/filter.py
+++ b/framework/subsystems/oeventsd/filter.py
@@ -1,5 +1,4 @@
# -*- coding: UTF-8 -*-
-
"""
The freesmartphone Events Module - Python Implementation
@@ -10,30 +9,29 @@ The freesmartphone Events Module - Python Implementation
GPLv2 or later
"""
-
class Filter(object):
def __call__(self, **kargs):
raise NotImplementedError
-
+
def __invert__(self): # The ~ operator
return InvertFilter(self)
-
+
class AttributeFilter(Filter):
def __init__(self, **kargs):
self.kargs = kargs
def __call__(self, **kargs):
return all( key in kargs and kargs[key] == value for (key, value) in self.kargs.items() )
-
+
def __repr__(self):
return "and".join( "%s == %s" % (key, value) for (key, value) in self.kargs.items() )
-
+
class InvertFilter(Filter):
def __init__(self, filter):
super(InvertFilter, self).__init__()
self.filter = filter
def __call__(self, **kargs):
return not self.filter(**kargs)
-
+
def __repr__(self):
return "~(%s)" % self.filter
diff --git a/framework/subsystems/oeventsd/parser.py b/framework/subsystems/oeventsd/parser.py
index 31bbc7a..37f9d73 100644
--- a/framework/subsystems/oeventsd/parser.py
+++ b/framework/subsystems/oeventsd/parser.py
@@ -1,4 +1,3 @@
-
# -*- coding: UTF-8 -*-
"""
The freesmartphone Events Module - Python Implementation
@@ -33,11 +32,11 @@ class FunctionMetaClass(type):
class Function(object):
__metaclass__ = FunctionMetaClass
functions = {}
-
+
def __call__(self, *args):
raise NotImplementedError
-
-
+
+
def split_params(s):
""" An ugly way to parse function parameters
I should use a library for that
@@ -53,8 +52,8 @@ def split_params(s):
if s[i] == ',' and lev == 0:
return [s[:i]] + split_params(s[i+1:])
return [s]
-
-
+
+
# The following is used to be able to parse instructions on yaml
pattern = re.compile(r'^(.+?)\((.*?)\)$')
@@ -69,27 +68,27 @@ def function_constructor(loader, node):
yaml.add_constructor(u'!Function', function_constructor)
yaml.add_implicit_resolver(u'!Function', pattern)
-
+
class CallStatus(Function):
name = 'CallStatus'
def __call__(self):
return CallStatusTrigger()
-
+
class PlaySound(Function):
name = 'PlaySound'
def __call__(self, file):
return AudioAction(file, 'Play')
-
+
class StopSound(Function):
name = 'StopSound'
def __call__(self, file):
return AudioAction(file, 'Stop')
-
+
class RingTone(Function):
name = 'RingTone'
def __call__(self, cmd):
return RingToneAction(cmd)
-
+
class StartVibration(Function):
name = 'StartVibration'
def __call__(self):
@@ -99,12 +98,12 @@ class StopVibration(Function):
name = 'StopVibration'
def __call__(self):
return VibratorAction(action='Stop')
-
+
class Not(Function):
name = 'Not'
def __call__(self, a):
return ~a
-
+
class HasAttr(Function):
name = 'HasAttr'
def __call__(self, name, value):
@@ -117,7 +116,7 @@ def as_rule(r):
filters = r.get('filters', [])
actions = r['actions']
return Rule(trigger, filters, actions)
-
+
class Parser(object):
def parse_rules(self, src):
rules = yaml.load(src)
diff --git a/framework/subsystems/oeventsd/ring_tone_action.py b/framework/subsystems/oeventsd/ring_tone_action.py
index 59e4a30..70c0ec0 100644
--- a/framework/subsystems/oeventsd/ring_tone_action.py
+++ b/framework/subsystems/oeventsd/ring_tone_action.py
@@ -1,3 +1,13 @@
+# -*- coding: UTF-8 -*-
+"""
+The freesmartphone Events Module - Python Implementation
+
+(C) 2008 Michael 'Mickey' Lauer <mlauer at vanille-media.de>
+(C) 2008 Jan 'Shoragan' Lübbe <jluebbe at lasnet.de>
+(C) 2008 Guillaume 'Charlie' Chereau
+(C) 2008 Openmoko, Inc.
+GPLv2 or later
+"""
from action import Action, AudioAction, VibratorAction
import dbus
@@ -13,7 +23,7 @@ class RingToneAction(Action):
self.cmd = cmd
def __call__(self, **kargs):
logger.info("RingToneAction %s", self.cmd)
-
+
# First we need to get the ring-tone music :
# TODO: as soon as we have some sort of global get_object('Preferences')
# method we should use it instead of PreferencesManager.singleton
@@ -22,7 +32,7 @@ class RingToneAction(Action):
ring_tone = phone_prefs.GetValue('ring-tone')
ring_volume = phone_prefs.GetValue('ring-volume')
sound_path = os.path.join("/usr/share/sounds/", ring_tone)
-
+
if self.cmd == 'play':
logger.info("Start ringing : tone=%s, volume=%s", ring_tone, ring_volume)
AudioAction(sound_path, 'play')()
diff --git a/framework/subsystems/oeventsd/rule.py b/framework/subsystems/oeventsd/rule.py
index bedd3bf..8e51822 100644
--- a/framework/subsystems/oeventsd/rule.py
+++ b/framework/subsystems/oeventsd/rule.py
@@ -1,4 +1,3 @@
-
# -*- coding: UTF-8 -*-
"""
The freesmartphone Events Module - Python Implementation
@@ -20,21 +19,21 @@ from action import Action
class Rule(object):
"""Event Rule object
-
+
A Rule consist of :
- a trigger
- a list of filters
- a list of actions
-
+
The way it works is the following :
When the trigger is activated, and if all the filter match the signal emitted by the trigger,
The all the actions will be called.
-
- The signal is passed in form of keywords arguments in the __call__ method
+
+ The signal is passed in form of keywords arguments in the __call__ method
"""
def __init__(self, trigger, filters, actions):
"""Create a new rule
-
+
We need to call the init method of the rule before
it will actually be actvated
"""
@@ -42,20 +41,20 @@ class Rule(object):
filters = [filters]
if not isinstance(actions, list):
actions = [actions]
-
+
assert all(isinstance(x, Filter) for x in filters)
- assert all(isinstance(x, Action) for x in actions)
-
+ assert all(isinstance(x, Action) for x in actions)
+
self.trigger = trigger
trigger.connect(self)
self.filters = filters
self.actions = actions
-
+
logger.info("Creating new rule : %s", self)
-
+
def __repr__(self):
return "on %s if %s then %s" % (self.trigger, self.filters, self.actions)
-
+
def on_signal(self, **kargs):
# First we check that ALL the filters match the signal
if any(not filter(**kargs) for filter in self.filters):
@@ -63,10 +62,10 @@ class Rule(object):
# If it is the case, then we start all the actions
for c in self.actions:
c(**kargs)
-
+
def init(self):
"""After we call this method, the rule is active"""
logger.info("init rule : %s", self)
self.trigger.init()
-
+
diff --git a/framework/subsystems/oeventsd/trigger.py b/framework/subsystems/oeventsd/trigger.py
index 709806f..5148398 100644
--- a/framework/subsystems/oeventsd/trigger.py
+++ b/framework/subsystems/oeventsd/trigger.py
@@ -1,4 +1,3 @@
-
# -*- coding: UTF-8 -*-
"""
The freesmartphone Events Module - Python Implementation
@@ -17,39 +16,39 @@ import dbus
class Trigger(object):
"""A trigger is the initial event that will activate a rule.
-
+
When a trigger is activated, it call the rule __call__ method,
giving a set of keywork arguments (the signal attributes to the method)
Then the rule can decide to start or not its actions.
"""
- def __init__(self):
+ def __init__(self):
"""Create a new trigger
-
+
The trigger need to be initialized with the `init` method before
- it can trigger the connected rules
+ it can trigger the connected rules
"""
self.listeners = [] # List of rules that are triggered by this trigger
-
+
def connect(self, rule):
"""Connect the trigger to a rule
-
+
This method should only be called by the Rule class
- """
+ """
self.listeners.append(rule)
-
+
def __call__(self, **kargs):
"""Trigger all the connected rules"""
for rule in self.listeners:
rule.on_signal(**kargs)
-
+
def init(self):
"""initialize the trigger
-
+
The trigger won't trigger the connect rules before this
method has been called
"""
pass
-
+
class DBusTrigger(Trigger):
"""A special trigger that wait for a given DBus signal to trigger its rules"""
def __init__(self, bus, service, obj, interface, signal):
@@ -64,14 +63,14 @@ class DBusTrigger(Trigger):
self.obj = obj
self.interface = interface
self.signal = signal
-
+
def init(self):
# Connect to the DBus signal
object = self.bus.get_object(self.service, self.obj)
iface = dbus.Interface(object, dbus_interface=self.interface)
logger.info("connect trigger to dbus signal %s %s", self.obj, self.signal)
iface.connect_to_signal(self.signal, self.on_signal)
-
+
def on_signal(self, *args):
self(args=args)
@@ -89,7 +88,7 @@ class CallStatusTrigger(DBusTrigger):
def on_signal(self, id, status, properties):
logger.info("Receive CallStatus, status = %s", status)
self(id=id, status=status, properties=properties)
-
+
def __repr__(self):
return "CallStatus"
-
+
--
framworkd debian packageing
More information about the pkg-fso-commits
mailing list