console: support new `slapos console script.py` invocation
To execute a slapconsole script, we could only do: `slapos console < script.py` but this does not stop in case of error or `echo 'execfile("script.py")' | slapos console` but this is too complicated. Extend this API so that we can simply use `slapos console script.py` inspired by `python script.py`
Showing
... | ... | @@ -79,6 +79,9 @@ class ConsoleCommand(ClientConfigCommand): |
action='store_true', | ||
help='Use plain Python shell') | ||
shell.add_argument('script_file', nargs='?', | ||
help='Script to run') | ||
return ap | ||
def take_action(self, args): | ||
... | ... | @@ -86,6 +89,9 @@ class ConsoleCommand(ClientConfigCommand): |
conf = ClientConfig(args, configp) | ||
local = init(conf, self.app.log) | ||
if args.script_file: | ||
return execfile(args.script_file, globals(), local) | ||
|
||
if not any([args.python, args.ipython, args.bpython]): | ||
args.ipython = True | ||
... | ... |