Tue, 18 Dec 2007 00:38:33 +0100
make header_formatter a little bit smarter (interpret bool values when it can)
HP3562A/__init__.py | file | annotate | diff | comparison | revisions |
--- a/HP3562A/__init__.py Tue Dec 18 00:23:10 2007 +0100 +++ b/HP3562A/__init__.py Tue Dec 18 00:38:33 2007 +0100 @@ -13,6 +13,7 @@ """ import struct +import re import gpib ######################################## @@ -52,13 +53,29 @@ """ Pretty print a data block (trace, state or coord) """ + bool_re = re.compile(r'((?P<before>.*) )?(?P<flag>\w+/\w+)( (?P<after>.*))?') + todisp = [] for row in head_struct: - key = row[0] + key = row[0] + typ = row[1] val = header.get(key, "N/A") if isinstance(val, basestring): val = repr(val) - else: + elif typ is bool and isinstance(val, typ): + m = bool_re.match(key) + if m: + d = m.groupdict() + key = "" + if d['before']: + key += d['before'] + if d['after']: + key += d['after'] + key = key.capitalize() + val = d['flag'].split('/')[not val] + else: + val = str(val) + else: val = str(val) todisp.append((key+":", val)) maxk = max([len(k) for k, v in todisp])