SF.net SVN: fclient: [456] trunk/fcp2/src/fcp2/config.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-07-01 11:26:55
|
Revision: 456
http://fclient.svn.sourceforge.net/fclient/?rev=456&view=rev
Author: jUrner
Date: 2008-07-01 04:27:03 -0700 (Tue, 01 Jul 2008)
Log Message:
-----------
for ease of use, all necessary symbols are now imported to main
Modified Paths:
--------------
trunk/fcp2/src/fcp2/config.py
Modified: trunk/fcp2/src/fcp2/config.py
===================================================================
--- trunk/fcp2/src/fcp2/config.py 2008-07-01 11:26:47 UTC (rev 455)
+++ trunk/fcp2/src/fcp2/config.py 2008-07-01 11:27:03 UTC (rev 456)
@@ -59,15 +59,259 @@
from fcp2 import consts
from fcp2 import types
-from fcp2 import message
+from fcp2 import key
from fcp2.fcp_lib import uuid
-del hack
+del hack, _RelImportHack
#<-- rel import hack
#****************************************************************************************
#
#****************************************************************************************
+ConfigKeySep = '.'
+
+class ConfigDataType:#
+ """Basic data types in config messages"""
+ Boolean = 'boolean'
+ Number = 'number'
+ String = 'string'
+ StringArray = 'atringArray'
+
+ TypesAll = (
+ Boolean,
+ Number,
+ String,
+ StringArray,
+ )
+
+
+class ConfigValueClass:
+ """Value classes Fcp passes in config messages"""
+
+ Current = 'current'
+ Default = 'default'
+ ExpertFlag = 'expertFlag'
+ ForceWriteFlag = 'forceWriteFlag'
+ ShortDescription = 'shortDescription'
+ LongDescription = 'longDescription'
+ SortOrder = 'sortOrder'
+ DataType = 'dataType'
+
+ ClassesAll = (
+ Current,
+ Default,
+ ExpertFlag,
+ ForceWriteFlag,
+ ShortDescription,
+ LongDescription,
+ SortOrder,
+ DataType,
+ )
+
+#***************************************************************************************
+#
+# param types for config message
+#
+# ..bit more efford here, cos we need types for user input checking
+# ...a sloppy implementation of a dict should be enough
+#
+#***************************************************************************************
+class _ConfigMessageParamTypes(object):
+ """Parameter --> Type mapping for config related messages
+
+ @note: we use this instead of _param_types_ dict to handle param classes
+ in L{ConfigData} and L{ModifyConfig}
+ """
+
+ # all known config keys (param class stripped)
+ Params = {
+
+ 'console.allowedHosts': types.TypeIPList, # host names, single IPs CIDR-maskip IPs likee 192.168.0.0/24
+ 'console.bindTo': types.TypeIPList,
+ 'console.directEnabled': types.TypeBool,
+ 'console.enabled': types.TypeBool,
+ 'console.port': types.TypeIPort,
+ 'console.ssl': types.TypeBool,
+
+ 'fcp.allowedHosts': types.TypeIPList,
+ 'fcp.allowedHostsFullAccess': types.TypeIPList,
+ 'fcp.assumeDownloadDDAIsAllowed': types.TypeBool,
+ 'fcp.assumeUploadDDAIsAllowed': types.TypeBool,
+ 'fcp.bindTo': types.TypeIP,
+ 'fcp.enabled': types.TypeBool,
+ 'fcp.persistentDownloadsEnabled': types.TypeBool,
+ 'fcp.persistentDownloadsFile': types.TypeFilename,
+ 'fcp.persistentDownloadsInterval': types.TypeTimeDelta,
+ 'fcp.port': types.TypeIPort,
+ 'fcp.ssl': types.TypeBool,
+
+ 'fproxy.CSSOverride': types.TypeBool,
+ 'fproxy.advancedModeEnabled': types.TypeBool,
+ 'fproxy.allowedHosts': types.TypeIPList,
+ 'fproxy.allowedHostsFullAccess': types.TypeIPList,
+ 'fproxy.bindTo': types.TypeIPList,
+ 'fproxy.css': types.TypeChoiceFProxyCss,
+ 'fproxy.doRobots': types.TypeBool,
+ 'fproxy.enabled': types.TypeBool,
+ 'fproxy.javascriptEnabled': types.TypeBool,
+ 'fproxy.port': types.TypeIPort,
+ 'fproxy.showPanicButton': types.TypeBool,
+ 'fproxy.ssl': types.TypeBool,
+
+ 'logger.dirname': types.TypeDirname,
+ 'logger.enabled': types.TypeBool,
+ 'logger.interval': types.TypeTimeDelta,
+ 'logger.maxCachedBytes': types.TypeByteAmount,
+ 'logger.maxCachedLines': types.TypeByteAmount, # ???
+ 'logger.maxZippedLogsSize': types.TypeByteAmount, # ???
+ 'logger.priority': types.TypeChoiceLoggerPriority,
+ 'logger.priorityDetail': types.Type, # ???? is it Detailed priority thresholds ???
+
+ 'node.alwaysAllowLocalAddresses': types.TypeBool,
+ 'node.assumeNATed': types.TypeBool,
+ 'node.bindTo': types.TypeIP,
+ 'node.clientThrottleFile': types.TypeFilename,
+ 'node.databaseMaxMemory': types.TypeByteAmount,
+ 'node.disableHangCheckers': types.TypeBool,
+ 'node.disableProbabilisticHTLs': types.TypeBool,
+ 'node.downloadAllowedDirs': types.TypeChoiceNodeDownloadAllowedDirs,
+ 'node.downloadsDir': types.TypeDirname,
+ 'node.enableARKs': types.TypeBool,
+ 'node.enablePacketCoalescing': types.TypeBool,
+ 'node.enablePerNodeFailureTables': types.TypeBool,
+ 'node.enableSwapping': types.TypeBool,
+ 'node.enableSwapQueueing': types.TypeBool,
+ 'node.enableULPRDataPropagation': types.TypeBool,
+ 'node.extraPeerDataDir': types.TypeDirname,
+ 'node.includeLocalAddressesInNoderefs': types.TypeBool,
+ 'node.inputBandwidthLimit': types.TypeByteAmount, # -1 is possible as value aswell
+ 'node.ipAddressOverride': types.TypeIP,
+ 'node.l10n': types.Type, # ???
+ 'node.lazyResume': types.TypeBool,
+ 'node.listenPort': types.TypeIPort,
+ 'node.maxBackgroundUSKFetchers': types.TypeIntWithBounds(0, None),
+ 'node.maxHTL': types.TypeIntWithBounds(0, None),
+ 'node.name': types.TypeString,
+ 'node.nodeDir': types.TypeDirname,
+ 'node.oneConnectionPerIP': types.TypeBool,
+ 'node.outputBandwidthLimit': types.TypeByteAmount,
+ 'node.passOpennetPeersThroughDarknet': types.TypeBool,
+ 'node.persistentTempDir': types.TypeDirname,
+ 'node.storeDir': types.TypeDirname,
+ 'node.storeForceBigShrinks': types.TypeBool,
+ 'node.storeSize': types.TypeByteAmount,
+ 'node.storeType': types.TypeString,
+ 'node.tempDir': types.TypeDirname,
+ 'node.tempIPAddressHint': types.TypeIP, # ???
+ 'node.testingDropPacketsEvery': types.TypeIntWithBounds(0, None),
+ 'node.uploadAllowedDirs': types.TypeChoiceNodeDownloadAllowedDirs,
+
+ 'node.testnet.enabled': types.TypeBool,
+
+ 'node.load.aggressiveGC': types.Type, # ???
+ 'node.load.freeHeapBytesThreshold': types.TypeByteAmount,
+ 'node.load.freeHeapPercentThreshold': types.TypePercent,
+ 'node.load.memoryChecker': types.TypeBool,
+ 'node.load.nodeThrottleFile': types.TypeFilename,
+ 'node.load.threadLimit': types.TypeIntWithBounds(0, None),
+
+ 'node.opennet.acceptSeedConnections': types.TypeBool,
+ 'node.opennet.alwaysAllowLocalAddresses': types.TypeBool,
+ 'node.opennet.assumeNATed': types.TypeBool,
+ 'node.opennet.bindTo': types.TypeIP,
+ 'node.opennet.enabled': types.TypeBool,
+ 'node.opennet.listenPort': types.TypeIPort,
+ 'node.opennet.maxOpennetPeers': types.TypeIntWithBounds(0, None),
+ 'node.opennet.oneConnectionPerIP': types.TypeBool,
+ 'node.opennet.testingDropPacketsEvery': types.TypeIntWithBounds(0, None),
+
+ 'node.scheduler.CHKinserter_priority_policy': types.TypeChoicePriorityPolicy,
+ 'node.scheduler.CHKrequester_priority_policy': types.TypeChoicePriorityPolicy,
+ 'node.scheduler.SSKinserter_priority_policy': types.TypeChoicePriorityPolicy,
+ 'node.scheduler.SSKrequester_priority_policy': types.TypeChoicePriorityPolicy,
+
+ 'node.updater.URI': key.TypeKey,
+ 'node.updater.autoupdate': types.TypeBool,
+ 'node.updater.enabled': types.TypeBool,
+ 'node.updater.extURI': key.TypeKey,
+ 'node.updater.revocationURI': key.TypeKey,
+
+ 'pluginmanager.loadplugin': types.TypeStringList,
+ 'pluginmanager2.loadedPlugins': types.TypeStringList,
+
+ 'ssl.sslEnable': types.TypeBool,
+ 'ssl.sslKeyPass': types.TypeString,
+ 'ssl.sslKeyStore': types.TypeFilename,
+ 'ssl.sslKeyStorePass': types.TypeString,
+ 'ssl.sslVersion': types.TypeChoiceSSLVersion,
+
+ 'toadletsymlinker.symlinks': types.TypeStringList,
+ }
+
+ def __init__(self):
+ pass
+
+ def splitAll(self, paramName):
+ """Splits a parameter name into its components
+ @param paramName: (str) parameter name to split
+ @return: (list) components
+ """
+ return paramName.split(ConfigKeySep)
+
+
+ def splitParamClass(self, paramName):
+ """Splits the parameter class from a parameter name
+ @param paramName: (str) parameter name to split
+ @return: (tuple) paramClass, tail
+ """
+ result = paramName.split(ConfigKeySep, 1)
+ if len(result) == 2:
+ if result[0] in ConfigValueClass.ClassesAll:
+ return result
+ return '', paramName
+
+
+ def get(self, paramName, default=None):
+ """Returns the type of a parameter or default
+ @param paramName: (str) name of the parameter to retuen the type for
+ @return: (Type)
+ """
+ try:
+ return self[paramName]
+ except KeyError:
+ return default
+
+
+ def __getitem__(self, paramName):
+ """Returns the type of a parameter
+ @param paramName: (str) name of the parameter to retuen the type for
+ @return: (Type)
+ """
+ paramClass, paramKey = self.splitParamClass(paramName)
+ if paramClass == ConfigValueClass.Current or paramClass == '':
+ return self.Params[paramKey]
+ elif paramClass == ConfigValueClass.Default:
+ return self.Params[paramKey]
+ elif paramClass == ConfigValueClass.ExpertFlag:
+ return types.TypeBool
+ elif paramClass == ConfigValueClass.ForceWriteFlag:
+ return types.TypeBool
+ elif paramClass == ConfigValueClass.ShortDescription:
+ return types.TypeString
+ elif paramClass == ConfigValueClass.LongDescription:
+ return types.TypeString
+ elif paramClass == ConfigValueClass.SortOrder:
+ return types.TypeInt
+ elif paramClass == ConfigValueClass.DataType:
+ return types.TypeString
+ else:
+ raise ValueError('Unknown param class in: %r' % paramName)
+
+_ConfigMessageParamTypes = _ConfigMessageParamTypes()
+
+#****************************************************************************************
+#
+#****************************************************************************************
class ConfigItem(object):
"""Config item
@@ -110,7 +354,7 @@
for x in walker(child):
yield x
return walker(self)
-
+
#****************************************************************************************
#
#****************************************************************************************
@@ -161,14 +405,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 = message.ConfigMessageParamTypes.splitParamClass(key)
- paramType = message.ConfigMessageParamTypes.get(key, None)
+ paramClass, components = _ConfigMessageParamTypes.splitParamClass(key)
+ paramType = _ConfigMessageParamTypes.get(key, None)
if paramType is None:
paramType = types.FcpType
consts.Logger.Config.warning('Unknown key: %r' % components)
# find or create new config item if necessary
- components = message.ConfigMessageParamTypes.splitAll(components)
+ components = _ConfigMessageParamTypes.splitAll(components)
parent = self
for component in components:
item = parent.children.get(component, None)
@@ -217,7 +461,8 @@
yield x
return walker(self)
-
+
+__all__ = [i for i in dir() if i[0].isupper() and not i.startswith('_')]
#****************************************************************************************************
#
#****************************************************************************************************
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|