[IMP] odoo shell agnostic execution mode

Streamed file or interactive console are both available whether or not a
database is specified.
This commit is contained in:
Antony Lesuisse
2014-12-27 00:03:32 +01:00
parent e903e37bb1
commit 18be1d9413
+19 -16
View File
@@ -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)