summaryrefslogtreecommitdiff
path: root/odoo/cli/shell.py
diff options
context:
space:
mode:
Diffstat (limited to 'odoo/cli/shell.py')
-rw-r--r--odoo/cli/shell.py47
1 files changed, 43 insertions, 4 deletions
diff --git a/odoo/cli/shell.py b/odoo/cli/shell.py
index 082ade3f948..cf7b5ffbce2 100644
--- a/odoo/cli/shell.py
+++ b/odoo/cli/shell.py
@@ -2,16 +2,22 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import code
+import logging
import os
import signal
import sys
import odoo
+from odoo.tools import config
from . import Command
+_logger = logging.getLogger(__name__)
+
+
def raise_keyboard_interrupt(*a):
raise KeyboardInterrupt()
+
class Console(code.InteractiveConsole):
def __init__(self, locals=None, filename="<console>"):
code.InteractiveConsole.__init__(self, locals, filename)
@@ -24,10 +30,13 @@ class Console(code.InteractiveConsole):
readline.set_completer(rlcompleter.Completer(locals).complete)
readline.parse_and_bind("tab: complete")
+
class Shell(Command):
"""Start odoo in an interactive shell"""
+ supported_shells = ['ipython', 'ptpython', 'bpython', 'python']
+
def init(self, args):
- odoo.tools.config.parse_config(args)
+ config.parse_config(args)
odoo.cli.server.report_configuration()
odoo.service.server.start(preload=[], stop=True)
signal.signal(signal.SIGINT, raise_keyboard_interrupt)
@@ -40,11 +49,41 @@ class Shell(Command):
print 'No environment set, use `odoo.py shell -d dbname` to get one.'
for i in sorted(local_vars):
print '%s: %s' % (i, local_vars[i])
- Console(locals=local_vars).interact()
+
+ preferred_interface = config.options.get('shell_interface')
+ if preferred_interface:
+ shells_to_try = [preferred_interface, 'python']
+ else:
+ shells_to_try = self.supported_shells
+
+ for shell in shells_to_try:
+ try:
+ return getattr(self, shell)(local_vars)
+ except ImportError:
+ pass
+ except Exception:
+ _logger.warning("Could not start '%s' shell." % shell)
+ _logger.debug("Shell error:", exc_info=True)
+
+ def ipython(self, local_vars):
+ from IPython import start_ipython
+ start_ipython(argv=[], user_ns=local_vars)
+
+ def ptpython(self, local_vars):
+ from ptpython.repl import embed
+ embed({}, local_vars)
+
+ def bpython(self, local_vars):
+ from bpython import embed
+ embed(local_vars)
+
+ def python(self, local_vars):
+ Console(locals=local_vars).interact()
def shell(self, dbname):
local_vars = {
- 'openerp': odoo
+ 'openerp': odoo,
+ 'odoo': odoo,
}
with odoo.api.Environment.manage():
if dbname:
@@ -61,5 +100,5 @@ class Shell(Command):
def run(self, args):
self.init(args)
- self.shell(odoo.tools.config['db_name'])
+ self.shell(config['db_name'])
return 0