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.
|