provide setup for MLZ_Amagnet to be used @PSI soon

Also implement lots of fixes and improvements.

fixes: #3381

Change-Id: Ibe6664da00756ae5813b90f190295045808b2ff0
This commit is contained in:
Enrico Faulhaber
2017-07-20 16:29:21 +02:00
parent 63418fce04
commit 2bb96bea70
31 changed files with 1510 additions and 403 deletions

View File

@ -269,7 +269,7 @@ class Dispatcher(object):
# now call func and wrap result as value
# note: exceptions are handled in handle_request, not here!
func = getattr(moduleobj, 'do' + command)
func = getattr(moduleobj, 'do_' + command)
res = func(*arguments)
res = CommandReply(
module=modulename,
@ -319,12 +319,14 @@ class Dispatcher(object):
# note: exceptions are handled in handle_request, not here!
readfunc()
if pobj.timestamp:
return Value(
res = Value(
modulename,
parameter=pname,
value=pobj.export_value,
t=pobj.timestamp)
return Value(modulename, parameter=pname, value=pobj.export_value)
else:
res = Value(modulename, parameter=pname, value=pobj.export_value)
return res
# now the (defined) handlers for the different requests
def handle_Help(self, conn, msg):
@ -404,6 +406,10 @@ class Dispatcher(object):
unit=pobj.unit)
if res.value != Ellipsis: # means we do not have a value at all so skip this
self.broadcast_event(res)
else:
self.log.error(
'activate: got no value for %s:%s!' %
modulename, pname)
conn.queue_async_reply(ActivateReply(**msg.as_dict()))
return None

View File

@ -39,12 +39,12 @@ class MessageEncoder(object):
raise NotImplemented
from demo_v2 import DemoEncoder as DemoEncoderV2
from demo_v3 import DemoEncoder as DemoEncoderV3
from demo_v4 import DemoEncoder as DemoEncoderV4
from text import TextEncoder
from pickle import PickleEncoder
from simplecomm import SCPEncoder
from .demo_v2 import DemoEncoder as DemoEncoderV2
from .demo_v3 import DemoEncoder as DemoEncoderV3
from .demo_v4 import DemoEncoder as DemoEncoderV4
from .text import TextEncoder
from .pickle import PickleEncoder
from .simplecomm import SCPEncoder
ENCODERS = {
'pickle': PickleEncoder,

View File

@ -24,6 +24,8 @@
# implement as class as they may need some internal 'state' later on
# (think compressors)
from __future__ import print_function
from secop.protocol.encoding import MessageEncoder
from secop.protocol import messages
from secop.lib.parsing import *
@ -43,9 +45,9 @@ class DemoEncoder(MessageEncoder):
if match:
novalue, devname, pname, propname, assign = match.groups()
if assign:
print "parsing", assign,
print("parsing", assign,)
assign = parse_args(assign)
print "->", assign
print("->", assign)
return messages.DemoRequest(novalue, devname, pname, propname,
assign)
return messages.HelpRequest()
@ -56,13 +58,13 @@ class DemoEncoder(MessageEncoder):
handler_name = '_encode_' + msg.__class__.__name__
handler = getattr(self, handler_name, None)
if handler is None:
print "Handler %s not yet implemented!" % handler_name
print("Handler %s not yet implemented!" % handler_name)
try:
args = dict((k, msg.__dict__[k]) for k in msg.ARGS)
result = handler(**args)
except Exception as e:
print "Error encoding %r with %r!" % (msg, handler)
print e
print("Error encoding %r with %r!" % (msg, handler))
print(e)
return '~InternalError~'
return result

View File

@ -24,6 +24,8 @@
# implement as class as they may need some internal 'state' later on
# (think compressors)
from __future__ import print_function
from secop.protocol.encoding import MessageEncoder
from secop.protocol.messages import *
from secop.protocol.errors import ProtocolError
@ -257,7 +259,7 @@ class DemoEncoder(MessageEncoder):
mgroups['args'] = args
# reformat qualifiers
print mgroups
print(mgroups)
quals = dict(
qual.split('=', 1)
for qual in helper(mgroups.pop('qualifiers', ';')))
@ -306,9 +308,9 @@ class DemoEncoder(MessageEncoder):
'read blub:c=14;t=3.3',
]
for m in testmsg:
print repr(m)
print self.decode(m)
print
print(repr(m))
print(self.decode(m))
print()
DEMO_RE_MZ = re.compile(
@ -326,7 +328,7 @@ class DemoEncoder_MZ(MessageEncoder):
def decode(sef, encoded):
m = DEMO_RE_MZ.match(encoded)
if m:
print "implement me !"
print("implement me !")
return HelpRequest()
def encode(self, msg):

View File

@ -24,6 +24,8 @@
# implement as class as they may need some internal 'state' later on
# (think compressors)
from __future__ import print_function
from secop.lib.parsing import format_time
from secop.protocol.encoding import MessageEncoder
from secop.protocol.messages import *
@ -235,7 +237,7 @@ class DemoEncoder(MessageEncoder):
# first check beginning
match = DEMO_RE.match(encoded)
if not match:
print repr(encoded), repr(IDENTREPLY)
print(repr(encoded), repr(IDENTREPLY))
if encoded == IDENTREPLY: # XXX:better just check the first 2 parts...
return IdentifyReply(version_string=encoded)
@ -274,9 +276,9 @@ class DemoEncoder(MessageEncoder):
origin=encoded)
def tests(self):
print "---- Testing encoding -----"
print("---- Testing encoding -----")
for msgclass, parts in sorted(self.ENCODEMAP.items()):
print msgclass
print(msgclass)
e = self.encode(
msgclass(
module='<module>',
@ -289,17 +291,17 @@ class DemoEncoder(MessageEncoder):
nonce='<nonce>',
errorclass='InternalError',
errorinfo='nix'))
print e
print self.decode(e)
print
print "---- Testing decoding -----"
print(e)
print(self.decode(e))
print()
print("---- Testing decoding -----")
for msgtype, _ in sorted(self.DECODEMAP.items()):
msg = '%s a:b 3' % msgtype
if msgtype == EVENT:
msg = '%s a:b [3,{"t":193868}]' % msgtype
print msg
print(msg)
d = self.decode(msg)
print d
print self.encode(d)
print
print "---- Testing done -----"
print(d)
print(self.encode(d))
print()
print("---- Testing done -----")

View File

@ -91,9 +91,3 @@ EXCEPTIONS = dict(
Readonly=ReadonlyError,
CommandFailed=CommandFailedError,
InvalidParam=InvalidParamValueError, )
if __name__ == '__main__':
print("Minimal testing of errors....")
print "OK"
print

View File

@ -45,10 +45,10 @@ class Framer(object):
raise NotImplemented
# now some Implementations
from null import NullFramer
from eol import EOLFramer
from rle import RLEFramer
from demo import DemoFramer
from .null import NullFramer
from .eol import EOLFramer
from .rle import RLEFramer
from .demo import DemoFramer
FRAMERS = {
'null': NullFramer,