[pkg-fso-commits] [SCM] framworkd debian packageing branch, master, updated. milestone2-89-geb27523

Guillaume Chereau (none) charlie at nikopol.
Sat Aug 23 14:06:15 UTC 2008


The following commit has been merged in the master branch:
commit ac33ed13414b69bc53a5009c3583180d5c52b7c3
Author: Guillaume Chereau <charlie at nikopol.(none)>
Date:   Mon Aug 11 14:42:07 2008 +0800

    [opreferncesd] Added phone configurations

diff --git a/etc/freesmartphone/opreferences/conf/phone/default.yaml b/etc/freesmartphone/opreferences/conf/phone/default.yaml
new file mode 100644
index 0000000..34b86ff
--- /dev/null
+++ b/etc/freesmartphone/opreferences/conf/phone/default.yaml
@@ -0,0 +1,6 @@
+
+# Those values are just here to test the preferences service,
+# They are not actually used yet
+ring-tone: "music1"
+ring-volume: 10
+
diff --git a/etc/freesmartphone/opreferences/conf/phone/silent.yaml b/etc/freesmartphone/opreferences/conf/phone/silent.yaml
new file mode 100644
index 0000000..4d4bbea
--- /dev/null
+++ b/etc/freesmartphone/opreferences/conf/phone/silent.yaml
@@ -0,0 +1,5 @@
+
+# Those values are just here to test the preferences service,
+# They are not actually used yet
+
+ring-volume: 0
diff --git a/etc/freesmartphone/opreferences/schema/phone.yaml b/etc/freesmartphone/opreferences/schema/phone.yaml
new file mode 100644
index 0000000..0020b72
--- /dev/null
+++ b/etc/freesmartphone/opreferences/schema/phone.yaml
@@ -0,0 +1,10 @@
+
+
+ring-tone:
+    type: str
+    profilable: yes
+    
+ring-volume:
+    type: int
+    profilable: yes
+    default: 10
diff --git a/framework/subsystems/opreferencesd/opreferences.py b/framework/subsystems/opreferencesd/opreferences.py
index c862e6c..edf1997 100644
--- a/framework/subsystems/opreferencesd/opreferences.py
+++ b/framework/subsystems/opreferencesd/opreferences.py
@@ -43,9 +43,11 @@ class PreferencesManager(dbus.service.Object):
         self.bus = bus
         self.schema_dir = schema_dir
         self.conf_dir = conf_dir
-        self.profile = 'default'
+        self.profiles = ['default']
         self.services = {}
         
+        logger.info("using schema path : %s", schema_dir)
+        logger.info("using conf path : %s", conf_dir)
         logger.info("initialized, services : %s", self.GetServices()) 
         
     @dbus.service.method("org.freesmartphone.Preferences", in_signature='', out_signature='as')
@@ -72,14 +74,14 @@ class PreferencesManager(dbus.service.Object):
             ret = Service(self, name)
         except NoServiceError:
             logger.info("service does not exist : %s", name)
-            raise DBusNoServiceError
+            raise DBusNoServiceError, name
         self.services[name] = ret
         return ret
         
     @dbus.service.method("org.freesmartphone.Preferences", in_signature='', out_signature='s')
     def GetProfile(self):
-        """Retrieve the current profile"""
-        return self.profile
+        """Retrieve the current top profile"""
+        return self.profiles[0]
     
     @dbus.service.method("org.freesmartphone.Preferences", in_signature='s', out_signature='')
     def SetProfile(self, profile):
@@ -87,7 +89,7 @@ class PreferencesManager(dbus.service.Object):
         logger.debug("SetProfile to %s", profile)
         profile = str(profile)
         assert profile in self.GetProfiles()
-        self.profile = profile
+        self.profiles = [profile, 'default']
         for s in self.services.itervalues():
             s.on_profile_changed(profile)
         
diff --git a/framework/subsystems/opreferencesd/schema.py b/framework/subsystems/opreferencesd/schema.py
index 4f8c310..bd52cfe 100644
--- a/framework/subsystems/opreferencesd/schema.py
+++ b/framework/subsystems/opreferencesd/schema.py
@@ -81,6 +81,8 @@ class Parameter(object):
         if self.type == str: return dbus.String(v)
         if self.type == bool: return dbus.Boolean(v)
         if self.type == object: return v
+        if v is None:
+            return ''
         raise TypeError, "can't convert parameter of type %s to dbus object" % self.type
         
 class DictParameter(Parameter):
diff --git a/framework/subsystems/opreferencesd/service.py b/framework/subsystems/opreferencesd/service.py
index 465d65c..ac6749f 100644
--- a/framework/subsystems/opreferencesd/service.py
+++ b/framework/subsystems/opreferencesd/service.py
@@ -6,6 +6,9 @@ import dbus.service
 from schema import Schema
 from configuration import Configuration
 
+import logging
+logger = logging.getLogger('opreferencesd')
+
 class NoServiceError(Exception):
     pass
 
@@ -48,10 +51,11 @@ class Service(dbus.service.Object):
         if profile in self.confs:
             return self.confs[profile]
         try:
-            conf = Configuration('%s/%s/%s.yaml' % (self.manager.conf_dir, self.name, profile))
-        except Exception, e:
-            print "can't parse the conf file : '%s/%s/%s.yaml : %s'" % (self.manager.conf_dir, self.name, profile, e)
-            return None
+            conf_path = '%s/%s/%s.yaml' % (self.manager.conf_dir, self.name, profile)
+            conf = Configuration(conf_path)
+        except IOError:
+            logger.info("no conf file : '%s'", conf_path)
+            conf = None
         self.confs[profile] = conf
         return conf
         
@@ -76,16 +80,21 @@ class Service(dbus.service.Object):
            key -- the name of the key
         """
         key = str(key)
-        # logger.debug("Service %s : Getting key %s", self, key)
+        logger.debug("Service %s : Getting key %s", self, key)
         parameter = self.schema[key]
-        profile = self.manager.profile if parameter.profilable else 'default'
-        try:
-            conf = self.get_conf(profile)
-            ret = conf[key]
-        except:
-            # print "Service %s : can't find key %s, using default" % (self, key) 
+        for profile in self.manager.profiles:
+            try:
+                conf = self.get_conf(profile)
+                if not conf:    # There is no conf file for this profile
+                    continue
+                ret = conf[key]
+                break
+            except KeyError:
+                pass
+        else:
+            logger.info("Service %s : can't find key %s, using default", self, key) 
             ret = parameter.default
-        # print "Service %s : value = %s" % (self, ret) 
+        # We have to call this method to give the proper type to the ret value
         ret = parameter.dbus(ret)
         return ret
     
@@ -94,9 +103,12 @@ class Service(dbus.service.Object):
         """set a parameter value for a service, in the current profile"""
         key = str(key)
         
-        # logger.debug("Service %s : Setting key %s = %s", self, key, value)
+        logger.debug("Service %s : Setting key %s = %s", self, key, value)
         parameter = self.schema[key]
-        profile = self.manager.profile if parameter.profilable else 'default'
+        # XXX:
+        # Here we always set the value into the top profile configuration file
+        # Shouldn't we use the profile that actually defines the value if there is one ?
+        profile = self.manager.profiles[0] if parameter.profilable else 'default'
         try:
             value = parameter.type(value)
         except:

-- 
framworkd debian packageing



More information about the pkg-fso-commits mailing list