Commit edee0991 authored by Marco Mariani's avatar Marco Mariani

Merge branch 'cliff'

parents 81a46850 0353c365
......@@ -47,6 +47,8 @@ setup(name=name,
'cliff',
'iniparse',
'requests',
'ipython',
'bpython',
] + additional_install_requires,
extra_requires={'docs': (
'Sphinx',
......
# -*- coding: utf-8 -*-
import textwrap
from slapos.cli.config import ClientConfigCommand
from slapos.client import init, do_console, ClientConfig
class ShellNotFound(Exception):
pass
class ConsoleCommand(ClientConfigCommand):
"""
open python console with slap library imported
......@@ -32,10 +38,73 @@ class ConsoleCommand(ClientConfigCommand):
ap.add_argument('-c', '--cert_file',
help='SSL Authorisation certificate file')
shell = ap.add_mutually_exclusive_group()
shell.add_argument('-b', '--bpython',
action='store_true',
help='Use BPython shell if available (default)')
shell.add_argument('-i', '--ipython',
action='store_true',
help='Use IPython shell if available')
shell.add_argument('-p', '--python',
action='store_true',
help='Use plain Python shell')
return ap
def take_action(self, args):
configp = self.fetch_config(args)
conf = ClientConfig(args, configp)
local = init(conf)
do_console(local)
if not any([args.python, args.ipython, args.bpython]):
args.bpython = True
if args.ipython:
try:
do_ipython_console(local)
except ShellNotFound:
self.app.log.info('IPython not available - using plain Python shell')
do_console(local)
elif args.bpython:
try:
do_bpython_console(local)
except ShellNotFound:
self.app.log.info('bpython not available - using plain Python shell')
do_console(local)
else:
do_console(local)
console_banner = """\
slapos console allows you interact with slap API. You can play with the global
"slap" object and with the global request() and supply() methods.
examples :
>>> # Request instance
>>> request(kvm, "myuniquekvm")
>>> # Request software installation on owned computer
>>> supply(kvm, "mycomputer")
>>> # Fetch instance informations on already launched instance
>>> request(kvm, "myuniquekvm").getConnectionParameter("url")
"""
def do_bpython_console(local):
try:
from bpython import embed
except ImportError:
raise ShellNotFound
embed(banner=console_banner,
locals_=local)
def do_ipython_console(local):
try:
from IPython import embed
except ImportError:
raise ShellNotFound
embed(banner1=console_banner,
user_ns=local)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment