|
@ -16,12 +16,21 @@ |
|
|
# |
|
|
# |
|
|
############################################################################## |
|
|
############################################################################## |
|
|
|
|
|
|
|
|
|
|
|
from __future__ import print_function |
|
|
import code |
|
|
import code |
|
|
|
|
|
import os |
|
|
import signal |
|
|
import signal |
|
|
|
|
|
import sys |
|
|
|
|
|
|
|
|
import openerp |
|
|
import openerp |
|
|
|
|
|
from openerp.api import Environment |
|
|
from openerp.cli import Command |
|
|
from openerp.cli import Command |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def raise_keyboard_interrupt(*a): |
|
|
|
|
|
raise KeyboardInterrupt() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Console(code.InteractiveConsole): |
|
|
class Console(code.InteractiveConsole): |
|
|
def __init__(self, locals=None, filename="<console>"): |
|
|
def __init__(self, locals=None, filename="<console>"): |
|
|
code.InteractiveConsole.__init__(self, locals, filename) |
|
|
code.InteractiveConsole.__init__(self, locals, filename) |
|
@ -29,43 +38,50 @@ class Console(code.InteractiveConsole): |
|
|
import readline |
|
|
import readline |
|
|
import rlcompleter |
|
|
import rlcompleter |
|
|
except ImportError: |
|
|
except ImportError: |
|
|
print 'readline or rlcompleter not available, autocomplete disabled.' |
|
|
|
|
|
|
|
|
print('readline or rlcompleter not available,' |
|
|
|
|
|
' autocomplete disabled.') |
|
|
else: |
|
|
else: |
|
|
readline.set_completer(rlcompleter.Completer(locals).complete) |
|
|
readline.set_completer(rlcompleter.Completer(locals).complete) |
|
|
readline.parse_and_bind("tab: complete") |
|
|
readline.parse_and_bind("tab: complete") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Shell(Command): |
|
|
class Shell(Command): |
|
|
"""Start odoo in an interactive shell""" |
|
|
"""Start odoo in an interactive shell""" |
|
|
def init(self, args): |
|
|
def init(self, args): |
|
|
openerp.tools.config.parse_config(args) |
|
|
openerp.tools.config.parse_config(args) |
|
|
openerp.cli.server.report_configuration() |
|
|
openerp.cli.server.report_configuration() |
|
|
openerp.service.server.start(preload=[], stop=True) |
|
|
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 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() |
|
|
|
|
|
|
|
|
def shell(self, dbname): |
|
|
def shell(self, dbname): |
|
|
signal.signal(signal.SIGINT, signal.SIG_DFL) |
|
|
|
|
|
# TODO: Fix ctrl-c that doesnt seem to generate KeyboardInterrupt |
|
|
|
|
|
with openerp.api.Environment.manage(): |
|
|
|
|
|
|
|
|
local_vars = { |
|
|
|
|
|
'openerp': openerp |
|
|
|
|
|
} |
|
|
|
|
|
with Environment.manage(): |
|
|
if dbname: |
|
|
if dbname: |
|
|
registry = openerp.modules.registry.RegistryManager.get(dbname) |
|
|
registry = openerp.modules.registry.RegistryManager.get(dbname) |
|
|
with registry.cursor() as cr: |
|
|
with registry.cursor() as cr: |
|
|
uid = openerp.SUPERUSER_ID |
|
|
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 |
|
|
|
|
|
print 'Connected to %s,' % dbname |
|
|
|
|
|
print ' env: Environement(cr, openerp.SUPERUSER_ID, %s).' % ctx |
|
|
|
|
|
print ' self: %s.' % env.user |
|
|
|
|
|
Console(locals=self.locals).interact() |
|
|
|
|
|
|
|
|
ctx = Environment(cr, uid, {})['res.users'].context_get() |
|
|
|
|
|
env = Environment(cr, uid, ctx) |
|
|
|
|
|
local_vars['env'] = env |
|
|
|
|
|
local_vars['self'] = env.user |
|
|
|
|
|
self.console(local_vars) |
|
|
else: |
|
|
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): |
|
|
def run(self, args): |
|
|
self.init(args) |
|
|
self.init(args) |
|
|
self.shell(openerp.tools.config['db_name']) |
|
|
self.shell(openerp.tools.config['db_name']) |
|
|
return 0 |
|
|
return 0 |
|
|
|
|
|
|