Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Yori Fournier
myplotlib
Commits
5a759ecb
Commit
5a759ecb
authored
Sep 16, 2017
by
Yori 'AGy' Fournier
Browse files
Now syncFigFormatRawData server-size
parent
38e4d065
Changes
1
Hide whitespace changes
Inline
Side-by-side
mplServer.py
View file @
5a759ecb
...
...
@@ -12,6 +12,8 @@ from . import SERVER_FIGURES
G_RAWDATA
=
{}
G_FIGURES
=
{}
SIZE_STATUS_MAX
=
1024
def
emptyfct
():
return
(
False
)
...
...
@@ -232,13 +234,7 @@ class MplServer():
by the client.'''
# Generate a string of a tuple of strings
packedData
=
'('
for
string
in
formattedData
:
packedData
=
packedData
+
"
\"
"
+
str
(
string
)
+
"
\"
"
+
', '
packedData
=
packedData
+
")"
return
(
packedData
)
return
(
str
(
formattedData
))
# PACKING ----------------------------------------------------------
def
packAnswer
(
self
,
answer
):
...
...
@@ -357,7 +353,7 @@ class MplServer():
return
(
False
)
# Send the final message
answer
=
(
'newSyncFigure'
,
FigID
,
'Requested Figure created with success.'
)
answer
=
(
'newSyncFigure'
,
"'"
+
FigID
+
"'"
,
'Requested Figure created with success.'
)
self
.
sendAnswer
(
conn
,
answer
)
return
(
True
)
...
...
@@ -423,7 +419,7 @@ class MplServer():
pass
# SIGNAL SYNC FIGURE FORMAT RAWDATA --------------------------------
def
treatSyncFigFormatRawData
(
self
,
conn
,
instrucSize
):
def
treatSyncFigFormatRawData
(
self
,
conn
,
figID
):
'''Treat signals of type SyncFigFormatRawData.
1. unpack signal with FigID,
2. Identify Figure and formatRawData,
...
...
@@ -431,47 +427,63 @@ class MplServer():
4. wait for receipt
5. send packedFormattedData
'''
pass
# try:
# (figID,) = eval(str(content))
# except:
# print(WARN+"The content of syncFigFormatRawData could not be extracted")
# print(SPCE+'Received: '+str(content))
# print(SPCE+"I expect '(figID,)'")
# answer = ('syncFigFormatRawData', None, 'could not extract content')
# return(answer)
#
# try:
# fig = G_FIGURES[figID]
# except:
# print(WARN+"Figure ID does not exists.")
# print(SPCE+str(figID))
# answer = ('syncFigFormatRawData', None, 'Figure ID does not exists.')
#
# try:
# fig.formatRawData()
# except:
# print(WARN+'Could not format the rawdata of the figure.')
# answer = ('syncFigFormatRawData', None, 'Could not format the rawdata of the figure.')
#
# datas = []
# for ax in fig.get_axes():
# # ax.data is any user defined object
# # ax.packFormattedData returns it's string representation
# # to be unpacked by ax.unpackFormattedData
# datas.append(ax.packFormattedData(ax.data))
#
# packedData = self.packFormattedData(datas)
#
# answer = ('syncFigFormatRawData', packedData, '')
#
# Identify the figure
try
:
fig
=
G_FIGURES
[
figID
]
except
:
if
DEBUG
:
print
(
WARN
+
"The figure ID: "
+
figID
+
" does not exist."
)
answer
=
(
'newSyncFigure'
,
'False'
,
'FigID: '
+
figID
+
' does not exist.'
)
self
.
sendAnswer
(
conn
,
answer
)
self
.
closeConnection
(
conn
)
return
(
False
)
# Format the rawdata
try
:
fig
.
formatRawData
()
except
:
if
DEBUG
:
print
(
WARN
+
"I couldn't format the rawdata."
)
answer
=
(
'newSyncFigure'
,
'False'
,
'The Server could not format the rawdata.'
)
self
.
sendAnswer
(
conn
,
answer
)
self
.
closeConnection
(
conn
)
return
(
False
)
# pack the data and compute its size
datas
=
()
for
ax
in
fig
.
get_axes
():
# ax.data is any user defined object
# ax.packFormatteata returns it's string representation
# to be unpacked by ax.unpackFormattedData
# datas.append(ax.packFormattedData(ax.data))
datas
=
datas
+
(
ax
.
data
,)
packedData
=
self
.
packFormattedData
(
datas
)
answer
=
(
'syncFigFormatRawData'
,
packedData
,
'The figure could format the rawData.'
)
print
(
answer
)
dataSize
=
len
(
str
(
answer
))
+
2
# Send the size of the data
self
.
sendAnswer
(
conn
,
(
'syncFigFormatRawData'
,
dataSize
,
'The figure could format the rawData.'
))
# Wait for the client receipt
status
=
self
.
waitForReceipt
(
conn
)
# If failed
if
not
status
:
self
.
closeConnection
(
conn
)
# Send the packed Formatted data
self
.
sendAnswer
(
conn
,
answer
)
return
(
True
)
# SEND ANSWER ------------------------------------------------------
def
sendAnswer
(
self
,
conn
,
answer
):
'''Send an answer to all clients.'''
answer
=
self
.
packAnswer
(
answer
)
conn
.
sendall
(
str
(
answer
)
)
conn
.
sendall
(
answer
)
return
(
True
)
# SEND RECEIPT -----------------------------------------------------
...
...
@@ -492,9 +504,34 @@ class MplServer():
# WAIT FOR SIGNAL --------------------------------------------------
def
waitForSignal
(
self
,
conn
):
'''Wait for a signal.'''
signal
=
conn
.
recv
(
1024
)
signal
=
conn
.
recv
(
SIZE_STATUS_MAX
)
return
(
signal
)
# WAIT FOR SIGNAL --------------------------------------------------
def
waitForReceipt
(
self
,
conn
):
'''Wait for a receipt.'''
receipt
=
conn
.
recv
(
SIZE_STATUS_MAX
)
status
=
False
header
=
''
errmsg
=
''
try
:
header
,
status
,
errmsg
=
eval
(
receipt
)
except
:
print
(
SEVR
+
'Could not extract the receit.'
)
print
(
SEVR
+
'Received: '
+
str
(
receipt
))
self
.
closeConnection
(
conn
)
return
(
False
)
# I should prevent that
status
=
eval
(
status
)
if
not
status
:
print
(
SEVR
+
"CLIENT: "
+
str
(
errmsg
))
return
(
status
)
# WAIT FOR INSTRUCTIONS --------------------------------------------
def
waitForInstructions
(
self
,
conn
,
size
):
'''Wait for instruction of given size.'''
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment