Commit d8f6ff63 authored by Yori Fournier's avatar Yori Fournier
Browse files

FEATURE added merge_data function. not tested.

parent ed74e0e7
Pipeline #652 canceled with stage
......@@ -131,6 +131,19 @@ class MplClient():
self.disconnect()
return self.test_status_sig(query, status_sig)
def merge_data(self, merged_name, data_names):
# create a Signal of type Query with arguments
self.connect((self.host, self.port))
query = Query(Query.MERGEDATA, {'merged_data': merged_data,
'data_names': data_names,}
status = self.send(query)
if not status:
print('''something went wrong with the
sending of readData request...''')
status_sig = self.wait_for_signal()
self.disconnect()
return self.test_status_sig(query, status_sig)
def list_remote_data(self):
""" The server retuns a list with the content of its G_RAWDATA
"""
......
......@@ -67,6 +67,24 @@ class MplHandler(socketserver.StreamRequestHandler):
return False # should never get here
def treat_merge_data(self, content):
'''Treat signals of type merge Data.
'''
data_names = content.get('data_names')
merged_name = content.get('merged_name')
merged_data = []
# Try to execute the instructions
try:
for data_name in data_names:
merged_data.append(self.server._rawdata[data_name].data)
self.server._rawdata[merged_name] = MplData(data=merged_data, name=merged_name)
except Exception:
pass
return False # should never get here
def treat_new_sync_figure(self, content):
# Try to create the requested figure
......@@ -195,6 +213,8 @@ class MplHandler(socketserver.StreamRequestHandler):
if isinstance(request, Query):
if request.query_type == request.READDATA:
reply = self.treat_read_data(request.content)
if request.query_type == request.MERGEDATA:
reply = self.treat_merge_data(request.content)
elif request.query_type == request.NEWSYNCFIGURE:
reply = self.treat_new_sync_figure(request.content)
elif request.query_type == request.UPDATESYNCFIGURE:
......
......@@ -14,8 +14,9 @@ class Query(Signal):
LISTDATA = 6
GETDATA = 7
LISTFIG = 8
MERGEDATA = 9
NBR_OF_QUERY_TYPES = 8
NBR_OF_QUERY_TYPES = 9
def __init__(self, query_type, content):
if query_type in range(1, Query.NBR_OF_QUERY_TYPES + 1):
......@@ -53,6 +54,9 @@ class Query(Signal):
elif query_type == Query.LISTFIG:
self.content = content
elif query_type == Query.MERGEDATA:
self.content = content
else:
print('unknown query type!')
raise UserWarning
......
Supports Markdown
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