Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion apstools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
~ipython_profile_name
~pairwise
~print_snapshot_list
~print_RE_md
~text_encode
~to_unicode_or_bust
~trim_string_for_EPICS
Expand Down Expand Up @@ -90,13 +91,14 @@ def dictionary_table(dictionary, fmt="simple"):
RETURNS

table : str or `None`
multi-line text table with dictionary contents
multiline text table with dictionary contents in chosen format
or ``None`` if dictionary has no contents

EXAMPLE::

In [8]: RE.md
Out[8]: {'login_id': 'jemian:wow.aps.anl.gov', 'beamline_id': 'developer', 'proposal_id': None, 'pid': 19072, 'scan_id': 10, 'version': {'bluesky': '1.5.2', 'ophyd': '1.3.3', 'apstools': '1.1.5', 'epics': '3.3.3'}}

In [9]: print(dictionary_table(RE.md))
=========== =============================================================================
key value
Expand All @@ -108,6 +110,7 @@ def dictionary_table(dictionary, fmt="simple"):
scan_id 10
version {'bluesky': '1.5.2', 'ophyd': '1.3.3', 'apstools': '1.1.5', 'epics': '3.3.3'}
=========== =============================================================================

"""
if len(dictionary) == 0:
return
Expand All @@ -119,6 +122,42 @@ def dictionary_table(dictionary, fmt="simple"):
return _t.reST(fmt=fmt)


def print_RE_md(dictionary=RE.md, fmt="simple"):
"""
custom print the RunEngine metadata in a table

EXAMPLE::

In [4]: print_RE_md()
RunEngine metadata dictionary:
======================== ===================================
key value
======================== ===================================
EPICS_CA_MAX_ARRAY_BYTES 1280000
EPICS_HOST_ARCH linux-x86_64
beamline_id APS USAXS 9-ID-C
login_id usaxs:usaxscontrol.xray.aps.anl.gov
pid 67933
proposal_id testing Bluesky installation
scan_id 0
versions ======== =====
key value
======== =====
apstools 1.1.3
bluesky 1.5.2
epics 3.3.1
ophyd 1.3.3
======== =====
======================== ===================================

"""
md = dict(dictionary) # copy of input for editing
v = dictionary_table(md["versions"], fmt=fmt) # sub-table
md["versions"] = str(v).rstrip()
print("RunEngine metadata dictionary:")
print(dictionary_table(md, fmt=fmt))


def pairwise(iterable):
"""
break a list (or other iterable) into pairs
Expand Down