SF.net SVN: fclient: [67] trunk/fclient/fclient_lib/fcp/fcp2_0.py
Status: Pre-Alpha
Brought to you by:
jurner
From: <jU...@us...> - 2007-11-12 10:35:06
|
Revision: 67 http://fclient.svn.sourceforge.net/fclient/?rev=67&view=rev Author: jUrner Date: 2007-11-12 02:35:09 -0800 (Mon, 12 Nov 2007) Log Message: ----------- bit of this and that Modified Paths: -------------- trunk/fclient/fclient_lib/fcp/fcp2_0.py Modified: trunk/fclient/fclient_lib/fcp/fcp2_0.py =================================================================== --- trunk/fclient/fclient_lib/fcp/fcp2_0.py 2007-11-10 11:30:27 UTC (rev 66) +++ trunk/fclient/fclient_lib/fcp/fcp2_0.py 2007-11-12 10:35:09 UTC (rev 67) @@ -168,6 +168,7 @@ 'ClientRequestInfo', + 'PersistentGet', 'DataFound', 'GetFailed', 'SimpleProgress', @@ -318,6 +319,7 @@ + class IdentifierPrefix: """Special purpose identifier prefixes""" ClientGetFile = 'ClientGetFile::' @@ -691,7 +693,7 @@ """ self._connectionName = connectionName - self._ddaTmpFiles = [] + self._ddaTmpFiles = {} self._log = logging.getLogger(name) self._socket = None @@ -813,6 +815,7 @@ ## #################################################### elif msg.name == self.Message.TestDDAReply: + directory = msg['Directory'] fpathWrite = msg.params.get('WriteFilename', None) fpathRead = msg.params.get('ReadFilename', None) readContent = '' @@ -821,8 +824,13 @@ if not written: saveRemoveFile(fpathWrite) else: - self._ddaTmpFiles.append(fpathWrite) - + # ...hope the node will keep request order so the correct + # tmp file is removed on completion + if directory in self._ddaTmpFiles: + self._ddaTmpFiles[directory].append(fpathWrite) + else: + self._ddaTmpFiles[directory] = [fpathWrite, ] + if fpathRead is not None: readContent = saveReadFile(fpathRead) if readContent is None: @@ -835,12 +843,11 @@ ) return True - #TODO: unconditionally clean up all tmp files? Looks like trouble.. elif msg.name == self.Message.TestDDAComplete: - # clean tmp files - for fpath in self._ddaTmpFiles: - saveRemoveFile(fpath) - self._ddaTmpFiles = [] + # clean up tmp file + directory = msg['Directory'] + tmp_file = self._ddaTmpFiles[directory].pop(0) + saveRemoveFile(tmp_file) self.events.TestDDAComplete(msg.params) return True @@ -926,6 +933,10 @@ self.events.IdentifierCollision(msg.params) return True + elif msg.name == self.Message.PersistentGet: + self.events.PersistentGet(msg.params) + return True + elif msg.name == self.Message.PersistentRequestModified: self.events.PersistentRequestModified(msg.params) return True @@ -1189,13 +1200,13 @@ ## ########################################################## #TODO: not complete yet - def clientGetFile(self, uri, filename, identifier=None): + def clientGetFile(self, uri, filename, identifier=None, clientToken=None): """ """ if identifier is None: identifier = self.IdentifierPrefix.ClientGetFile + self.newIdentifier() else: - assert identifier.startswith(self.IdentifierPrefix.ClientGetFile), 'Wrong prefix' + assert self.isClientGetFile(identifier), 'Wrong prefix' msg = self.Message( self.Message.ClientGet, IgnoreDS='false', @@ -1214,12 +1225,14 @@ #BinaryBlob='false', Filename=filename, ) + if clientToken is not None: + msg['ClientToken'] = clientToken self.sendMessageEx(msg) return identifier - def clientRequestInfo(self, uri, identifier=None, **params): + def clientRequestInfo(self, uri, identifier=None, clientToken=None, **params): """Requests info about a file @param uri: uri of the file to request info about @param identifier: request identifier or None to let the method create one. If an identifier is passed, it has to be @@ -1234,13 +1247,13 @@ if identifier is None: identifier = self.IdentifierPrefix.ClientRequestInfo + self.newIdentifier() else: - assert identifier.startswith(self.IdentifierPrefix.ClientRequestInfo), 'Wrong prefix' - self.sendMessage( + assert self.isClientRequestInfo(identifier), 'Wrong prefix' + msg = self.Message( self.Message.ClientGet, Identifier=identifier, URI=uri, #TODO: persistance??? - #Persistence='forever', + Persistence='forever', # suggested by Mathew Toseland to use about 32k for mimeType requests # basic sizes of keys are: 1k for SSks and 32k for CHKs @@ -1249,9 +1262,41 @@ Verbosity='1', **params ) + + if clientToken is not None: + msg['ClientToken'] = clientToken + + self.sendMessageEx(msg) return identifier + + def isClientGetFile(self, identifier): + """Checks if an identifier is a ClientGetFile identifier + @return: (bool) + """ + return identifier.startswith(self.IdentifierPrefix.ClientGetFile) + + def isClientRequestInfo(self, identifier): + """Checks if an identifier is a RequestFileInfo identifier + @return: (bool) + """ + return identifier.startswith(self.IdentifierPrefix.ClientRequestInfo) + + + def removePersistentRequest(self, identifier, global_=False): + """Removes a request + @param identifier: (str) identifier of the request to remove + @param global_: (bool) has to be set to True if the request was a global request + """ + self.sendMessage( + self.Message.RemovePersistentRequest, + Global=self.fcpBool(global_), + Identifier=identifier + ) + + + #TODO: check if node passes directory unchanged to testDDAComplete (trailing slash) def testDDA(self, directory, wantReadDirectory=None, wantWriteDirectory=None): """Tests a directory for read / write access @param directory: directory to test @@ -1292,6 +1337,7 @@ msg['WantWriteDirectory'] = self.fcpBool(wantWriteDirectory) self.sendMessageEx(msg) + ########################################################## ## ## others This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |