|
5 | 5 | |
6 | 6 | ~cleanupText |
7 | 7 | ~connect_pvlist |
| 8 | + ~dictionary_table |
8 | 9 | ~EmailNotifications |
9 | 10 | ~ExcelDatabaseFileBase |
10 | 11 | ~ExcelDatabaseFileGeneric |
|
13 | 14 | ~ipython_profile_name |
14 | 15 | ~pairwise |
15 | 16 | ~print_snapshot_list |
| 17 | + ~print_RE_md |
16 | 18 | ~text_encode |
17 | 19 | ~to_unicode_or_bust |
18 | 20 | ~trim_string_for_EPICS |
@@ -71,6 +73,91 @@ def mapper(c): |
71 | 73 | return "".join([mapper(c) for c in text]) |
72 | 74 |
|
73 | 75 |
|
| 76 | +def dictionary_table(dictionary, fmt="simple"): |
| 77 | + """ |
| 78 | + return a text table from ``dictionary`` |
| 79 | + |
| 80 | + PARAMETERS |
| 81 | + |
| 82 | + dictionary : dict |
| 83 | + Python dictionary |
| 84 | + fmt : str |
| 85 | + Any of the format names provided by |
| 86 | + `spec2nexus <https://pyresttable.readthedocs.io/en/latest/examples/index.html#examples>`_ |
| 87 | + One of these: ``simple | plain | grid | complex | markdown | list-table | html`` |
| 88 | + |
| 89 | + default: ``simple`` |
| 90 | + |
| 91 | + RETURNS |
| 92 | +
|
| 93 | + table : str or `None` |
| 94 | + multiline text table with dictionary contents in chosen format |
| 95 | + or ``None`` if dictionary has no contents |
| 96 | + |
| 97 | + EXAMPLE:: |
| 98 | +
|
| 99 | + In [8]: RE.md |
| 100 | + 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'}} |
| 101 | +
|
| 102 | + In [9]: print(dictionary_table(RE.md)) |
| 103 | + =========== ============================================================================= |
| 104 | + key value |
| 105 | + =========== ============================================================================= |
| 106 | + beamline_id developer |
| 107 | + login_id jemian:wow.aps.anl.gov |
| 108 | + pid 19072 |
| 109 | + proposal_id None |
| 110 | + scan_id 10 |
| 111 | + version {'bluesky': '1.5.2', 'ophyd': '1.3.3', 'apstools': '1.1.5', 'epics': '3.3.3'} |
| 112 | + =========== ============================================================================= |
| 113 | +
|
| 114 | + """ |
| 115 | + if len(dictionary) == 0: |
| 116 | + return |
| 117 | + _t = pyRestTable.Table() |
| 118 | + _t.addLabel("key") |
| 119 | + _t.addLabel("value") |
| 120 | + for k, v in sorted(dictionary.items()): |
| 121 | + _t.addRow((k, str(v))) |
| 122 | + return _t.reST(fmt=fmt) |
| 123 | + |
| 124 | + |
| 125 | +def print_RE_md(dictionary=RE.md, fmt="simple"): |
| 126 | + """ |
| 127 | + custom print the RunEngine metadata in a table |
| 128 | + |
| 129 | + EXAMPLE:: |
| 130 | +
|
| 131 | + In [4]: print_RE_md() |
| 132 | + RunEngine metadata dictionary: |
| 133 | + ======================== =================================== |
| 134 | + key value |
| 135 | + ======================== =================================== |
| 136 | + EPICS_CA_MAX_ARRAY_BYTES 1280000 |
| 137 | + EPICS_HOST_ARCH linux-x86_64 |
| 138 | + beamline_id APS USAXS 9-ID-C |
| 139 | + login_id usaxs:usaxscontrol.xray.aps.anl.gov |
| 140 | + pid 67933 |
| 141 | + proposal_id testing Bluesky installation |
| 142 | + scan_id 0 |
| 143 | + versions ======== ===== |
| 144 | + key value |
| 145 | + ======== ===== |
| 146 | + apstools 1.1.3 |
| 147 | + bluesky 1.5.2 |
| 148 | + epics 3.3.1 |
| 149 | + ophyd 1.3.3 |
| 150 | + ======== ===== |
| 151 | + ======================== =================================== |
| 152 | + |
| 153 | + """ |
| 154 | + md = dict(dictionary) # copy of input for editing |
| 155 | + v = dictionary_table(md["versions"], fmt=fmt) # sub-table |
| 156 | + md["versions"] = str(v).rstrip() |
| 157 | + print("RunEngine metadata dictionary:") |
| 158 | + print(dictionary_table(md, fmt=fmt)) |
| 159 | + |
| 160 | + |
74 | 161 | def pairwise(iterable): |
75 | 162 | """ |
76 | 163 | break a list (or other iterable) into pairs |
|
0 commit comments