Thread: SF.net SVN: fclient: [92] trunk/sandbox/fcp/fcp2_0_config.py
Status: Pre-Alpha
Brought to you by:
jurner
From: <ju...@us...> - 2008-01-30 14:35:57
|
Revision: 92 http://fclient.svn.sourceforge.net/fclient/?rev=92&view=rev Author: jurner Date: 2008-01-30 06:35:57 -0800 (Wed, 30 Jan 2008) Log Message: ----------- re Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_config.py Modified: trunk/sandbox/fcp/fcp2_0_config.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_config.py 2008-01-30 14:35:33 UTC (rev 91) +++ trunk/sandbox/fcp/fcp2_0_config.py 2008-01-30 14:35:57 UTC (rev 92) @@ -1,5 +1,7 @@ """Sketch for fcp config tree""" + +from fcp2_0_consts import ConfigMessageParams #**************************************************************************************** # #**************************************************************************************** @@ -26,242 +28,15 @@ # #**************************************************************************************** class Config(object): - """Class representing fcp config tree - """ - #{'current': {'valueType': (8, None), 'allowedHosts': 'true'}, 'default': {'valueType': (8, None), 'allowedHosts': 'true'}} - - ValueClassCurrent = 'current' - ValueClassDefault = 'default' - ValueClassExpertFlag = 'expertFlag' - ValueClassForceWriteFlag = 'forceWriteFlag' - ValueClassShortDescription = 'shortDescription' - ValueClassLongDescription = 'longDescription' - ValueClassSortOrder = 'sortOrder' - ValueClassType = 'valueType' - - ValueClassesFcp = ( - ValueClassDefault, - ValueClassExpertFlag, - ValueClassForceWriteFlag, - ValueClassShortDescription, - ValueClassLongDescription, - ) - ValueClassAll = ValueClassesFcp + (ValueClassType, ) - - - ValueTypeUnknown = 0 - ValueTypeBool = 1 - ValueTypeInt = 2 # params: LowerLimit, UpperLimit - ValueTypeBytes = 3 # may have params: LowerLimit, UpperLimit - ValueTypeFilename = 4 - ValueTypeDirname = 5 - ValueTypePort = 6 - ValueTypeIP = 7 - ValueTypeIPList = 8 - ValueTypeChoice = 9 - ValueTypeChoiceDirname = 10 - ValueTypePercent = 11 - ValueTypeString = 12 - ValueTypeUri = 13 - ValueTypeStringList = 14 - - - class ChoiceFProxyCss: - Clean = 'Clean' - Boxed = 'boxed' - GrayAndBlue = 'grayandblue' - Sky = 'sky' - - ChoicesAll = (Clean, Boxed, GrayAndBlue, Sky) - ChoicesAllowMultiple = False - - class ChoiceLoggerPriority: - Error = 'ERROR' - Normal = 'NORMAL' - Minor = 'MINOR' - Debug = 'DEBUG' - - ChoicesAll = (Error, Normal, Minor, Debug) - ChoicesAllowMultiple = False - - class ChoiceNodeDownloadAllowedDirs: - All = 'all' - Downloads = 'downloads' - Nowhere = '' - - ChoicesAll = (All, Downloads, Nowhere) - ChoicesAllowMultiple = False - - class ChoiceNodeUploadAllowedDirs: - All = 'all' - Nowhere = '' - ChoicesAll = (All, Nowhere) - ChoicesAllowMultiple = False - - class ChoicePriorityPolicy: - Hard = 'HARD' - Soft = 'SOFT' - - ChoicesAll = (Hard, Soft) - ChoicesAllowMultiple = False - - - class ChoiceSSLVersion: - Stl = 'STL' - SslV3 = 'SSLV3' - TlsV1 = 'TLSv1' - - ChoicesAll = (Stl, SslV3, TlsV1) - ChoicesAllowMultiple = False - - - KeyConsole = 'console' - KeyFcp = 'fcp' - KeyFproxy = 'fproxy' - KeyLogger = 'logger' - KeyNode = 'node' - KeyNodeLoad = 'node.load' - KeyNodeOpennet = 'node.opennet' - KeyNodeScheduler = 'node.scheduler' - KeyNodeUpdaterer = 'node.updater' - KeyPluginmanager = 'pluginmanager' - KeyPluginmanager2 = 'pluginmanager2' - KeySSL = 'ssl' - KeyToadletSymlinker = 'toadletsymlinker' - - Keys = { - - 'console.allowedHosts': (ValueTypeIPList, None), # host names, single IPs CIDR-maskip IPs likee 192.168.0.0/24 - 'console.bindTo': (ValueTypeIPList, None), - 'console.directEnabled': (ValueTypeBool, None), - 'console.enabled': (ValueTypeBool, None), - 'console.port': (ValueTypePort, None), - 'console.ssl': (ValueTypeBool, None), - - - 'fcp.allowedHosts': (ValueTypeIPList, None), - 'fcp.allowedHostsFullAccess': (ValueTypeIPList, None), - 'fcp.assumeDownloadDDAIsAllowed': (ValueTypeBool, None), - 'fcp.assumeUploadDDAIsAllowed': (ValueTypeBool, None), - 'fcp.bindTo': (ValueTypeIP, None), - 'fcp.enabled': (ValueTypeBool, None), - 'fcp.persistentDownloadsEnabled': (ValueTypeBool, None), - 'fcp.persistentDownloadsFile': (ValueTypeFilename, None), - 'fcp.persistentDownloadsInterval': (ValueTypeInt, (0, None)), - 'fcp.port': (ValueTypePort, None), - 'fcp.ssl': (ValueTypeBool, None), - - - 'fproxy.CSSOverride': (ValueTypeBool, None), - 'fproxy.advancedModeEnabled': (ValueTypeBool, None), - 'fproxy.allowedHosts': (ValueTypeIPList, None), - 'fproxy.allowedHostsFullAccess': (ValueTypeIPList, None), - 'fproxy.bindTo': (ValueTypeIPList, None), - 'fproxy.css': (ValueTypeChoice, ChoiceFProxyCss), - 'fproxy.doRobots': (ValueTypeBool, None), - 'fproxy.enabled': (ValueTypeBool, None), - 'fproxy.javascriptEnabled': (ValueTypeBool, None), - 'fproxy.port': (ValueTypePort, None), - 'fproxy.showPanicButton': (ValueTypeBool, None), - 'fproxy.ssl': (ValueTypeBool, None), - - - 'logger.dirname': (ValueTypeDirname, None), - 'logger.enabled': (ValueTypeBool, None), - 'logger.interval': (ValueTypeUnknown, None), # ??? 1HOUR ?? - 'logger.maxCachedBytes': (ValueTypeBytes, None), - 'logger.maxCachedLines': (ValueTypeInt, (0, None)), # ??? - 'logger.maxZippedLogsSize': (ValueTypeBytes, None), # ??? - 'logger.priority': (ValueTypeChoice, ChoiceLoggerPriority), - 'logger.priorityDetail': (ValueTypeUnknown, None), # ???? Detailed priority thresholds - - - 'node.alwaysAllowLocalAddresses': (ValueTypeBool, None), - 'node.assumeNATed': (ValueTypeBool, None), - 'node.bindTo': (ValueTypeIP, None), - 'node.clientThrottleFile': (ValueTypeFilename, None), - 'node.databaseMaxMemory': (ValueTypeBytes, None), - 'node.disableHangCheckers':( ValueTypeBool, None), - 'node.disableProbabilisticHTLs': (ValueTypeBool, None), - 'node.downloadAllowedDirs': (ValueTypeChoiceDirname, ChoiceNodeDownloadAllowedDirs), - 'node.downloadsDir': (ValueTypeDirname, None), - 'node.extraPeerDataDir': (ValueTypeDirname, None), - 'node.includeLocalAddressesInNoderefs': (ValueTypeBool, None), - 'node.inputBandwidthLimit': (ValueTypeBytes, (-1, None) ), - 'node.ipAddressOverride': (ValueTypeIP, None), - 'node.l10n': (ValueTypeUnknown, None), # ??? - 'node.lazyResume': (ValueTypeBool, None), - 'node.listenPort': (ValueTypePort, None), - 'node.maxBackgroundUSKFetchers': (ValueTypeInt, (0, None) ), - 'node.maxHTL': (ValueTypeInt, (0, None) ), - 'node.name': (ValueTypeString, None), - 'node.nodeDir': (ValueTypeDirname, None), - 'node.oneConnectionPerIP': (ValueTypeBool, None), - 'node.outputBandwidthLimit': (ValueTypeBytes, None), - 'node.passOpennetPeersThroughDarknet': (ValueTypeBool, None), - 'node.persistentTempDir': (ValueTypeDirname, None), - 'node.storeDir': (ValueTypeDirname, None), - 'node.storeForceBigShrinks': (ValueTypeBool, None), - 'node.storeSize': (ValueTypeBytes, None), - 'node.tempDir': (ValueTypeDirname, None), - 'node.tempIPAddressHint': (ValueTypeIP, None), # ??? - 'node.testingDropPacketsEvery': (ValueTypeInt, (0, None) ), - 'node.uploadAllowedDirs': (ValueTypeChoiceDirname, ChoiceNodeDownloadAllowedDirs), - - - 'node.testnet.enabled': (ValueTypeBool, None), - - 'node.load.aggressiveGC': (ValueTypeUnknown, None), # ??? - 'node.load.freeHeapBytesThreshold': (ValueTypeBytes, None), - 'node.load.freeHeapPercentThreshold': (ValueTypePercent, None), - 'node.load.memoryChecker': (ValueTypeBool, None), - 'node.load.nodeThrottleFile': (ValueTypeFilename, None), - 'node.load.threadLimit': (ValueTypeInt, (0, None) ), - - - 'node.opennet.acceptSeedConnections': (ValueTypeBool, None), - 'node.opennet.alwaysAllowLocalAddresses': (ValueTypeBool, None), - 'node.opennet.assumeNATed': (ValueTypeBool, None), - 'node.opennet.bindTo': (ValueTypeIP, None), - 'node.opennet.enabled': (ValueTypeBool, None), - 'node.opennet.listenPort': (ValueTypePort, None), - 'node.opennet.maxOpennetPeers': (ValueTypeInt, (0, None) ), - 'node.opennet.oneConnectionPerIP': (ValueTypeBool, None), - 'node.opennet.testingDropPacketsEvery': (ValueTypeInt, (0, None)), - - 'node.scheduler.CHKinserter_priority_policy': (ValueTypeChoice, ChoicePriorityPolicy), - 'node.scheduler.CHKrequester_priority_policy': (ValueTypeChoice, ChoicePriorityPolicy), - 'node.scheduler.SSKinserter_priority_policy': (ValueTypeChoice, ChoicePriorityPolicy), - 'node.scheduler.SSKrequester_priority_policy': (ValueTypeChoice, ChoicePriorityPolicy), - - 'node.updater.URI': (ValueTypeUri, None), - 'node.updater.autoupdate': (ValueTypeBool, None), - 'node.updater.enabled': (ValueTypeBool, None), - 'node.updater.extURI': (ValueTypeUri, None), - 'node.updater.revocationURI': (ValueTypeUri, None), - - - 'pluginmanager.loadplugin': (ValueTypeStringList, None), - 'pluginmanager2.loadedPlugins': (ValueTypeStringList, None), - - - 'ssl.sslEnable': (ValueTypeBool, None), - 'ssl.sslKeyPass': (ValueTypeString, None), - 'ssl.sslKeyStore': (ValueTypeFilename, None), - 'ssl.sslKeyStorePass': (ValueTypeString, None), - 'ssl.sslVersion': (ValueTypeChoice, ChoiceSSLVersion), - - 'toadletsymlinker.symlinks': (ValueTypeStringList, None), - } - - def __init__(self, configDataMsg=None): self.parent = None self.name = None self.children = {} + self.values = {} # for consistency + self.configMessageParams = ConfigMessageParams() if configDataMsg is not None: for key, value in configDataMsg.params.items(): @@ -281,15 +56,14 @@ return parent - def __setitem__(self, key, value): - valueClass, components = key.split('.', 1) - valueType = self.Keys.get(components, None) - components, valueName = components.rsplit('.', 1) - components = components.split('.') + paramClass, components = self.configMessageParams.splitParamClass(key) + paramType = self.configMessageParams.get(key, None) + components = self.configMessageParams.splitAll(components) + valueName = components.pop() - #TODO: how to handle undefinmed keys? - if valueType is None: + #TODO: how to handle non existent keys? + if paramType is None: # log somehow return False @@ -307,12 +81,10 @@ if values is None: values = {} parent.values[valueName] = values - values[self.ValueClassType] = valueType - values[valueClass] = value + values[paramClass] = (value, paramType) return True - - + def walk(self): def walker(node): @@ -322,6 +94,7 @@ yield x return walker(self) + def key(self): return None This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-01-30 17:16:35
|
Revision: 94 http://fclient.svn.sourceforge.net/fclient/?rev=94&view=rev Author: jurner Date: 2008-01-30 09:16:34 -0800 (Wed, 30 Jan 2008) Log Message: ----------- refactored and a few fixes Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_config.py Modified: trunk/sandbox/fcp/fcp2_0_config.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_config.py 2008-01-30 14:36:38 UTC (rev 93) +++ trunk/sandbox/fcp/fcp2_0_config.py 2008-01-30 17:16:34 UTC (rev 94) @@ -6,14 +6,28 @@ # #**************************************************************************************** class ConfigItem(object): + """Config item""" + def __init__(self, parent, name): + """ + @param parent: parent item + @param name: name of the item + + @ivar parent: parent item + @ivar name: name of the item + @ivar children: (dict) child items + @ivar values: dict of values + """ self.parent = parent self.name = name self.children = {} self.values = {} def key(self): + """Returns the key of the config item + @return: (str) key + """ out = [] parent = self while parent is not None: @@ -21,7 +35,7 @@ out.append(parent.name) parent = parent.parent out.reverse() - return '.'.join(out) + return ConfigMessageParams.ComponentsSep.join(out) #**************************************************************************************** @@ -31,20 +45,39 @@ """Class representing fcp config tree """ + ValueClassCurrent = ConfigMessageParams.ParamClassCurrent + ValueClassDefault = ConfigMessageParams.ParamClassDefault + ValueClassExpertFlag = ConfigMessageParams.ParamClassExpertFlag + ValueClassForceWriteFlag = ConfigMessageParams.ParamClassForceWriteFlag + ValueClassShortDescription = ConfigMessageParams.ParamClassShortDescription + ValueClassLongDescription = ConfigMessageParams.ParamClassLongDescription + + def __init__(self, configDataMsg=None): + """ + @param parent: parent item + @param name: name of the item + + @ivar parent: parent item + @ivar name: name of the item + @ivar children: (dict) child items + """ + self.parent = None self.name = None self.children = {} - self.values = {} # for consistency - self.configMessageParams = ConfigMessageParams() + self._configMessageParams = ConfigMessageParams() if configDataMsg is not None: for key, value in configDataMsg.params.items(): - self[key] = value + self.addNewValue(key, value) - def __getitem__(self, key): + """Returns the item associated to a key + @param key: (str) key to retrieve the item for (not including ValueClass prefix) + @return: (L{ConfigItem}) + """ components = key.split('.') parent = self while components: @@ -55,49 +88,69 @@ parent = item return parent - - def __setitem__(self, key, value): - paramClass, components = self.configMessageParams.splitParamClass(key) - paramType = self.configMessageParams.get(key, None) - components = self.configMessageParams.splitAll(components) - valueName = components.pop() - - #TODO: how to handle non existent keys? + + def addNewValue(self, key, value): + """Adds a value to an item + @param key: (str) key to add the value to (including ParamClass prefix) + @param value to associate + @note: if the item does not exist, it is created + """ + paramClass, components = self._configMessageParams.splitParamClass(key) + paramType = self._configMessageParams.get(key, None) if paramType is None: - # log somehow - return False - - # create new config item if necessary + raise ValueError('Unknown key: %r' % components) + + # find or create new config item if necessary + components = self._configMessageParams.splitAll(components) parent = self for component in components: item = parent.children.get(component, None) if item is None: item = ConfigItem(parent, component) - self.children[component] = item + parent.children[component] = item parent = item + parent.values[paramClass] = (value, paramType) + + + + def removeParamClass(self, key): + """Removes the paramClass component if necessary + @param key: (str) key to remove the param class from + @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: + return tail + return tail - # assign value - values = parent.values.get(valueName, None) - if values is None: - values = {} - parent.values[valueName] = values - values[paramClass] = (value, paramType) - return True - + def toMessageParams(self): + """Dumps the contents of the config to a dict + @note: you can use this dict as params for FcpClient.modifyConfig() + """ + out = {} + for node in self.walk(): + if node.name is None: + continue + + key = node.key() + result = node.values.get(self.ValueClassCurrent, None) + if result is not None: + out[key] = result[0] + return out + + def walk(self): + """Walks over the config tree, returning the next L{ConfigItemm} in turn""" def walker(node): yield node for child in node.children.values(): for x in walker(child): yield x - return walker(self) - + return walker(self) - def key(self): - return None - #**************************************************************************************************** # This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-04 11:51:38
|
Revision: 136 http://fclient.svn.sourceforge.net/fclient/?rev=136&view=rev Author: jurner Date: 2008-02-04 03:51:16 -0800 (Mon, 04 Feb 2008) Log Message: ----------- fix Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_config.py Modified: trunk/sandbox/fcp/fcp2_0_config.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_config.py 2008-02-04 11:50:30 UTC (rev 135) +++ trunk/sandbox/fcp/fcp2_0_config.py 2008-02-04 11:51:16 UTC (rev 136) @@ -36,7 +36,7 @@ out.append(parent.name) parent = parent.parent out.reverse() - return types-ConfigMessageParams.ComponentsSep.join(out) + return types.ConfigMessageParams.ComponentSep.join(out) #**************************************************************************************** @@ -129,7 +129,6 @@ """Dumps the contents of the config to a dict @note: you can use this dict as params for FcpClient.modifyConfig() """ - out = {} for node in self.walk(): if node.name is None: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-16 10:06:21
|
Revision: 214 http://fclient.svn.sourceforge.net/fclient/?rev=214&view=rev Author: jurner Date: 2008-02-16 02:06:20 -0800 (Sat, 16 Feb 2008) Log Message: ----------- added logging for unknown config params Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_config.py Modified: trunk/sandbox/fcp/fcp2_0_config.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_config.py 2008-02-16 10:05:34 UTC (rev 213) +++ trunk/sandbox/fcp/fcp2_0_config.py 2008-02-16 10:06:20 UTC (rev 214) @@ -1,6 +1,7 @@ """Sketch for fcp config tree""" - +import logging +import fcp2_0_consts as consts import fcp2_0_types as types #**************************************************************************************** # @@ -67,6 +68,7 @@ self.name = None self.children = {} self._configMessageParams = types.ConfigMessageParams() + self._log = logging.getLogger(consts.LoggerNames.Config) if configDataMsg is not None: for key, value in configDataMsg.params.items(): @@ -93,13 +95,17 @@ """Adds a value to an item @param key: (str) key to add the value to (including ParamClass prefix) @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 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) if paramType is None: - raise ValueError('Unknown key: %r' % components) - + paramType = types.FcpType + self._log.warning('Unknown key: %r' % components) + # find or create new config item if necessary components = self._configMessageParams.splitAll(components) parent = self @@ -110,9 +116,9 @@ parent.children[component] = item parent = item parent.values[paramClass] = (value, paramType) - + + - def removeParamClass(self, key): """Removes the paramClass component if necessary @param key: (str) key to remove the param class from This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-02 05:13:18
|
Revision: 106 http://fclient.svn.sourceforge.net/fclient/?rev=106&view=rev Author: jurner Date: 2008-02-01 21:13:24 -0800 (Fri, 01 Feb 2008) Log Message: ----------- adapt to recent Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_config.py Modified: trunk/sandbox/fcp/fcp2_0_config.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_config.py 2008-02-02 05:12:51 UTC (rev 105) +++ trunk/sandbox/fcp/fcp2_0_config.py 2008-02-02 05:13:24 UTC (rev 106) @@ -1,23 +1,24 @@ """Sketch for fcp config tree""" -from fcp2_0_consts import ConfigMessageParams +import fcp2_0_types as types #**************************************************************************************** # #**************************************************************************************** class ConfigItem(object): - """Config item""" + """Config item + @ivar parent: parent item + @ivar name: name of the item + @ivar children: (dict) child items + @ivar values: dict of values + """ + def __init__(self, parent, name): """ @param parent: parent item @param name: name of the item - - @ivar parent: parent item - @ivar name: name of the item - @ivar children: (dict) child items - @ivar values: dict of values """ self.parent = parent self.name = name @@ -35,7 +36,7 @@ out.append(parent.name) parent = parent.parent out.reverse() - return ConfigMessageParams.ComponentsSep.join(out) + return types-ConfigMessageParams.ComponentsSep.join(out) #**************************************************************************************** @@ -43,30 +44,29 @@ #**************************************************************************************** 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 """ - ValueClassCurrent = ConfigMessageParams.ParamClassCurrent - ValueClassDefault = ConfigMessageParams.ParamClassDefault - ValueClassExpertFlag = ConfigMessageParams.ParamClassExpertFlag - ValueClassForceWriteFlag = ConfigMessageParams.ParamClassForceWriteFlag - ValueClassShortDescription = ConfigMessageParams.ParamClassShortDescription - ValueClassLongDescription = ConfigMessageParams.ParamClassLongDescription + 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 parent: parent item - @param name: name of the item - - @ivar parent: parent item - @ivar name: name of the item - @ivar children: (dict) child items + @param configDataMsg: ConfigData message to initialize the config with or None """ self.parent = None self.name = None self.children = {} - self._configMessageParams = ConfigMessageParams() + self._configMessageParams = types.ConfigMessageParams() if configDataMsg is not None: for key, value in configDataMsg.params.items(): @@ -143,7 +143,7 @@ def walk(self): - """Walks over the config tree, returning the next L{ConfigItemm} in turn""" + """Walks over the config tree, returning the next L{ConfigItem} in turn""" def walker(node): yield node for child in node.children.values(): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |