Commit 040ed59a authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

Now newSyncFigures works server side

tested
parent e5cf3138
......@@ -119,7 +119,7 @@ elif(D_HIERARCHY in ('SERVER', 'server')):
from .test import readStupidData
SERVER_IOFUNCTIONS = {'readStupidData': readStupidData}
SERVER_FIGURES = {'FigTest', FigTest}
SERVER_FIGURES = {'FigTest': FigTest}
from .mplServer import MplServer
......
......@@ -187,6 +187,13 @@ class MplServer():
# Try to extract instructions
dataName, fct, args, kwargs = self.unpackReadDataInstructions(conn, instructions)
if DEBUG:
print(INFO+"I got: ")
print(SPCE+" dataName: "+str(dataName))
print(SPCE+" fct: "+str(fct.__name__))
print(SPCE+" args: "+str(args))
print(SPCE+" kwargs: "+ str(kwargs))
# If failed
if (not self.connected):
if (DEBUG):
......@@ -258,7 +265,8 @@ class MplServer():
kwargs = '{}'
try:
dataName, fct, args, kwargs = eval(str(instructions))
# dataName, fct, args, kwargs = eval(str(instructions))
dataName, fct, args, kwargs = instructions
except:
if(DEBUG):
print(WARN+"SERVER: The instructions of readData could not be extracted.")
......@@ -270,8 +278,8 @@ class MplServer():
self.closeConnection(conn)
fct = self.knownFunctions.get(fct, emptyfct) # SHOULD DEFINE EMPTY FUNCTION
args = eval(args)
kwargs = eval(kwargs)
# args = eval(args)
# kwargs = eval(kwargs)
return(dataName, fct, args, kwargs)
......@@ -284,7 +292,75 @@ class MplServer():
4. create figure with corresponding rawdata
5. send FigureID
'''
pass
# Send a receipt
self.sendReceipt(conn)
# Wait for the Instructions of given size
instructions = self.waitForInstructions(conn, instrucSize)
# If exchanged failed
if (not self.connected):
if (DEBUG):
print(WARN+"SERVER: Connection interupted due to error. (1)")
return(False)
# THIS HAS TO BE DONE IN A BETTER WAY CATCHING EXCEPTION AND DISANTANGLE UNCAPSULATION AND UNPACK
header, instructions = eval(instructions)
# Try to extract instructions
FigClass, rawdata, kwargs = self.unpackNewSyncFigureInstructions(conn, instructions)
# If failed
if (not self.connected):
if (DEBUG):
print(WARN+"SERVER: Connection interupted due to error. (2)")
return(False)
else:
if DEBUG:
print(INFO+"I got: ")
print(SPCE+" FigClass: "+str(FigClass.__name__))
print(SPCE+" FigClass.bases: "+str(FigClass.__bases__))
print(SPCE+" rawdata: "+str(rawdata))
print(SPCE+" kwargs: "+ str(kwargs))
# Verify if rawdata are complete
datas = ()
for name in rawdata:
try:
datas = datas + (G_RAWDATA[name],)
except:
if(DEBUG):
print(WARN+"SERVER: I could not find data: "+str(name))
answer = ('newSyncFigure', 'False', 'could not find data: '+str(name))
self.sendAnswer(conn, answer)
self.closeConnection(conn)
return(False)
# Generate an FigID
FigID = '26042017'
# Try to create the requested figure
try:
G_FIGURES[FigID] = FigClass(datas, **kwargs)
if (DEBUG):
print(INFO+"SERVER: I created the requested Figure")
print(repr(G_FIGURES[FigID])) # SHOULD BE SUPPRESS LATER
except:
if(DEBUG):
print(WARN+"SERVER: I could not create the requested Figure.")
print(SPCE+"SERVER: I tried: "+str(FigClass.__name__)+'('+str(datas)+', '+str(kwargs)+')')
answer = ('newSyncFigure', 'False', 'could not create requested Figure.')
self.sendAnswer(conn, answer)
self.closeConnection(conn)
return(False)
# Send the final message
answer = ('newSyncFigure', FigID, 'Requested Figure created with success.')
self.sendAnswer(conn, answer)
return(True)
# try:
# (figClassName, rawdata, kwargs) = eval(str(content))
......@@ -317,6 +393,24 @@ class MplServer():
## return(answer)
#
# UNPACK NEW SYNC FIGURE INSTRCUCTIONS
def unpackNewSyncFigureInstructions(self, conn, instructions):
figClassName, rawdata, kwargs = instructions
print(figClassName)
try:
FigClass = self.knownFigures[figClassName]
except:
if DEBUG:
print(WARN+"The figure class: "+figClassName+" is not known by server.")
answer = ('newSyncFigure', 'False', 'FigClass: '+figClassName+' is not known.')
self.sendAnswer(conn, answer)
self.closeConnection(conn)
return(('', (), {}))
return((FigClass, rawdata, kwargs))
# SIGNAL UPDATE SYNC FIGURE ----------------------------------------
def treatUpdateSyncFigure(self, conn, instrucSize):
'''Treat signals of type updateSyncFigure
......
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