[REF] simplified init_db/load_modules:
authorVo Minh Thu <vmt@openerp.com>
Tue, 17 May 2011 09:18:22 +0000 (11:18 +0200)
committerVo Minh Thu <vmt@openerp.com>
Tue, 17 May 2011 09:18:22 +0000 (11:18 +0200)
- 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

openerp/modules/db.py
openerp/modules/loading.py
openerp/service/web_services.py

index 261b39f..25ce728 100644 (file)
 
 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.
 
index c370166..17ae2dc 100644 (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...
index 8806e1b..4f6ab75 100644 (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]