[IMP] Make wizard work
[odoo/odoo.git] / openerp / tools / config.py
index a92ad44..9717792 100644 (file)
@@ -58,6 +58,8 @@ def check_ssl():
     except:
         return False
 
+DEFAULT_LOG_HANDLER = [':INFO']
+
 class configmanager(object):
     def __init__(self, fname=None):
         # Options not exposed on the command line. Command line options will be added
@@ -144,8 +146,9 @@ class configmanager(object):
                          help="specify the TCP IP address for the NETRPC protocol")
         group.add_option("--netrpc-port", dest="netrpc_port", my_default=8070,
                          help="specify the TCP port for the NETRPC protocol", type="int")
-        group.add_option("--no-netrpc", dest="netrpc", action="store_false", my_default=True,
-                         help="disable the NETRPC protocol")
+        # Needed a few day for runbot and saas
+        group.add_option("--no-netrpc", dest="netrpc", action="store_false", my_default=False, help="disable the NETRPC protocol")
+        group.add_option("--netrpc", dest="netrpc", action="store_true", my_default=False, help="enable the NETRPC protocol")
         parser.add_option_group(group)
 
         # WEB
@@ -168,13 +171,10 @@ class configmanager(object):
                          help="Launch a YML test file.")
         group.add_option("--test-report-directory", dest="test_report_directory", my_default=False,
                          help="If set, will save sample of all reports in this directory.")
-        group.add_option("--test-disable", action="store_true", dest="test_disable",
-                         my_default=False, help="Disable loading test files.")
+        group.add_option("--test-enable", action="store_true", dest="test_enable",
+                         my_default=False, help="Enable YAML and unit tests.")
         group.add_option("--test-commit", action="store_true", dest="test_commit",
-                         my_default=False, help="Commit database changes performed by tests.")
-        group.add_option("--assert-exit-level", dest='assert_exit_level', type="choice", choices=self._LOGLEVELS.keys(),
-                         my_default='error',
-                         help="specify the level at which a failed assertion will stop the server. Accepted values: %s" % (self._LOGLEVELS.keys(),))
+                         my_default=False, help="Commit database changes performed by YAML or XML tests.")
         parser.add_option_group(group)
 
         # Logging Group
@@ -182,10 +182,10 @@ class configmanager(object):
         group.add_option("--logfile", dest="logfile", help="file where the server log will be stored")
         group.add_option("--no-logrotate", dest="logrotate", action="store_false", my_default=True, help="do not rotate the logfile")
         group.add_option("--syslog", action="store_true", dest="syslog", my_default=False, help="Send the log to the syslog server")
-        group.add_option('--log-handler', action="append", default=[':INFO'], my_default=[':INFO'], metavar="PREFIX:LEVEL", help='setup a handler at LEVEL for a given PREFIX. An empty PREFIX indicates the root logger. This option can be repeated. Example: "openerp.orm:DEBUG" or "werkzeug:CRITICAL" (default: ":INFO")')
+        group.add_option('--log-handler', action="append", default=DEFAULT_LOG_HANDLER, my_default=DEFAULT_LOG_HANDLER, metavar="PREFIX:LEVEL", help='setup a handler at LEVEL for a given PREFIX. An empty PREFIX indicates the root logger. This option can be repeated. Example: "openerp.orm:DEBUG" or "werkzeug:CRITICAL" (default: ":INFO")')
         group.add_option('--log-request', action="append_const", dest="log_handler", const="openerp.netsvc.rpc.request:DEBUG", help='shortcut for --log-handler=openerp.netsvc.rpc.request:DEBUG')
         group.add_option('--log-response', action="append_const", dest="log_handler", const="openerp.netsvc.rpc.response:DEBUG", help='shortcut for --log-handler=openerp.netsvc.rpc.response:DEBUG')
-        group.add_option('--log-web', action="append_const", dest="log_handler", const="openerp.addons.web.common.http:DEBUG", help='shortcut for --log-handler=openerp.addons.web.common.http:DEBUG')
+        group.add_option('--log-web', action="append_const", dest="log_handler", const="openerp.addons.web.http:DEBUG", help='shortcut for --log-handler=openerp.addons.web.http:DEBUG')
         group.add_option('--log-sql', action="append_const", dest="log_handler", const="openerp.sql_db:DEBUG", help='shortcut for --log-handler=openerp.sql_db:DEBUG')
         # For backward-compatibility, map the old log levels to something
         # quite close.
@@ -226,7 +226,7 @@ class configmanager(object):
                          help="specify the database port", type="int")
         group.add_option("--db_maxconn", dest="db_maxconn", type='int', my_default=64,
                          help="specify the the maximum number of physical connections to posgresql")
-        group.add_option("--db-template", dest="db_template", my_default="template0",
+        group.add_option("--db-template", dest="db_template", my_default="template1",
                          help="specify a custom database template to create a new database")
         parser.add_option_group(group)
 
@@ -256,8 +256,6 @@ class configmanager(object):
 
         # Advanced options
         group = optparse.OptionGroup(parser, "Advanced options")
-        group.add_option("--cache-timeout", dest="cache_timeout", my_default=100000,
-                          help="set the timeout for the cache system", type="int")
         group.add_option('--debug', dest='debug_mode', action='store_true', my_default=False, help='enable debug mode')
         group.add_option("--stop-after-init", action="store_true", dest="stop_after_init", my_default=False,
                           help="stop the server after its initialization")
@@ -272,33 +270,41 @@ class configmanager(object):
                               "osv_memory tables. This is a decimal value expressed in hours, "
                               "and the default is 1 hour.",
                          type="float")
-        group.add_option("--max-cron-threads", dest="max_cron_threads", my_default=4,
-                         help="Maximum number of threads processing concurrently cron jobs.",
+        group.add_option("--max-cron-threads", dest="max_cron_threads", my_default=2,
+                         help="Maximum number of threads processing concurrently cron jobs (default 2).",
                          type="int")
+        group.add_option("--unaccent", dest="unaccent", my_default=False, action="store_true",
+                         help="Use the unaccent function provided by the database when available.")
+        parser.add_option_group(group)
+
+        group = optparse.OptionGroup(parser, "Multiprocessing options")
         # TODO sensible default for the three following limits.
-        group.add_option("--virtual-memory-limit", dest="virtual_memory_limit", my_default=768 * 1024 * 1024,
-                         help="Maximum allowed virtual memory per Gunicorn process. "
-                         "When the limit is reached, any memory allocation will fail.",
+        group.add_option("--workers", dest="workers", my_default=0,
+                         help="Specify the number of workers, 0 disable prefork mode.",
                          type="int")
-        group.add_option("--virtual-memory-reset", dest="virtual_memory_reset", my_default=640 * 1024 * 1024,
-                         help="Maximum allowed virtual memory per Gunicorn process. "
-                         "When the limit is reached, the worker will be reset after "
-                         "the current request.",
+        group.add_option("--limit-memory-soft", dest="limit_memory_soft", my_default=640 * 1024 * 1024,
+                         help="Maximum allowed virtual memory per worker, when reached the worker be reset after the current request (default 640M).",
                          type="int")
-        group.add_option("--cpu-time-limit", dest="cpu_time_limit", my_default=60,
-                         help="Maximum allowed CPU time per Gunicorn process. "
-                         "When the limit is reached, an exception is raised.",
+        group.add_option("--limit-memory-hard", dest="limit_memory_hard", my_default=768 * 1024 * 1024,
+                         help="Maximum allowed virtual memory per worker, when reached, any memory allocation will fail (default 768M).",
+                         type="int")
+        group.add_option("--limit-time-cpu", dest="limit_time_cpu", my_default=60,
+                         help="Maximum allowed CPU time per request (default 60).",
+                         type="int")
+        group.add_option("--limit-time-real", dest="limit_time_real", my_default=120,
+                         help="Maximum allowed Real time per request (default 120).",
+                         type="int")
+        group.add_option("--limit-request", dest="limit_request", my_default=8192,
+                         help="Maximum number of request to be processed per worker (default 8192).",
                          type="int")
-        group.add_option("--unaccent", dest="unaccent", my_default=False, action="store_true",
-                         help="Use the unaccent function provided by the database when available.")
-
         parser.add_option_group(group)
 
         # Copy all optparse options (i.e. MyOption) into self.options.
         for group in parser.option_groups:
             for option in group.option_list:
-                self.options[option.dest] = option.my_default
-                self.casts[option.dest] = option
+                if option.dest not in self.options:
+                    self.options[option.dest] = option.my_default
+                    self.casts[option.dest] = option
 
         self.parse_config(None, False)
 
@@ -346,7 +352,7 @@ class configmanager(object):
         # Check if the config file exists (-c used, but not -s)
         die(not opt.save and opt.config and not os.path.exists(opt.config),
             "The config file '%s' selected with -c/--config doesn't exist, "\
-            "use -s/--save if you want to generate it"%(opt.config))
+            "use -s/--save if you want to generate it"% opt.config)
 
         # place/search the config file on Win32 near the server installation
         # (../etc from the server)
@@ -372,7 +378,7 @@ class configmanager(object):
 
         # if defined dont take the configfile value even if the defined value is None
         keys = ['xmlrpc_interface', 'xmlrpc_port', 'db_name', 'db_user', 'db_password', 'db_host',
-                'db_port', 'db_template', 'logfile', 'pidfile', 'smtp_port', 'cache_timeout',
+                'db_port', 'db_template', 'logfile', 'pidfile', 'smtp_port',
                 'email_from', 'smtp_server', 'smtp_user', 'smtp_password',
                 'netrpc_interface', 'netrpc_port', 'db_maxconn', 'import_partial', 'addons_path',
                 'netrpc', 'xmlrpc', 'syslog', 'without_demo', 'timezone',
@@ -382,22 +388,27 @@ class configmanager(object):
                 ]
 
         for arg in keys:
-            # Copy the command-line argument...
-            if getattr(opt, arg):
+            # Copy the command-line argument (except the special case for log_handler, due to
+            # action=append requiring a real default, so we cannot use the my_default workaround)
+            if getattr(opt, arg) and getattr(opt, arg) != DEFAULT_LOG_HANDLER:
                 self.options[arg] = getattr(opt, arg)
             # ... or keep, but cast, the config file value.
             elif isinstance(self.options[arg], basestring) and self.casts[arg].type in optparse.Option.TYPE_CHECKER:
                 self.options[arg] = optparse.Option.TYPE_CHECKER[self.casts[arg].type](self.casts[arg], arg, self.options[arg])
 
+
+        if isinstance(self.options['log_handler'], basestring):
+            self.options['log_handler'] = self.options['log_handler'].split(',')
+
         # if defined but None take the configfile value
         keys = [
             'language', 'translate_out', 'translate_in', 'overwrite_existing_translations',
             'debug_mode', 'smtp_ssl', 'load_language',
             'stop_after_init', 'logrotate', 'without_demo', 'netrpc', 'xmlrpc', 'syslog',
             'list_db', 'xmlrpcs', 'proxy_mode',
-            'test_file', 'test_disable', 'test_commit', 'test_report_directory',
-            'osv_memory_count_limit', 'osv_memory_age_limit', 'max_cron_threads',
-            'virtual_memory_limit', 'virtual_memory_reset', 'cpu_time_limit', 'unaccent',
+            'test_file', 'test_enable', 'test_commit', 'test_report_directory',
+            'osv_memory_count_limit', 'osv_memory_age_limit', 'max_cron_threads', 'unaccent',
+            'workers', 'limit_memory_hard', 'limit_memory_soft', 'limit_time_cpu', 'limit_time_real', 'limit_request'
         ]
 
         for arg in keys:
@@ -408,11 +419,6 @@ class configmanager(object):
             elif isinstance(self.options[arg], basestring) and self.casts[arg].type in optparse.Option.TYPE_CHECKER:
                 self.options[arg] = optparse.Option.TYPE_CHECKER[self.casts[arg].type](self.casts[arg], arg, self.options[arg])
 
-        if opt.assert_exit_level:
-            self.options['assert_exit_level'] = self._LOGLEVELS[opt.assert_exit_level]
-        else:
-            self.options['assert_exit_level'] = self._LOGLEVELS.get(self.options['assert_exit_level']) or int(self.options['assert_exit_level'])
-
         self.options['root_path'] = os.path.abspath(os.path.expanduser(os.path.expandvars(os.path.dirname(openerp.__file__))))
         if not self.options['addons_path'] or self.options['addons_path']=='None':
             self.options['addons_path'] = os.path.join(self.options['root_path'], 'addons')
@@ -474,8 +480,6 @@ class configmanager(object):
         if opt.save:
             self.save()
 
-        openerp.conf.max_cron_threads = self.options['max_cron_threads']
-
         openerp.conf.addons_paths = self.options['addons_path'].split(',')
         if opt.server_wide_modules:
             openerp.conf.server_wide_modules = map(lambda m: m.strip(), opt.server_wide_modules.split(','))
@@ -582,7 +586,7 @@ class configmanager(object):
                 continue
             if opt in self.blacklist_for_save:
                 continue
-            if opt in ('log_level', 'assert_exit_level'):
+            if opt in ('log_level',):
                 p.set('options', opt, loglevelnames.get(self.options[opt], self.options[opt]))
             else:
                 p.set('options', opt, self.options[opt])
@@ -616,6 +620,9 @@ class configmanager(object):
 
     def __setitem__(self, key, value):
         self.options[key] = value
+        if key in self.options and isinstance(self.options[key], basestring) and \
+                key in self.casts and self.casts[key].type in optparse.Option.TYPE_CHECKER:
+            self.options[key] = optparse.Option.TYPE_CHECKER[self.casts[key].type](self.casts[key], key, self.options[key])
 
     def __getitem__(self, key):
         return self.options[key]