[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:
Vo Minh Thu 2011-05-17 11:18:22 +02:00
parent 6c051106ae
commit a09b91d8fd
3 changed files with 17 additions and 14 deletions

View File

@ -22,6 +22,15 @@
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):
""" Initialize a database with for the ORM.

View File

@ -254,24 +254,23 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
open_openerp_namespace()
force = []
if force_demo:
force.append('demo')
cr = db.cursor()
if cr:
cr.execute("SELECT relname FROM pg_class WHERE relkind='r' AND relname='ir_module_module'")
if len(cr.fetchall())==0:
try:
if not openerp.modules.db.is_initialized(cr):
logger.notifyChannel("init", netsvc.LOG_INFO, "init db")
openerp.modules.db.initialize(cr)
tools.config["init"]["all"] = 1
tools.config['update']['all'] = 1
if not tools.config['without_demo']:
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()
pool = pooler.get_pool(cr.dbname)
# This is a brand new pool, just created in pooler.get_db_and_pool()
pool = pooler.get_pool(cr.dbname)
try:
processed_modules = []
report = tools.assertion_report()
# NOTE: Try to also load the modules that have been marked as uninstallable previously...

View File

@ -92,12 +92,7 @@ class db(netsvc.ExportService):
cr = None
try:
serv.actions[id]['progress'] = 0
cr = sql_db.db_connect(db_name).cursor()
openerp.modules.db.initialize(cr)
tools.config['lang'] = lang
cr.commit()
cr.close()
cr = None
pool = pooler.restart_pool(db_name, demo, serv.actions[id],
update_module=True)[1]