[FIX] rare problem in m2mtags, when the form view is destroyed just after a reload
[odoo/odoo.git] / openerp-server
index d402f35..5501eba 100755 (executable)
@@ -30,7 +30,6 @@ GNU Public Licence.
 (c) 2003-TODAY, Fabien Pinckaers - OpenERP SA
 """
 
-import imp
 import logging
 import os
 import signal
@@ -92,7 +91,7 @@ def setup_pid_file():
 def preload_registry(dbname):
     """ Preload a registry, and start the cron."""
     try:
-        db, registry = openerp.pooler.get_db_and_pool(dbname, update_module=config['init'] or config['update'], pooljobs=False)
+        db, registry = openerp.pooler.get_db_and_pool(dbname, update_module=openerp.tools.config['init'] or openerp.tools.config['update'], pooljobs=False)
 
         # jobs will start to be processed later, when openerp.cron.start_master_thread() is called by openerp.service.start_services()
         registry.schedule_cron_jobs()
@@ -102,16 +101,16 @@ def preload_registry(dbname):
 def run_test_file(dbname, test_file):
     """ Preload a registry, possibly run a test file, and start the cron."""
     try:
+        config = openerp.tools.config
         db, registry = openerp.pooler.get_db_and_pool(dbname, update_module=config['init'] or config['update'], pooljobs=False)
         cr = db.cursor()
         _logger.info('loading test file %s', test_file)
-        openerp.tools.convert_yaml_import(cr, 'base', file(test_file), {}, 'test', True)
+        openerp.tools.convert_yaml_import(cr, 'base', file(test_file), 'test', {}, 'test', True)
         cr.rollback()
         cr.close()
     except Exception:
         _logger.exception('Failed to initialize database `%s` and run test file `%s`.', dbname, test_file)
 
-
 def export_translation():
     config = openerp.tools.config
     dbname = config['db_name']
@@ -165,11 +164,16 @@ def dumpstacks(sig, frame):
     """ Signal handler: dump a stack trace for each existing thread."""
     # code from http://stackoverflow.com/questions/132058/getting-stack-trace-from-a-running-python-application#answer-2569696
     # modified for python 2.5 compatibility
-    thread_map = dict(threading._active, **threading._limbo)
-    id2name = dict([(threadId, thread.getName()) for threadId, thread in thread_map.items()])
+    threads_info = dict([(th.ident, {'name': th.name,
+                                    'uid': getattr(th,'uid','n/a')})
+                                for th in threading.enumerate()])
     code = []
     for threadId, stack in sys._current_frames().items():
-        code.append("\n# Thread: %s(%d)" % (id2name[threadId], threadId))
+        thread_info = threads_info.get(threadId)
+        code.append("\n# Thread: %s (id:%s) (uid:%s)" % \
+                    (thread_info and thread_info['name'] or 'n/a',
+                     threadId,
+                     thread_info and thread_info['uid'] or 'n/a'))
         for filename, lineno, name, line in traceback.extract_stack(stack):
             code.append('File: "%s", line %d, in %s' % (filename, lineno, name))
             if line:
@@ -198,17 +202,23 @@ def quit_on_signals():
     try:
         while quit_signals_received == 0:
             time.sleep(60)
-    except KeyboardInterrupt, e:
+    except KeyboardInterrupt:
         pass
 
+    config = openerp.tools.config
     if config['pidfile']:
         os.unlink(config['pidfile'])
 
     openerp.service.stop_services()
     sys.exit(0)
 
-if __name__ == "__main__":
+def configure_babel_localedata_path():
+    # Workaround: py2exe and babel.
+    if hasattr(sys, 'frozen'):
+        import babel
+        babel.localedata._dirname = os.path.join(os.path.dirname(sys.executable), 'localedata')
 
+def main():
     os.environ["TZ"] = "UTC"
 
     check_root_user()
@@ -220,6 +230,8 @@ if __name__ == "__main__":
 
     config = openerp.tools.config
 
+    configure_babel_localedata_path()
+
     setup_signal_handlers()
 
     if config["test_file"]:
@@ -235,24 +247,13 @@ if __name__ == "__main__":
         sys.exit(0)
 
     if not config["stop_after_init"]:
+        setup_pid_file()
         # Some module register themselves when they are loaded so we need the
         # services to be running before loading any registry.
-        openerp.service.start_services()
-
-    for m in openerp.conf.server_wide_modules:
-        try:
-            __import__('openerp.addons.' + m)
-            # Call any post_load hook.
-            info = openerp.modules.module.load_information_from_description_file(m)
-            if info['post_load']:
-                getattr(sys.modules[m], info['post_load'])()
-        except Exception:
-            msg = ''
-            if m == 'web':
-                msg = """
-The `web` module is provided by the addons found in the `openerp-web` project.
-Maybe you forgot to add those addons in your addons_path configuration."""
-            _logger.exception('Failed to load server-wide module `%s`.%s', m, msg)
+        if config['workers']:
+            openerp.service.start_services_workers()
+        else:
+            openerp.service.start_services()
 
     if config['db_name']:
         for dbname in config['db_name'].split(','):
@@ -261,8 +262,10 @@ Maybe you forgot to add those addons in your addons_path configuration."""
     if config["stop_after_init"]:
         sys.exit(0)
 
-    setup_pid_file()
     _logger.info('OpenERP server is running, waiting for connections...')
     quit_on_signals()
 
+if __name__ == "__main__":
+    main()
+
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: