SF.net SVN: fclient: [217] trunk/sandbox/fcp/fcp2_0_types.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <ju...@us...> - 2008-02-16 10:09:21
|
Revision: 217
http://fclient.svn.sourceforge.net/fclient/?rev=217&view=rev
Author: jurner
Date: 2008-02-16 02:09:26 -0800 (Sat, 16 Feb 2008)
Log Message:
-----------
added a few new config params
still working on how to handle byte amounts and time deltas
Modified Paths:
--------------
trunk/sandbox/fcp/fcp2_0_types.py
Modified: trunk/sandbox/fcp/fcp2_0_types.py
===================================================================
--- trunk/sandbox/fcp/fcp2_0_types.py 2008-02-16 10:07:55 UTC (rev 216)
+++ trunk/sandbox/fcp/fcp2_0_types.py 2008-02-16 10:09:26 UTC (rev 217)
@@ -3,6 +3,24 @@
This module handles type conversions from Fcp to Python and vice versa
"""
+import os, sys
+
+#--> rel import hack
+class SysPathHack(object):
+ def __init__(self, n):
+ fpath = os.path.abspath(__file__)
+ for i in xrange(n): fpath = os.path.dirname(fpath)
+ sys.path.insert(0, fpath)
+ def __del__(self): sys.path.pop(0)
+hack = SysPathHack(3)
+
+
+from fcp_lib import numbers
+
+
+del hack
+#<-- rel import hack
+
import base64
import fcp2_0_consts as consts
@@ -112,7 +130,8 @@
def fcpToPython(clss, value):
return int(value) / 1000
-
+#TODO: how to handle time deltas? Convert them to seconds?
+class FcpTypeTimeDelta(FcpType): pass
class FcpTypeIP(FcpType): pass
class FcpTypeIPList(FcpType): pass
@@ -120,7 +139,37 @@
class FcpTypeStringList(FcpType): pass
class FcpTypeDirname(FcpType): pass
class FcpTypeFilename(FcpType): pass
-class FcpTypeNumBytes(FcpType): pass
+
+#TODO: how to handle byte amounts? Convert them to (int) bytes?
+class FcpTypeNumBytes(FcpType):
+ """Type conversion """
+
+ NamesBinary = ('', 'K', 'M', 'G', 'T', 'P', 'E')
+ NamesCommon = ('', 'k', 'm', 'g', 't', 'p', 'e')
+
+ @classmethod
+ def pythonToFcp(clss, value):
+ return format_num_bytes(value, binary=True, names=clss.NamesBinary)
+
+ @classmethod
+ def fcpToPython(clss, value):
+ result = -1
+ if value and value != '-1':
+ if value[-1] in clss.NamesBinary:
+ names = clss.NamesBinary
+ binary = True
+ else:
+ names = clss.NamesCommon
+ binary = False
+ try:
+ result = numbers.num_bytes_to_bytes(value, binary=binary, names=names)
+ except ValueError:
+ pass
+ return result
+
+
+
+
class FcpTypePercent(FcpTypeFloat): pass
class FcpTypeUri(FcpType): pass
@@ -207,6 +256,7 @@
ParamClassForceWriteFlag,
ParamClassShortDescription,
ParamClassLongDescription,
+ ParamClassSortOrder,
)
# all known config keys (param class stripped)
@@ -227,7 +277,7 @@
'fcp.enabled': FcpTypeBool,
'fcp.persistentDownloadsEnabled': FcpTypeBool,
'fcp.persistentDownloadsFile': FcpTypeFilename,
- 'fcp.persistentDownloadsInterval': FcpTypeIntWithBounds(0, None),
+ 'fcp.persistentDownloadsInterval': FcpTypeTimeDelta,
'fcp.port': FcpTypeIPort,
'fcp.ssl': FcpTypeBool,
@@ -246,7 +296,7 @@
'logger.dirname': FcpTypeDirname,
'logger.enabled': FcpTypeBool,
- 'logger.interval': FcpType, # ??? 1HOUR ??
+ 'logger.interval': FcpTypeTimeDelta,
'logger.maxCachedBytes': FcpTypeNumBytes,
'logger.maxCachedLines': FcpTypeNumBytes, # ???
'logger.maxZippedLogsSize': FcpTypeNumBytes, # ???
@@ -262,6 +312,11 @@
'node.disableProbabilisticHTLs': FcpTypeBool,
'node.downloadAllowedDirs': FcpTypeChoiceNodeDownloadAllowedDirs,
'node.downloadsDir': FcpTypeDirname,
+ 'node.enableARKs': FcpTypeBool,
+ 'node.enablePerNodeFailureTables': FcpTypeBool,
+ 'node.enableSwapping': FcpTypeBool,
+ 'node.enableSwapQueueing': FcpTypeBool,
+ 'node.enableULPRDataPropagation': FcpTypeBool,
'node.extraPeerDataDir': FcpTypeDirname,
'node.includeLocalAddressesInNoderefs': FcpTypeBool,
'node.inputBandwidthLimit': FcpTypeNumBytes, # -1 is possible as value aswell
@@ -280,6 +335,7 @@
'node.storeDir': FcpTypeDirname,
'node.storeForceBigShrinks': FcpTypeBool,
'node.storeSize': FcpTypeNumBytes,
+ 'node.storeType': FcpTypeString,
'node.tempDir': FcpTypeDirname,
'node.tempIPAddressHint': FcpTypeIP, # ???
'node.testingDropPacketsEvery': FcpTypeIntWithBounds(0, None),
@@ -343,7 +399,11 @@
@param paramName: (str) parameter name to split
@return: (tuple) paramClass, tail
"""
- return paramName.split(self.ComponentSep, 1)
+ result = paramName.split(self.ComponentSep, 1)
+ if len(result) == 2:
+ if result[0] in self.ParamClasses:
+ return result
+ return '', paramName
def get(self, paramName, default=None):
@@ -363,7 +423,7 @@
@return: (FcpType)
"""
paramClass, paramKey = self.splitParamClass(paramName)
- if paramClass == self.ParamClassCurrent:
+ if paramClass == self.ParamClassCurrent or paramClass == '':
return self.Params[paramKey]
elif paramClass == self.ParamClassDefault:
return self.Params[paramKey]
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|