summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntony Lesuisse <al@openerp.com>2014-12-27 00:03:32 +0100
committerAntony Lesuisse <al@openerp.com>2014-12-27 00:03:32 +0100
commit18be1d9413fc5cf8a0d3a7c6d3824fea55e032d7 (patch)
tree9a38845fa33d9b6b415046ab4bd5c986f5849457
parente903e37bb13f4541c950aa734090d2d0f3305f71 (diff)
[IMP] odoo shell agnostic execution mode
Streamed file or interactive console are both available whether or not a database is specified.
-rw-r--r--openerp/cli/shell.py35
1 files changed, 19 insertions, 16 deletions
diff --git a/openerp/cli/shell.py b/openerp/cli/shell.py
index 3639615a2e8..f3c397d063f 100644
--- a/openerp/cli/shell.py
+++ b/openerp/cli/shell.py
@@ -17,9 +17,9 @@
##############################################################################
import code
+import os
import signal
-from os import isatty
-from sys import stdin
+import sys
import openerp
from . import Command
@@ -45,12 +45,22 @@ class Shell(Command):
openerp.tools.config.parse_config(args)
openerp.cli.server.report_configuration()
openerp.service.server.start(preload=[], stop=True)
- self.locals = {
- 'openerp': openerp
- }
signal.signal(signal.SIGINT, raise_keyboard_interrupt)
+ def console(self, local_vars):
+ if not os.isatty(sys.stdin.fileno()):
+ exec sys.stdin in local_vars
+ else:
+ if 'env' not in local_vars:
+ print 'No evironement 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()
+
def shell(self, dbname):
+ local_vars = {
+ 'openerp': openerp
+ }
with openerp.api.Environment.manage():
if dbname:
registry = openerp.modules.registry.RegistryManager.get(dbname)
@@ -58,18 +68,11 @@ class Shell(Command):
uid = openerp.SUPERUSER_ID
ctx = openerp.api.Environment(cr, uid, {})['res.users'].context_get()
env = openerp.api.Environment(cr, uid, ctx)
- self.locals['env'] = env
- self.locals['self'] = env.user
- if not isatty(stdin.fileno()):
- exec stdin in self.locals
- else:
- print 'Connected to %s,' % dbname
- print ' env: Environement(cr, openerp.SUPERUSER_ID, %s).' % ctx
- print ' self: %s.' % env.user
- Console(locals=self.locals).interact()
+ local_vars['env'] = env
+ local_vars['self'] = env.user
+ self.console(local_vars)
else:
- print 'No evironement set, use `odoo.py shell -d dbname` to get one.'
- Console(locals=self.locals).interact()
+ self.console(local_vars)
def run(self, args):
self.init(args)