From c5fb8044167495c78ae09c0c0df5b622604b55fb Mon Sep 17 00:00:00 2001 From: Philipp gast Date: Tue, 6 Feb 2018 14:53:56 +0100 Subject: [PATCH] added the deSyncFig method to server and client side --- mplClient2.py | 45 +++++++++++++++++++++++----------------- mplServer2.py | 11 ++++++++++ myFig_client.py | 10 +++++++++ signal.py | 12 ++++++++--- test/network/test_com.py | 4 +++- 5 files changed, 59 insertions(+), 23 deletions(-) diff --git a/mplClient2.py b/mplClient2.py index c55f45a..32c60ca 100644 --- a/mplClient2.py +++ b/mplClient2.py @@ -46,8 +46,7 @@ class MplClient2(): print('please provide host,port. currently host: ',self.host,' , port:',self.port) def send(self,sig): - # pickel the signal - # send the str + """ Sending a Type derived from Signal through the socket after 'pickling' it""" wf = self.sock.makefile(mode='wb') if debug: print('sending ',type(sig),' with content \"',sig.content,'\"') @@ -103,7 +102,10 @@ class MplClient2(): return self.testStatusSig(query,statusSig) def listRemoteData(self): - """ The server retuns a list with the content of its G_RAWDATA """ + """ The server retuns a list with the content of its G_RAWDATA + + not implemented yet. + """ pass def newSyncFigure(self, figname, dataname,*args,**kwargs) : @@ -115,6 +117,7 @@ class MplClient2(): # create a Signal of type Query with args query = Query(Query.NEWSYNCFIGURE,{'figClassName' : figname.__name__, "dataName" : dataname, 'args' : args, 'kwargs' : kwargs}) status = self.send(query) + if not status : print('something went wrong with the sending of newSincFigure request...') statusSig = self.waitForSignal() @@ -152,20 +155,25 @@ class MplClient2(): #~ # do not update the figure. #~ print statusSig.error #~ - #~ def deleteSyncFigure() - #~ ''' - #~ Send a DELETE_SYNC_FIGURE query to the server. - #~ wait for the status - #~ if status ok then sync. - #~ ''' - #~ # create a signal with args - #~ query = Query(Query.DELETE_SYNC_FIGURE) - #~ sendSignal(query) - #~ statusSig = waitForSignal() - #~ if statusSig.value: - #~ # delete local figure. - #~ else: - #~ print statusSig.error + def deleteSyncFigure(self,syncID): + ''' + Send a DELETESYNCFIGURE query to the server. + + If the FigID is known delete it from G_FIGURES (server) + wait for the confirmation status + if status ok then proceed deletion. + ''' + # create a signal with syncID as content + query = Query(Query.DELETESYNCFIGURE,syncID) + status = self.send(query) + + statusSig = self.waitForSignal() + if status and statusSig.value: + return True + else: + print('The remote figure could not be deleted') + print statusSig.content + return False # SYNC FIGURE FORMAT RAWDATA --------------------------------------- def syncFigFormatRawData(self, syncID): @@ -174,9 +182,8 @@ class MplClient2(): if answer not empty then set data to answer's value. ''' - # Send the signal with syncID + # Send the signal with syncID as content signal = Query(Query.SYNCFIGFORMATRAWDATA,syncID) - status = self.send(signal) if debug: diff --git a/mplServer2.py b/mplServer2.py index 0f8a034..4779e19 100644 --- a/mplServer2.py +++ b/mplServer2.py @@ -119,6 +119,15 @@ class MplHandler(SocketServer.StreamRequestHandler): datas = datas + (ax.data,) return Answer(datas) + + def treatDeleteSyncFigure(self,figID) : + """ Deletes the figure with ID figID from G_FIGURES """ + if figID in G_FIGURES : + del G_FIGURES[figID] + return Status(True,'Figure with ID '+str(figID)+' deleted from server.') + else : + return Status(False,'Figure with ID '+str(figID)+' not found on server side.') + def send(self,sig): # pickel the signal @@ -166,6 +175,8 @@ class MplHandler(SocketServer.StreamRequestHandler): return self.treatUpdateSyncFigure(sig.content) elif sig.queryType == sig.SYNCFIGFORMATRAWDATA : return self.treatSyncFigFormatRawData(sig.content) + elif sig.queryType == sig.DELETESYNCFIGURE : + return self.treatDeleteSyncFigure(sig.content) else : self.servPrint('received unknown query type') return Status(False,"received unknown query type") diff --git a/myFig_client.py b/myFig_client.py index 6953da4..9d18139 100644 --- a/myFig_client.py +++ b/myFig_client.py @@ -110,6 +110,16 @@ class MyFig_client(Figure): # initialise self._initialize(*args, **kwargs) + def deSyncFig(self): + if self.client is not None : + if self.client.deleteSyncFigure(self.syncID) : + print('The figure was successfully deleted on the server Side') + self.syncID = -1 + else : + print('The figure could not be deleted on the server Side') + else: + print('The client is not connected to a server yet') + # INITIALIZE ------------------------------------------------------- def _initialize(self, *args, **kwargs): diff --git a/signal.py b/signal.py index f1cec5d..4d3fda5 100644 --- a/signal.py +++ b/signal.py @@ -9,9 +9,10 @@ class Query(Signal) : NEWSYNCFIGURE = 2 UPDATESYNCFIGURE = 3 SYNCFIGFORMATRAWDATA = 4 + DELETESYNCFIGURE = 5 def __init__(self,queryType, content) : - if queryType in [Query.READDATA,Query.NEWSYNCFIGURE,Query.UPDATESYNCFIGURE,Query.SYNCFIGFORMATRAWDATA] : + if queryType in [Query.READDATA,Query.NEWSYNCFIGURE,Query.UPDATESYNCFIGURE,Query.SYNCFIGFORMATRAWDATA,Query.DELETESYNCFIGURE] : self.queryType = queryType if queryType == Query.READDATA : if type(content) == dict : @@ -27,11 +28,16 @@ class Query(Signal) : raise elif queryType == Query.UPDATESYNCFIGURE : - pass + self.content = content elif queryType == Query.SYNCFIGFORMATRAWDATA : self.content = content - + + elif queryType == Query.DELETESYNCFIGURE : + self.content = content + else : + print('unknown query type!') + raise class Status(Signal): diff --git a/test/network/test_com.py b/test/network/test_com.py index 5670222..04bb4fb 100644 --- a/test/network/test_com.py +++ b/test/network/test_com.py @@ -27,4 +27,6 @@ client.connect(('', 50803)) client.readData('readStupidData', 'data1') fig = client.newSyncFigure(FigTestc, ('data1',)) win=mpl_client.MyWin(fig) -sleep(10) +sleep(2) + +fig.deSyncFig() -- GitLab