Commit 3050ddf6 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

Merge branch '54-clean-server' of gitlab.aip.de:yfournier/myplotlib into 54-clean-server

parents 5a759ecb 823dcbd3
......@@ -206,7 +206,7 @@ class MplClient(object):
ID = self.waitForStatus(sock)
# If failed
if ID == 'ERROR':
if not ID:
del(syncFigure)
return(None)
......@@ -216,27 +216,6 @@ class MplClient(object):
syncFigure.syncID = ID
syncFigure.client = self
# content = "['"+str(figClass.__name__)+"', \""+str(symbolicRawdata)+"\", '"+str(kwargs)+"']"
# signal = "("+"'newSyncFigure'"+", "+str(content)+")"
#
# sock = self.sendSignal(signal)
#
# answer = self.waitForAnswer(sock)
# header, content, errmsg = eval(answer)
#
# ID = content
#
# # Figure was created then link sync version locally
# if ID is not None:
# syncFigure.syncID = ID
# syncFigure.client = self
# # else delete the sync Figure
# else:
# print(WARN + 'The server could not create the figure')
# print(errmsg)
# del(syncFigure)
# syncFigure = None
#
return(syncFigure)
# PACK NEW SYNC FIGURE CONTENT -------------------------------------
......@@ -251,25 +230,73 @@ class MplClient(object):
def syncFigFormatRawData(self, syncID):
'''the returned datas should be a tuple of strings'''
content = "['"+str(syncID)+"']"
signal = "("+"'syncFigFormatRawData'"+", "+str(content)+")"
# Send the signal with syncID
signal = self.packSignal(('syncFigFormatRawData', "'"+syncID+"'"))
sock = self.sendSignal(signal)
answer = self.waitForAnswer(sock)
if(DEBUG):
print(INFO+'Sent Signal, waiting for the size of the formatted data...')
# Wait for the size of the formatted data
dataSize = self.waitForStatus(sock)
# header, content, errmsg = eval(answer)
header, content, errmsg = unpackFormattedData(answer)
# if failed
if not dataSize:
self.sendCloseConnection(sock)
return(None)
if content is not None:
datas = content
# Send a receipt
self.sendReceipt(sock)
# Wait for the formatted data
packedData = self.waitForData(sock, dataSize)
print(INFO+str(packedData))
# Unpack
header, datas, errmsg = self.unpackFormattedData(packedData)
# Check status
if datas is not None:
if(DEBUG):
print(INFO+'Received the data')
else:
print(WARN + 'The server could not format the rawdata.')
print(errmsg)
datas = None
datas = (None,)
return(datas)
# SEND CLOSE CONNECTION --------------------------------------------
def sendCloseConnection(self, sock):
'''Send a close connection receipt to the server.'''
packedReceipt = self.packAnswer(('', "'False'", 'Close connection'))
sock.sendall(packedReceipt)
return(True)
# SEND RECEIPT -----------------------------------------------------
def sendReceipt(self, sock):
'''Send a receipt to the server.'''
packedReceipt = self.packAnswer(('', "'True'", 'Receipt'))
sock.sendall(packedReceipt)
return(True)
# PACK ANSWER ------------------------------------------------------
def packAnswer(self, answer):
'''Pack an answer, a tuple of strings: (header, content, errmsg).'''
header, packedContent, errmsg = answer
packedAnswer = "(\""+header+"\", "+str(packedContent)+", \""+str(errmsg)+"\")"
return(packedAnswer)
# WAIT FOR DATA ----------------------------------------------------
def waitForData(self, sock, dataSize):
'''Wait for data of size dataSize.'''
unpackedData = sock.recv(dataSize)
return(unpackedData)
# UNPACKING --------------------------------------------------------
def unpackFormattedData(self, packedData):
'''The packedData should be the string representation
......@@ -284,14 +311,17 @@ class MplClient(object):
header, content, errmsg = eval(packedData)
except:
print(WARN+'The data sent by the server could not be evaluated')
print(SPCE+str(packedData))
return((None, None, None))
# The tuple of as many strings as axes
try:
evaluatedContent = eval(content)
except:
print(WARN+'The content sent by the server could not be evaluated')
return((header, None, errmsg))
# try:
# evaluatedContent = eval(content)
# except:
# print(WARN+'The content sent by the server could not be evaluated')
# return((header, None, errmsg))
content = eval(content)
# check is format is correct
if not isinstance(content, tuple):
......@@ -300,7 +330,7 @@ class MplClient(object):
return((header, None, errmsg))
# create the final tuple
partlyUnpackedData = (header, evaluatedContent, errmsg)
partlyUnpackedData = (header, content, errmsg)
return(partlyUnpackedData)
......
......@@ -219,7 +219,8 @@ class MyFig_client(Figure):
for ax, data in zip(self.get_axes(), datas):
# each data is a string that can be unpacked by axes itself
ax.data = ax.unpackFormattedData(data)
# ax.data = ax.unpackFormattedData(data)
ax.data = data
else:
print(SEVR+'The figure is not properly synchronized.')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment