5959import xlrd
6060import zipfile
6161
62+ from .filewriters import _rebuild_scan_command
63+
6264
6365logger = logging .getLogger (__name__ )
6466
@@ -182,7 +184,7 @@ def itemizer(fmt, items):
182184 return [fmt % k for k in items ]
183185
184186
185- def list_recent_scans (num = 20 , keys = [], printing = True , db = None ):
187+ def list_recent_scans (num = 20 , keys = [], printing = True , show_command = False , db = None ):
186188 """
187189 make a table of the most recent scans
188190
@@ -192,8 +194,20 @@ def list_recent_scans(num=20, keys=[], printing=True, db=None):
192194 Make the table include the ``num`` most recent scans.
193195 keys : [str] (default: ``[]``)
194196 Include these additional keys from the start document.
197+
198+ Two special keys are supported:
199+
200+ * ``command`` : shows the scan command.
201+ (note: This command is reconstructed from keys in the start
202+ document so it will not be exactly as the user typed.
203+ Also, it will be truncated so that it is no more than 40 characters.)
204+ * ``exit_status`` : from the stop document
205+
195206 printing : bool (default: ``True``)
196207 If True, print the table to stdout
208+ show_command : bool (default: ``False``)
209+ If True, show the (reconstructed) full command,
210+ but truncate it to no more than 40 characters)
197211 db : object (default: ``db`` from the IPython shell)
198212 Instance of ``databroker.Broker()``
199213
@@ -223,7 +237,10 @@ def list_recent_scans(num=20, keys=[], printing=True, db=None):
223237 global_db = None
224238 db = db or global_db
225239
226- labels = "scan_id plan_name" .split () + keys
240+ if show_command :
241+ labels = "scan_id command" .split () + keys
242+ else :
243+ labels = "scan_id plan_name" .split () + keys
227244
228245 table = pyRestTable .Table ()
229246 table .labels = "short_uid date/time" .split () + labels
@@ -232,7 +249,20 @@ def list_recent_scans(num=20, keys=[], printing=True, db=None):
232249 row = [
233250 h .start ["uid" ][:7 ],
234251 datetime .datetime .fromtimestamp (h .start ['time' ]),
235- ] + [h .start .get (k , "" ) for k in labels ]
252+ ]
253+ for k in labels :
254+ if k == "command" :
255+ command = _rebuild_scan_command (h .start )
256+ command = command [command .find (" " ):].strip ()
257+ maxlen = 40
258+ if len (command ) > maxlen :
259+ suffix = " ..."
260+ command = command [:maxlen - len (suffix )] + suffix
261+ row .append (command )
262+ elif k == "exit_status" :
263+ row .append (h .stop .get (k , "" ))
264+ else :
265+ row .append (h .start .get (k , "" ))
236266 table .addRow (row )
237267
238268 if printing :
0 commit comments