From a5dad001726ef469e1ec0e4d7bf7d795164a4d91 Mon Sep 17 00:00:00 2001 From: Samus CTO Date: Thu, 25 Dec 2014 23:28:05 +0100 Subject: [PATCH] [IMP] stream code from stdin through Odoo's shell Now I have a machine gun. Ho-ho-ho. --- openerp/cli/shell.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/openerp/cli/shell.py b/openerp/cli/shell.py index 6b251284e6d..3639615a2e8 100644 --- a/openerp/cli/shell.py +++ b/openerp/cli/shell.py @@ -18,6 +18,8 @@ import code import signal +from os import isatty +from sys import stdin import openerp from . import Command @@ -58,10 +60,13 @@ class Shell(Command): env = openerp.api.Environment(cr, uid, ctx) self.locals['env'] = env self.locals['self'] = env.user - print 'Connected to %s,' % dbname - print ' env: Environement(cr, openerp.SUPERUSER_ID, %s).' % ctx - print ' self: %s.' % env.user - Console(locals=self.locals).interact() + 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() else: print 'No evironement set, use `odoo.py shell -d dbname` to get one.' Console(locals=self.locals).interact()