SF.net SVN: fclient: [248] trunk/sandbox/fcp/fcp2_0_client.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <ju...@us...> - 2008-02-26 09:07:35
|
Revision: 248
http://fclient.svn.sourceforge.net/fclient/?rev=248&view=rev
Author: jurner
Date: 2008-02-26 01:07:39 -0800 (Tue, 26 Feb 2008)
Log Message:
-----------
moved helpers to fcp_lib/tools module
Modified Paths:
--------------
trunk/sandbox/fcp/fcp2_0_client.py
Modified: trunk/sandbox/fcp/fcp2_0_client.py
===================================================================
--- trunk/sandbox/fcp/fcp2_0_client.py 2008-02-24 11:52:23 UTC (rev 247)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-26 09:07:39 UTC (rev 248)
@@ -214,65 +214,12 @@
from fcp2_0_config import Config
from fcp2_0_message import Message
import fcp2_0_params as FcParams
-from fcp2_0_requests import Upload
from fcp2_0_uri import Uri
-logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
-#**********************************************************************
-# helpers
-#**********************************************************************
-def saveReadFile(fpath):
- """Reads contents of a file in the savest manner possible
- @param fpath: file to write
- @return: contents of the file if successful, None otherwise
- """
- read = None
- try:
- fp = open(fpath, 'rb')
- except: pass
- else:
- try:
- read = fp.read()
- except: pass
- fp.close()
- return read
+from fcp_lib import tools
-def saveRemoveFile(fpath):
- """Savely removes a file
- @param fpath: filepath of the file to remove or None
- @return: True if the file was removed, False otherwise
- """
- if fpath is not None:
- if os.path.isfile(fpath):
- try:
- os.remove(fpath)
- except Exception, d:
- pass
- else:
- return True
- return False
-
-def saveWriteFile(fpath, data):
- """Writes data to a file in the savest manner possible
- @param fpath: file to write
- @param data: data to write to file
- @return: True if successful, False otherwise
- """
- written = False
- try:
- fp = open(fpath, 'wb')
- except: pass
- else:
- try:
- fp.write(data)
- written = True
- except:
- fp.Close()
- else:
- fp.close()
- return written
-
+logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
#*************************************************************************************************
#
#*************************************************************************************************
@@ -304,10 +251,8 @@
Message = Message
FcParams = FcParams
Uri = Uri
- Upload = Upload
+
-
-
def __init__(self,
connectionName=None,
debugVerbosity=None,
@@ -350,7 +295,7 @@
# clean left over DDA test tmp files
for initialRequest in self._ddaTests:
if initialRequest['FcTestDDA'].get('TmpFile', None) is not None:
- saveRemoveFile(initialRequest['FcTestDDA']['TmpFile'])
+ tools.saveRemoveFile(initialRequest['FcTestDDA']['TmpFile'])
self._ddaTests = []
self._requests = {}
@@ -738,8 +683,7 @@
ddaRequestMsg['WantReadDirectory'] = True
directory = os.path.dirname(initialRequest['Filename'])
ddaRequestMsg['Directory'] = directory
-
-
+
# add params required for testing
initialRequest['FcTestDDA'] = {
'Directory': directory,
@@ -824,16 +768,16 @@
fpathRead = msg.params.get('ReadFilename', None)
readContent = ''
if fpathRead is not None:
- readContent = saveReadFile(fpathRead)
+ readContent = tools.saveReadFile(fpathRead)
if readContent is None:
readContent = ''
# perform write test if necessary
fpathWrite = msg.params.get('WriteFilename', None)
if fpathWrite is not None:
- written = saveWriteFile(fpathWrite, msg['ContentToWrite'])
+ written = tools.saveWriteFile(fpathWrite, msg['ContentToWrite'])
if not written:
- saveRemoveFile(fpathWrite)
+ tools.saveRemoveFile(fpathWrite)
else:
initialRequest['FcTestDDA']['TmpFile'] = fpathWrite
@@ -861,7 +805,7 @@
# remove test and clean tmp data
self._ddaTests.remove(initialRequest)
if initialRequest['FcTestDDA']['TmpFile'] is not None:
- saveRemoveFile(initialRequest['FcTestDDA']['TmpFile'])
+ tools.saveRemoveFile(initialRequest['FcTestDDA']['TmpFile'])
wantWrite = initialRequest.params['FcTestDDA']['WantWrite']
# check if test was sucessful
@@ -881,9 +825,7 @@
# else: resend message
self.sendMessageEx(initialRequest)
return True
-
-
-
+
####################################################
##
## config related
@@ -896,8 +838,7 @@
elif msg.name == consts.Message.NodeData:
self.events.NodeData(msg)
return True
-
-
+
####################################################
##
## get / put related
@@ -1424,8 +1365,6 @@
If the value of a keyword is None, it is ignored.
@return: (str) identifier of the request
-
-
"""
uri = self.Uri(uri).uri
msg = self.Message(consts.Message.ClientGet, URI=uri)
@@ -1645,7 +1584,7 @@
def subscribeUSK(self, uri, dontPoll=True):
"""Asks the node to notify the client when an USK is updated
@param uri: uri of the USK to subscribe to
- @param dontPoll: if True, whatever ???
+ @param dontPoll: if True, does whatever ???
@return: (str) identifer of the request
@note: this request can not be removed or modified and the {consts.RequestStatus.Completed}
@@ -1681,7 +1620,7 @@
@param uri:
@param data: (str) for L{consts.RequestType.PutData} data to upload or None
@param persistentUserData: (str) persistent data to be assosiated to the request
- @param userdata: (any) any data to be associated to the request at runtime
+ @param userData: (any) any data to be associated to the request at runtime
@param items: for L{consts.RequestType.PutMultiple}, items to upload
@param msgParams: (dict) Fcp parameters to pass along with the message
@@ -1771,7 +1710,7 @@
self.sendMessageEx(msg)
return msg['Identifier']
-
+
def putRedirect(self,
name,
targetURI,
@@ -1786,9 +1725,9 @@
@param targetURI: (str) uri to redirect to
@param maxRetries: (int) maximum number of tretries or -1 to leave the decission up to the node
@param persistence: (L{consts.Persistence}) of the request
- @param priority: (L{consts.Priority}) priority of the request
+ @param priorityClass: (L{consts.Priority}) priority of the request
@param persistentUserData: (str) persistent data to be assosiated to the request
- @param userdata: (any) any data to be associated to the request at runtime
+ @param userData: (any) any data to be associated to the request at runtime
@return: (str) request identifier
"""
msg = self.Message(
@@ -1850,6 +1789,7 @@
Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
)
+
def chkPutDir(self,
directory,
allowUnreadableFiles=False,
@@ -1866,9 +1806,8 @@
):
"""
- @param TargetFilename: (str) filename to append to the CHK key or None (may not contain slashes)
+ @param targetFilename: (str) filename to append to the CHK key or None (may not contain slashes)
"""
-
return self.clientPut(
consts.RequestType.PutDir,
consts.KeyType.CHK,
@@ -1876,8 +1815,7 @@
data=None,
persistentUserData=persistentUserData,
userData=userData,
-
-
+
# fcp params
Filename=directory,
AllowUnreadableFiles=allowUnreadableFiles,
@@ -1911,7 +1849,7 @@
):
"""
- @param TargetFilename: (str) filename to append to the CHK key or None (may not contain slashes)
+ @param targetFilename: (str) filename to append to the CHK key or None (may not contain slashes)
"""
return self.clientPut(
@@ -1959,12 +1897,11 @@
@param items:
- @param TargetFilename: (str) filename to append to the CHK key or None (may not contain slashes)
+ @param targetFilename: (str) filename to append to the CHK key or None (may not contain slashes)
"""
-
return self.clientPut(
consts.RequestType.PutMultiple,
consts.KeyType.CHK,
@@ -1973,8 +1910,7 @@
persistentUserData=persistentUserData,
userData=userData,
items=items,
-
-
+
# fcp params
Filename=directory,
AllowUnreadableFiles=allowUnreadableFiles,
@@ -2097,7 +2033,7 @@
All attempts to modify other requests will fail
@note: a RequestModified event is triggered as soon as the request has actually been modified
@note: you can not change the priority of requests with Persistence=L{consts.Persistence.Connection}.
- All attempts to do so are ignored. Too bad, but doing so is simply not implemented in the client protocol.
+ All attempts to do so are ignored. Too bad, but doing so is not implemented in the client protocol.
"""
initialRequest = self._requests[requestIdentifier]
@@ -2169,8 +2105,8 @@
@note: you can use this method to resend get / put requests.All attempts to resend other requests
will fail
- @note: actually a new request is created and registered. Todo so, the request passed is copied and removed from
- the queue (if necessary). The new request will have FcInitTime reseet and FcUserData amd FcPersistentUserData
+ @note: actually a new request is created and registered. Todo so, the request passed is copied. If it is a persistent
+ request, it will be removed. The new request will have FcInitTime reset and FcUserData amd FcPersistentUserData
taken over from the old request
"""
requestType = request.get('FcRequestType', consts.RequestType.Null)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|