Thread: SF.net SVN: fclient: [268] trunk/sandbox/fcp2/config.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <ju...@us...> - 2008-02-26 14:45:01
|
Revision: 268
http://fclient.svn.sourceforge.net/fclient/?rev=268&view=rev
Author: jurner
Date: 2008-02-26 06:45:05 -0800 (Tue, 26 Feb 2008)
Log Message:
-----------
moved ConfigValueClasses to consts
Modified Paths:
--------------
trunk/sandbox/fcp2/config.py
Modified: trunk/sandbox/fcp2/config.py
===================================================================
--- trunk/sandbox/fcp2/config.py 2008-02-26 14:43:43 UTC (rev 267)
+++ trunk/sandbox/fcp2/config.py 2008-02-26 14:45:05 UTC (rev 268)
@@ -1,5 +1,50 @@
-"""Sketch for fcp config tree"""
+"""Config handling
+Fcp passes the nodes config in form of a L{consts.Message.Config} message.
+This message can be fed to the L{Config} class to access the config tree.
+
+Fcp passes config settings as dotted names following this pattern:
+ValueClass.KeyName.SubkeyName.ValueName (...). The config class rebuilds the tree as
+a hirarchical tree of nodes with the L{Config} as root and L{ConfigItem}s as child nodes.
+Each L{ConfigItem} has a dict of child items and a values dict wich is a mapping from
+ValueName --> ValueClass0 ... ValueClassN.
+
+
+Sample code::
+
+ c = Config(configDataMsg=myConfigDataMessage)
+ configItem = c['settingsName.valueName']
+
+
+The config can be traversed like this::
+
+ for configItem in c.walk():
+ print configItem
+
+
+ConfigItems carry a values dict where the actual values for a key are stored.
+Values can be accessed by specifying the desired value class (see L{consts.ConfigValueClass})::
+
+ value, valueType = configItem.values[consts.ConfigValueClass.Current]
+
+ print configItem.values
+ >>> {
+ >>> 'current': ('whatever', <FcpTypeString>),
+ >>> 'default': ('whatever', <FcpTypeString>),
+ >>> 'valueType': ('string', <FcpTypeString>),
+ >>> (...)
+ >>> }
+
+ configItem.values[onsts.ConfigValueClass.Current] = 'another'
+ print configItem.values[consts.ConfigValueClass.Current][0]
+ >>> 'another'
+
+Note that Fcp passes some basic information about value types. This package does
+a bit more work and passes detailed information about the value type (as far as it is
+known) as one of the L{types.FcpType} subclasses. Unknown value types are passed
+as L{types.FcpType}.
+
+"""
import os, sys
import logging
@@ -55,6 +100,15 @@
out.reverse()
return types.ConfigMessageParams.ComponentSep.join(out)
+
+ def walk(self):
+ """Walks over the config item, returning the next L{ConfigItem} in turn"""
+ def walker(node):
+ yield node
+ for child in node.children.values():
+ for x in walker(child):
+ yield x
+ return walker(self)
#****************************************************************************************
#
@@ -67,14 +121,6 @@
@ivar children: (dict) child items
"""
- ValueClassCurrent = types.ConfigMessageParams.ParamClassCurrent
- ValueClassDefault = types.ConfigMessageParams.ParamClassDefault
- ValueClassExpertFlag = types.ConfigMessageParams.ParamClassExpertFlag
- ValueClassForceWriteFlag = types.ConfigMessageParams.ParamClassForceWriteFlag
- ValueClassShortDescription = types.ConfigMessageParams.ParamClassShortDescription
- ValueClassLongDescription = types.ConfigMessageParams.ParamClassLongDescription
-
-
def __init__(self, configDataMsg=None):
"""
@param configDataMsg: ConfigData message to initialize the config with or None
@@ -157,7 +203,7 @@
continue
key = node.key()
- result = node.values.get(self.ValueClassCurrent, None)
+ result = node.values.get(consts.ConfigValueClass.Current, None)
if result is not None:
out[key] = result[0]
return out
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-26 18:58:10
|
Revision: 280
http://fclient.svn.sourceforge.net/fclient/?rev=280&view=rev
Author: jurner
Date: 2008-02-26 10:52:56 -0800 (Tue, 26 Feb 2008)
Log Message:
-----------
moved config key sep to consts
Modified Paths:
--------------
trunk/sandbox/fcp2/config.py
Modified: trunk/sandbox/fcp2/config.py
===================================================================
--- trunk/sandbox/fcp2/config.py 2008-02-26 16:26:26 UTC (rev 279)
+++ trunk/sandbox/fcp2/config.py 2008-02-26 18:52:56 UTC (rev 280)
@@ -98,7 +98,7 @@
out.append(parent.name)
parent = parent.parent
out.reverse()
- return types.ConfigMessageParams.ComponentSep.join(out)
+ return consts.ConfigKeySep.join(out)
def walk(self):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-27 00:12:59
|
Revision: 284
http://fclient.svn.sourceforge.net/fclient/?rev=284&view=rev
Author: jurner
Date: 2008-02-26 16:13:02 -0800 (Tue, 26 Feb 2008)
Log Message:
-----------
beautifications
Modified Paths:
--------------
trunk/sandbox/fcp2/config.py
Modified: trunk/sandbox/fcp2/config.py
===================================================================
--- trunk/sandbox/fcp2/config.py 2008-02-26 19:00:14 UTC (rev 283)
+++ trunk/sandbox/fcp2/config.py 2008-02-27 00:13:02 UTC (rev 284)
@@ -70,10 +70,10 @@
class ConfigItem(object):
"""Config item
- @ivar parent: parent item
- @ivar name: name of the item
- @ivar children: (dict) child items
- @ivar values: dict of values
+ @ivar parent: (ConfigItem) parent item
+ @ivar name: (str) name of the item
+ @ivar children: (dict) child items (itemName --> ConfigItem)
+ @ivar values: (dict) values (L{consts.ConfigValueClass} --> value)
"""
@@ -116,9 +116,9 @@
class Config(object):
"""Class representing fcp config tree
- @ivar parent: parent item
- @ivar name: name of the config (always None)
- @ivar children: (dict) child items
+ @ivar parent: (always None) parent item
+ @ivar name: (always None) name of the config
+ @ivar children: (dict) child items (itemName --> L{ConfigItem})
"""
def __init__(self, configDataMsg=None):
@@ -159,7 +159,7 @@
@param value to associate
@return: (bool) True if the key has been added, False otherwise
- @note: if the item does not exist, it is created
+ @note: if the item does not already exist it is created
@note: if the key is unknown its type will always be set to L{types.FcpType}
"""
paramClass, components = self._configMessageParams.splitParamClass(key)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jU...@us...> - 2008-03-08 11:13:37
|
Revision: 342
http://fclient.svn.sourceforge.net/fclient/?rev=342&view=rev
Author: jUrner
Date: 2008-03-08 03:13:42 -0800 (Sat, 08 Mar 2008)
Log Message:
-----------
adapt to new message handling
Modified Paths:
--------------
trunk/sandbox/fcp2/config.py
Modified: trunk/sandbox/fcp2/config.py
===================================================================
--- trunk/sandbox/fcp2/config.py 2008-03-08 11:13:11 UTC (rev 341)
+++ trunk/sandbox/fcp2/config.py 2008-03-08 11:13:42 UTC (rev 342)
@@ -59,6 +59,7 @@
from fcp2 import consts
from fcp2 import types
+from fcp2 import message
from fcp2.fcp_lib import uuid
@@ -129,7 +130,6 @@
self.parent = None
self.name = None
self.children = {}
- self._configMessageParams = types.ConfigMessageParams()
self._log = logging.getLogger(consts.LoggerNames.Config)
if configDataMsg is not None:
@@ -162,14 +162,14 @@
@note: if the item does not already exist it is created
@note: if the key is unknown its type will always be set to L{types.FcpType}
"""
- paramClass, components = self._configMessageParams.splitParamClass(key)
- paramType = self._configMessageParams.get(key, None)
+ paramClass, components = message.ConfigMessageParamTypes.splitParamClass(key)
+ paramType = message.ConfigMessageParamTypes.get(key, None)
if paramType is None:
paramType = types.FcpType
self._log.warning('Unknown key: %r' % components)
# find or create new config item if necessary
- components = self._configMessageParams.splitAll(components)
+ components = message.ConfigMessageParamTypes.splitAll(components)
parent = self
for component in components:
item = parent.children.get(component, None)
@@ -187,8 +187,8 @@
@return: (str) key
@note: if the key does not contain the paramClass it is returned unchanged
"""
- head, tail = self._configMessageParams.splitParamClass(key)
- if head in self._configMessageParams.ParamClasses:
+ head, tail = message.ConfigMessageParamTypes.splitParamClass(key)
+ if head in message.ConfigMessageParamTypes.ParamClasses:
return tail
return tail
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jU...@us...> - 2008-04-09 07:45:03
|
Revision: 386
http://fclient.svn.sourceforge.net/fclient/?rev=386&view=rev
Author: jUrner
Date: 2008-04-09 00:45:07 -0700 (Wed, 09 Apr 2008)
Log Message:
-----------
moved more logging stuff to consts
Modified Paths:
--------------
trunk/sandbox/fcp2/config.py
Modified: trunk/sandbox/fcp2/config.py
===================================================================
--- trunk/sandbox/fcp2/config.py 2008-04-09 07:44:59 UTC (rev 385)
+++ trunk/sandbox/fcp2/config.py 2008-04-09 07:45:07 UTC (rev 386)
@@ -130,8 +130,7 @@
self.parent = None
self.name = None
self.children = {}
- self._log = logging.getLogger(consts.LoggerNames.Config)
-
+
if configDataMsg is not None:
for key, value in configDataMsg.params.items():
self.addNewValue(key, value)
@@ -166,7 +165,7 @@
paramType = message.ConfigMessageParamTypes.get(key, None)
if paramType is None:
paramType = types.FcpType
- self._log.warning('Unknown key: %r' % components)
+ consts.Logger.Config.warning('Unknown key: %r' % components)
# find or create new config item if necessary
components = message.ConfigMessageParamTypes.splitAll(components)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|