Skip to content

Commit

Permalink
Merge 84e188f into feb29a7
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Aug 15, 2019
2 parents feb29a7 + 84e188f commit 8dab7d8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Change History
* `#226 <https://github.com/prjemian/spec2nexus/issues/226>`_
writer: unit tests for empty #O0 & P0 control lines
* `#224 <https://github.com/prjemian/spec2nexus/issues/224>`_
rename: list_recent_scans --> scanlist
rename: list_recent_scans --> listscans
* `#222 <https://github.com/prjemian/spec2nexus/issues/222>`_
writer: add empty #O0 and #P0 lines
* `#220 <https://github.com/prjemian/spec2nexus/issues/220>`_
Expand Down
38 changes: 22 additions & 16 deletions apstools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,34 +187,41 @@ def itemizer(fmt, items):
return [fmt % k for k in items]


def list_recent_scans(num=20, keys=[], printing=True, show_command=False, db=None):
def list_recent_scans(raises=False, **kwargs):
"""(deprecated): use ``listruns`` instead"""
msg = "'list_recent_scans()' is deprecated"
msg += ", use 'listruns()' instead"
if raises:
raise RuntimeWarning(msg)
logger.warning(msg)
return listruns(**kwargs)


def listruns(
num=20, keys=[], printing=True, show_command=True,
exit_status=True, db=None):
"""
make a table of the most recent scans
make a table of the most recent runs (scans)
PARAMETERS
num : int
Make the table include the ``num`` most recent scans.
Make the table include the ``num`` most recent runs.
(default: ``20``)
keys : [str]
Include these additional keys from the start document.
(default: ``[]``)
Two special keys are supported:
* ``command`` : shows the scan command.
(note: This command is reconstructed from keys in the start
document so it will not be exactly as the user typed.
Also, it will be truncated so that it is no more than 40 characters.)
* ``exit_status`` : from the stop document
printing : bool
If True, print the table to stdout
(default: ``True``)
show_command : bool
If True, show the (reconstructed) full command,
but truncate it to no more than 40 characters)
(default: ``False``)
(note: This command is reconstructed from keys in the start
document so it will not be exactly as the user typed.)
(default: ``True``)
exit_status : bool
How the run ended, as reported in the ``stop`` document.
db : object
Instance of ``databroker.Broker()``
(default: ``db`` from the IPython shell)
Expand Down Expand Up @@ -247,12 +254,13 @@ def list_recent_scans(num=20, keys=[], printing=True, show_command=False, db=Non
labels = "scan_id plan_name".split() + keys

table = pyRestTable.Table()
table.labels = "short_uid date/time".split() + labels
table.labels = "short_uid date/time exit".split() + labels

for h in db[-abs(num):]:
row = [
h.start["uid"][:7],
datetime.datetime.fromtimestamp(h.start['time']),
h.stop.get("exit_status", "")
]
for k in labels:
if k == "command":
Expand All @@ -263,8 +271,6 @@ def list_recent_scans(num=20, keys=[], printing=True, show_command=False, db=Non
suffix = " ..."
command = command[:maxlen-len(suffix)] + suffix
row.append(command)
elif k == "exit_status":
row.append(h.stop.get(k, ""))
else:
row.append(h.start.get(k, ""))
table.addRow(row)
Expand Down
14 changes: 10 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,17 @@ def tearDown(self):
pass

def test_list_recent_scans(self):
with self.assertRaises(RuntimeWarning):
APS_utils.list_recent_scans(db=self.db, raises=True)

table = APS_utils.list_recent_scans(printing=False, db=self.db)
self.assertIsNotNone(table)

def test_listruns(self):
headers = self.db(plan_name="count")
headers = list(headers)[0:1]
self.assertEqual(len(headers), 1)
table = APS_utils.list_recent_scans(
keys=["exit_status",],
table = APS_utils.listruns(
show_command=True,
printing=False,
num=10,
Expand All @@ -197,14 +203,14 @@ def test_list_recent_scans(self):
self.assertIsNotNone(table)
self.assertEqual(
len(table.labels),
5,
3+2,
"asked for 2 extra columns (total 5)")
self.assertEqual(
len(table.rows),
10,
"asked for 10 rows")
self.assertLessEqual(
len(table.rows[1][3]),
len(table.rows[1][4]),
40,
"command row should be 40 char or less")

Expand Down

0 comments on commit 8dab7d8

Please sign in to comment.