improve formatting of values
Change-Id: I4a9290e85ee2071a3f2cfe0d00bc7dc4dcb4caed
This commit is contained in:
parent
0b9e227669
commit
3ab9821860
@ -23,11 +23,11 @@
|
||||
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import re
|
||||
from queue import Queue
|
||||
from secop.client import SecopClient
|
||||
from secop.errors import SECoPError
|
||||
from secop.datatypes import get_datatype
|
||||
|
||||
USAGE = """
|
||||
Usage:
|
||||
@ -97,15 +97,12 @@ class Module:
|
||||
|
||||
def _one_line(self, pname, minwid=0):
|
||||
"""return <module>.<param> = <value> truncated to one line"""
|
||||
param = getattr(type(self), pname)
|
||||
try:
|
||||
value = getattr(self, pname)
|
||||
# make floats appear with 7 digits only
|
||||
r = repr(json.loads(json.dumps(value), parse_float=PrettyFloat))
|
||||
r = param.format(value)
|
||||
except Exception as e:
|
||||
r = repr(e)
|
||||
unit = getattr(type(self), pname).unit
|
||||
if unit:
|
||||
r += ' %s' % unit
|
||||
pname = pname.ljust(minwid)
|
||||
vallen = 113 - len(self._name) - len(pname)
|
||||
if len(r) > vallen:
|
||||
@ -192,11 +189,11 @@ class Module:
|
||||
|
||||
|
||||
class Param:
|
||||
def __init__(self, name, unit=None):
|
||||
def __init__(self, name, datainfo):
|
||||
self.name = name
|
||||
self.prev = None
|
||||
self.prev_time = 0
|
||||
self.unit = unit
|
||||
self.datatype = get_datatype(datainfo)
|
||||
|
||||
def __get__(self, obj, owner):
|
||||
if obj is None:
|
||||
@ -214,6 +211,9 @@ class Param:
|
||||
except SECoPError as e:
|
||||
obj._secnode.log.error(repr(e))
|
||||
|
||||
def format(self, value):
|
||||
return self.datatype.format_value(value)
|
||||
|
||||
|
||||
class Command:
|
||||
def __init__(self, name, modname, secnode):
|
||||
@ -266,8 +266,7 @@ class Client(SecopClient):
|
||||
self.log.info('overwrite module %s', modname)
|
||||
attrs = {}
|
||||
for pname, pinfo in moddesc['parameters'].items():
|
||||
unit = pinfo['datainfo'].get('unit')
|
||||
attrs[pname] = Param(pname, unit)
|
||||
attrs[pname] = Param(pname, pinfo['datainfo'])
|
||||
for cname in moddesc['commands']:
|
||||
attrs[cname] = Command(cname, modname, self)
|
||||
mobj = type('M_%s' % modname, (Module,), attrs)(modname, self)
|
||||
|
Loading…
x
Reference in New Issue
Block a user