def storefile( self, fname, service ): """ Send a file to the proxy for storing @param fname: String. Contains the file's name @param service: String. Contains the storage service @return A touple that contains the request's status and the file's curren version """ s = FileStream(os.path.basename(fname), self._uid, self._uid, service) s.loadfromfile(fname) code, ver = self._send( Message.SAVESTREAM, s.serialize() ) return code, ver
def getfile( self, fname ): """ Asks for a file @param fname: String. file's base name @return A FileStream instance that contains the requested file """ conf = Config() fpath = os.path.join( self._downloads, fname ) result = FileStream() code, data = self._send( Message.LOADSTREAM, fname ) result.load(data) result.savetofile(fpath) print "Done"
def storestream(self, sdata ): """ Logs a file into the proxy and send it to the server where it'll be stored @param sdata: @return: Current File's version. """ stream = FileStream() stream.load(sdata) node = self._neighbors.nextval() # Recording operation. # sid : File's id # ver: File's current version sid, ver = stream.registerfile( self._dbase, node.getid() ) # Sending stream node.client.sendfile( stream ) msg = Messages.SendingFileTo % (stream.getname(), node.getname(), node.geturi(), ver) print msg logging.info(msg) return Message.SUCCESS, ver