Skip to content

Commit

Permalink
Add dsari-info shell
Browse files Browse the repository at this point in the history
  • Loading branch information
rfinnie committed Sep 25, 2016
1 parent 5fde2d3 commit 41152d4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/dsari-info.1
Expand Up @@ -47,6 +47,12 @@ List recorded runs.
Options: \f[I]\-\-job\f[], \f[I]\-\-run\f[], \f[I]\-\-format\f[],
\f[I]\-\-epoch\f[]
.RE
.TP
.B shell
Enter a Python shell, with several dsari\-specific variables pre\-loaded
(config, db, etc).
.RS
.RE
.SH OPTIONS
.TP
.B \-\-config\-dir=\f[I]directory\f[], \-c \f[I]directory\f[]
Expand Down
3 changes: 3 additions & 0 deletions doc/dsari-info.md
Expand Up @@ -36,6 +36,9 @@ list-runs

Options: *--job*, *--run*, *--format*, *--epoch*

shell
: Enter a Python shell, with several dsari-specific variables pre-loaded (config, db, etc).

# OPTIONS

--config-dir=*directory*, -c *directory*
Expand Down
33 changes: 33 additions & 0 deletions dsari/info.py
Expand Up @@ -110,6 +110,11 @@ def parse_args():
help='list currently running runs',
)

subparsers.add_parser(
'shell',
help='interactive shell',
)

args = parser.parse_args()
args.parser = parser

Expand Down Expand Up @@ -247,6 +252,34 @@ def main(self):
with open(fn) as f:
for l in f:
print(l, end='')
elif self.args.subcommand == 'shell':
import readline
import code
import datetime

vars = {
'__name__': '__console__',
'__doc__': None,
'concurrency_groups': self.config.concurrency_groups,
'config': self.config,
'datetime': datetime,
'db': self.db,
'dsari': dsari,
'jobs': self.config.jobs,
}
print('Additional variables available:')
for k in sorted([k for k in vars.keys() if not k.startswith('__')]):
v = vars[k]
if type(v) == dict:
r = 'Dictionary (%d items)' % len(v)
elif type(v) == list:
r = 'List (%d items)' % len(v)
else:
r = repr(v)
print(' %s: %s' % (k, r))
print()
shell = code.InteractiveConsole(vars)
shell.interact()


def main():
Expand Down

0 comments on commit 41152d4

Please sign in to comment.