[REF] simplified init_db/load_modules:
- removed unnecessary call to openerp.modules.db.initialize() in openerp/service/web_services.py as the pooler.restart_pool() call just next after is already doing it. - made the try/finally section bigger in openerp/modules/loading.py, to inlcude the first cr.execute. - abstracted the test to check if a database is initialized. - removed unnecessary "if cr:" as the cr is nevertheless used after that. bzr revid: vmt@openerp.com-20110517091822-pjtw6sc1s5assbr5
This commit is contained in:
parent
6c051106ae
commit
a09b91d8fd
|
@ -22,6 +22,15 @@
|
||||||
|
|
||||||
import openerp.modules
|
import openerp.modules
|
||||||
|
|
||||||
|
def is_initialized(cr):
|
||||||
|
""" Check if a database has been initialized for the ORM.
|
||||||
|
|
||||||
|
The database can be initialized with the 'initialize' function below.
|
||||||
|
|
||||||
|
"""
|
||||||
|
cr.execute("SELECT relname FROM pg_class WHERE relkind='r' AND relname='ir_module_module'")
|
||||||
|
return len(cr.fetchall()) > 0
|
||||||
|
|
||||||
def initialize(cr):
|
def initialize(cr):
|
||||||
""" Initialize a database with for the ORM.
|
""" Initialize a database with for the ORM.
|
||||||
|
|
||||||
|
|
|
@ -254,24 +254,23 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
|
||||||
|
|
||||||
open_openerp_namespace()
|
open_openerp_namespace()
|
||||||
|
|
||||||
|
force = []
|
||||||
|
if force_demo:
|
||||||
|
force.append('demo')
|
||||||
|
|
||||||
cr = db.cursor()
|
cr = db.cursor()
|
||||||
if cr:
|
try:
|
||||||
cr.execute("SELECT relname FROM pg_class WHERE relkind='r' AND relname='ir_module_module'")
|
if not openerp.modules.db.is_initialized(cr):
|
||||||
if len(cr.fetchall())==0:
|
|
||||||
logger.notifyChannel("init", netsvc.LOG_INFO, "init db")
|
logger.notifyChannel("init", netsvc.LOG_INFO, "init db")
|
||||||
openerp.modules.db.initialize(cr)
|
openerp.modules.db.initialize(cr)
|
||||||
tools.config["init"]["all"] = 1
|
tools.config["init"]["all"] = 1
|
||||||
tools.config['update']['all'] = 1
|
tools.config['update']['all'] = 1
|
||||||
if not tools.config['without_demo']:
|
if not tools.config['without_demo']:
|
||||||
tools.config["demo"]['all'] = 1
|
tools.config["demo"]['all'] = 1
|
||||||
force = []
|
|
||||||
if force_demo:
|
|
||||||
force.append('demo')
|
|
||||||
|
|
||||||
# This is a brand new pool, just created in pooler.get_db_and_pool()
|
# This is a brand new pool, just created in pooler.get_db_and_pool()
|
||||||
pool = pooler.get_pool(cr.dbname)
|
pool = pooler.get_pool(cr.dbname)
|
||||||
|
|
||||||
try:
|
|
||||||
processed_modules = []
|
processed_modules = []
|
||||||
report = tools.assertion_report()
|
report = tools.assertion_report()
|
||||||
# NOTE: Try to also load the modules that have been marked as uninstallable previously...
|
# NOTE: Try to also load the modules that have been marked as uninstallable previously...
|
||||||
|
|
|
@ -92,12 +92,7 @@ class db(netsvc.ExportService):
|
||||||
cr = None
|
cr = None
|
||||||
try:
|
try:
|
||||||
serv.actions[id]['progress'] = 0
|
serv.actions[id]['progress'] = 0
|
||||||
cr = sql_db.db_connect(db_name).cursor()
|
|
||||||
openerp.modules.db.initialize(cr)
|
|
||||||
tools.config['lang'] = lang
|
tools.config['lang'] = lang
|
||||||
cr.commit()
|
|
||||||
cr.close()
|
|
||||||
cr = None
|
|
||||||
pool = pooler.restart_pool(db_name, demo, serv.actions[id],
|
pool = pooler.restart_pool(db_name, demo, serv.actions[id],
|
||||||
update_module=True)[1]
|
update_module=True)[1]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue