[IMP] Make wizard work
[odoo/odoo.git] / openerp / tools / config.py
index edceb08..9717792 100644 (file)
@@ -3,6 +3,7 @@
 #
 #    OpenERP, Open Source Management Solution
 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
+#    Copyright (C) 2010-2012 OpenERP s.a. (<http://openerp.com>).
 #
 #    This program is free software: you can redistribute it and/or modify
 #    it under the terms of the GNU Affero General Public License as
@@ -24,10 +25,30 @@ import optparse
 import os
 import sys
 import openerp
+import openerp.conf
 import openerp.loglevels as loglevels
 import logging
 import openerp.release as release
 
+class MyOption (optparse.Option, object):
+    """ optparse Option with two additional attributes.
+
+    The list of command line options (getopt.Option) is used to create the
+    list of the configuration file options. When reading the file, and then
+    reading the command line arguments, we don't want optparse.parse results
+    to override the configuration file values. But if we provide default
+    values to optparse, optparse will return them and we can't know if they
+    were really provided by the user or not. A solution is to not use
+    optparse's default attribute, but use a custom one (that will be copied
+    to create the default values of the configuration file).
+
+    """
+    def __init__(self, *opts, **attrs):
+        self.my_default = attrs.pop('my_default', None)
+        super(MyOption, self).__init__(*opts, **attrs)
+
+#.apidoc title: Server Configuration Loader
+
 def check_ssl():
     try:
         from OpenSSL import SSL
@@ -37,79 +58,37 @@ 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
+        # from optparse's parser.
         self.options = {
-            'email_from':False,
-            'xmlrpc_interface': '',    # this will bind the server to all interfaces
-            'xmlrpc_port': 8069,
-            'netrpc_interface': '',
-            'netrpc_port': 8070,
-            'xmlrpcs_interface': '',    # this will bind the server to all interfaces
-            'xmlrpcs_port': 8071,
-            'db_host': False,
-            'db_port': False,
-            'db_name': False,
-            'db_user': False,
-            'db_password': False,
-            'db_maxconn': 64,
-            'reportgz': False,
-            'netrpc': True,
-            'xmlrpc': True,
-            'xmlrpcs': True,
-            'translate_in': None,
-            'translate_out': None,
-            'overwrite_existing_translations': False,
-            'load_language': None,
-            'language': None,
-            'pg_path': None,
             'admin_passwd': 'admin',
             'csv_internal_sep': ',',
-            'addons_path': None,
-            'root_path': None,
-            'debug_mode': False,
-            'import_partial': "",
-            'pidfile': None,
-            'logfile': None,
-            'logrotate': True,
-            'smtp_server': 'localhost',
-            'smtp_user': False,
-            'smtp_port':25,
-            'smtp_ssl':False,
-            'smtp_password': False,
-            'stop_after_init': False,   # this will stop the server after initialization
-            'syslog' : False,
-            'log_level': logging.INFO,
-            'assert_exit_level': logging.ERROR, # level above which a failed assert will be raised
-            'cache_timeout': 100000,
             'login_message': False,
-            'list_db' : True,
-            'timezone' : False, # to override the default TZ
-            'test_file' : False,
-            'test_report_directory' : False,
-            'test_disable' : False,
-            'test_commit' : False,
-            'static_http_enable': False,
-            'static_http_document_root': None,
-            'static_http_url_prefix': None,
-            'secure_cert_file': 'server.cert',
-            'secure_pkey_file': 'server.pkey',
             'publisher_warranty_url': 'http://services.openerp.com/publisher-warranty/',
-            'osv_memory_count_limit': None, # number of records in each osv_memory virtual table
-            'osv_memory_age_limit': 1, # hours
+            'reportgz': False,
+            'root_path': None,
         }
 
-        self.blacklist_for_save = set(["publisher_warranty_url", "load_language", "root_path"])
+        # Not exposed in the configuration file.
+        self.blacklist_for_save = set(
+            ['publisher_warranty_url', 'load_language', 'root_path',
+            'init', 'save', 'config', 'update', 'stop_after_init'])
+
+        # dictionary mapping option destination (keys in self.options) to MyOptions.
+        self.casts = {}
 
         self.misc = {}
         self.config_file = fname
         self.has_ssl = check_ssl()
 
-        self._LOGLEVELS = dict([(getattr(loglevels, 'LOG_%s' % x), getattr(logging, x))
-                          for x in ('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'TEST', 'DEBUG', 'DEBUG_RPC', 'DEBUG_SQL', 'DEBUG_RPC_ANSWER','NOTSET')])
+        self._LOGLEVELS = dict([(getattr(loglevels, 'LOG_%s' % x), getattr(logging, x)) for x in ('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'TEST', 'DEBUG', 'NOTSET')])
 
         version = "%s %s" % (release.description, release.version)
-        self.parser = parser = optparse.OptionParser(version=version)
+        self.parser = parser = optparse.OptionParser(version=version, option_class=MyOption)
 
         # Server startup config
         group = optparse.OptionGroup(parser, "Common options")
@@ -121,86 +100,134 @@ class configmanager(object):
                           help="update one or more modules (comma-separated list, use \"all\" for all modules). Requires -d.")
         group.add_option("--without-demo", dest="without_demo",
                           help="disable loading demo data for modules to be installed (comma-separated, use \"all\" for all modules). Requires -d and -i. Default is %default",
-                          default=False)
-        group.add_option("-P", "--import-partial", dest="import_partial",
-                        help="Use this for big data importation, if it crashes you will be able to continue at the current state. Provide a filename to store intermediate importation states.", default=False)
+                          my_default=False)
+        group.add_option("-P", "--import-partial", dest="import_partial", my_default='',
+                        help="Use this for big data importation, if it crashes you will be able to continue at the current state. Provide a filename to store intermediate importation states.")
         group.add_option("--pidfile", dest="pidfile", help="file where the server pid will be stored")
+        group.add_option("--addons-path", dest="addons_path",
+                         help="specify additional addons paths (separated by commas).",
+                         action="callback", callback=self._check_addons_path, nargs=1, type="string")
+        group.add_option("--load", dest="server_wide_modules", help="Comma-separated list of server-wide modules default=web")
         parser.add_option_group(group)
 
+        # XML-RPC / HTTP
         group = optparse.OptionGroup(parser, "XML-RPC Configuration")
-        group.add_option("--xmlrpc-interface", dest="xmlrpc_interface", help="specify the TCP IP address for the XML-RPC protocol")
-        group.add_option("--xmlrpc-port", dest="xmlrpc_port", help="specify the TCP port for the XML-RPC protocol", type="int")
-        group.add_option("--no-xmlrpc", dest="xmlrpc", action="store_false", help="disable the XML-RPC protocol")
+        group.add_option("--xmlrpc-interface", dest="xmlrpc_interface", my_default='',
+                         help="Specify the TCP IP address for the XML-RPC protocol. The empty string binds to all interfaces.")
+        group.add_option("--xmlrpc-port", dest="xmlrpc_port", my_default=8069,
+                         help="specify the TCP port for the XML-RPC protocol", type="int")
+        group.add_option("--no-xmlrpc", dest="xmlrpc", action="store_false", my_default=True,
+                         help="disable the XML-RPC protocol")
+        group.add_option("--proxy-mode", dest="proxy_mode", action="store_true", my_default=False,
+                         help="Enable correct behavior when behind a reverse proxy")
         parser.add_option_group(group)
 
+        # XML-RPC / HTTPS
         title = "XML-RPC Secure Configuration"
         if not self.has_ssl:
             title += " (disabled as ssl is unavailable)"
 
         group = optparse.OptionGroup(parser, title)
-        group.add_option("--xmlrpcs-interface", dest="xmlrpcs_interface", help="specify the TCP IP address for the XML-RPC Secure protocol")
-        group.add_option("--xmlrpcs-port", dest="xmlrpcs_port", help="specify the TCP port for the XML-RPC Secure protocol", type="int")
-        group.add_option("--no-xmlrpcs", dest="xmlrpcs", action="store_false", help="disable the XML-RPC Secure protocol")
-        group.add_option("--cert-file", dest="secure_cert_file", help="specify the certificate file for the SSL connection")
-        group.add_option("--pkey-file", dest="secure_pkey_file", help="specify the private key file for the SSL connection")
+        group.add_option("--xmlrpcs-interface", dest="xmlrpcs_interface", my_default='',
+                         help="Specify the TCP IP address for the XML-RPC Secure protocol. The empty string binds to all interfaces.")
+        group.add_option("--xmlrpcs-port", dest="xmlrpcs_port", my_default=8071,
+                         help="specify the TCP port for the XML-RPC Secure protocol", type="int")
+        group.add_option("--no-xmlrpcs", dest="xmlrpcs", action="store_false", my_default=True,
+                         help="disable the XML-RPC Secure protocol")
+        group.add_option("--cert-file", dest="secure_cert_file", my_default='server.cert',
+                         help="specify the certificate file for the SSL connection")
+        group.add_option("--pkey-file", dest="secure_pkey_file", my_default='server.pkey',
+                         help="specify the private key file for the SSL connection")
         parser.add_option_group(group)
 
         # NET-RPC
         group = optparse.OptionGroup(parser, "NET-RPC Configuration")
-        group.add_option("--netrpc-interface", dest="netrpc_interface", help="specify the TCP IP address for the NETRPC protocol")
-        group.add_option("--netrpc-port", dest="netrpc_port", help="specify the TCP port for the NETRPC protocol", type="int")
-        group.add_option("--no-netrpc", dest="netrpc", action="store_false", help="disable the NETRPC protocol")
+        group.add_option("--netrpc-interface", dest="netrpc_interface", my_default='',
+                         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")
+        # 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
+        # TODO move to web addons after MetaOption merge
+        group = optparse.OptionGroup(parser, "Web interface Configuration")
+        group.add_option("--db-filter", dest="dbfilter", default='.*',
+                         help="Filter listed database", metavar="REGEXP")
         parser.add_option_group(group)
 
         # Static HTTP
         group = optparse.OptionGroup(parser, "Static HTTP service")
-        group.add_option("--static-http-enable", dest="static_http_enable", action="store_true", default=False, help="enable static HTTP service for serving plain HTML files")
+        group.add_option("--static-http-enable", dest="static_http_enable", action="store_true", my_default=False, help="enable static HTTP service for serving plain HTML files")
         group.add_option("--static-http-document-root", dest="static_http_document_root", help="specify the directory containing your static HTML files (e.g '/var/www/')")
         group.add_option("--static-http-url-prefix", dest="static_http_url_prefix", help="specify the URL root prefix where you want web browsers to access your static HTML files (e.g '/')")
         parser.add_option_group(group)
 
         # Testing Group
         group = optparse.OptionGroup(parser, "Testing Configuration")
-        group.add_option("--test-file", dest="test_file", help="Launch a YML test file.")
-        group.add_option("--test-report-directory", dest="test_report_directory", help="If set, will save sample of all reports in this directory.")
-        group.add_option("--test-disable", action="store_true", dest="test_disable",
-                         default=False, help="Disable loading test files.")
+        group.add_option("--test-file", dest="test_file", my_default=False,
+                         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-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",
-                         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(),
-                          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
         group = optparse.OptionGroup(parser, "Logging Configuration")
         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",
-                         help="do not rotate the logfile")
-        group.add_option("--syslog", action="store_true", dest="syslog",
-                         default=False, help="Send the log to the syslog server")
-        group.add_option('--log-level', dest='log_level', type='choice', choices=self._LOGLEVELS.keys(),
-                         help='specify the level of the logging. Accepted values: ' + str(self._LOGLEVELS.keys()))
+        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=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.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.
+        levels = ['info', 'debug_rpc', 'warn', 'test', 'critical',
+            'debug_sql', 'error', 'debug', 'debug_rpc_answer', 'notset']
+        group.add_option('--log-level', dest='log_level', type='choice', choices=levels,
+            my_default='info', help='specify the level of the logging. Accepted values: ' + str(levels) + ' (deprecated option).')
+
         parser.add_option_group(group)
 
         # SMTP Group
         group = optparse.OptionGroup(parser, "SMTP Configuration")
-        group.add_option('--email-from', dest='email_from', help='specify the SMTP email address for sending email')
-        group.add_option('--smtp', dest='smtp_server', help='specify the SMTP server for sending email')
-        group.add_option('--smtp-port', dest='smtp_port', help='specify the SMTP port', type="int")
-        group.add_option('--smtp-ssl', dest='smtp_ssl', action='store_true', help='specify the SMTP server support SSL or not')
-        group.add_option('--smtp-user', dest='smtp_user', help='specify the SMTP username for sending email')
-        group.add_option('--smtp-password', dest='smtp_password', help='specify the SMTP password for sending email')
+        group.add_option('--email-from', dest='email_from', my_default=False,
+                         help='specify the SMTP email address for sending email')
+        group.add_option('--smtp', dest='smtp_server', my_default='localhost',
+                         help='specify the SMTP server for sending email')
+        group.add_option('--smtp-port', dest='smtp_port', my_default=25,
+                         help='specify the SMTP port', type="int")
+        group.add_option('--smtp-ssl', dest='smtp_ssl', action='store_true', my_default=False,
+                         help='specify the SMTP server support SSL or not')
+        group.add_option('--smtp-user', dest='smtp_user', my_default=False,
+                         help='specify the SMTP username for sending email')
+        group.add_option('--smtp-password', dest='smtp_password', my_default=False,
+                         help='specify the SMTP password for sending email')
         parser.add_option_group(group)
 
         group = optparse.OptionGroup(parser, "Database related options")
-        group.add_option("-d", "--database", dest="db_name", help="specify the database name")
-        group.add_option("-r", "--db_user", dest="db_user", help="specify the database user name")
-        group.add_option("-w", "--db_password", dest="db_password", help="specify the database password")
+        group.add_option("-d", "--database", dest="db_name", my_default=False,
+                         help="specify the database name")
+        group.add_option("-r", "--db_user", dest="db_user", my_default=False,
+                         help="specify the database user name")
+        group.add_option("-w", "--db_password", dest="db_password", my_default=False,
+                         help="specify the database password")
         group.add_option("--pg_path", dest="pg_path", help="specify the pg executable path")
-        group.add_option("--db_host", dest="db_host", help="specify the database host")
-        group.add_option("--db_port", dest="db_port", help="specify the database port", type="int")
-        group.add_option("--db_maxconn", dest="db_maxconn", type='int',
+        group.add_option("--db_host", dest="db_host", my_default=False,
+                         help="specify the database host")
+        group.add_option("--db_port", dest="db_port", my_default=False,
+                         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="template1",
+                         help="specify a custom database template to create a new database")
         parser.add_option_group(group)
 
         group = optparse.OptionGroup(parser, "Internationalisation options",
@@ -216,42 +243,92 @@ class configmanager(object):
                          help="export all sentences to be translated to a CSV file, a PO file or a TGZ archive and exit")
         group.add_option("--i18n-import", dest="translate_in",
                          help="import a CSV or a PO file with translations and exit. The '-l' option is required.")
-        group.add_option("--i18n-overwrite", dest="overwrite_existing_translations", action="store_true", default=False,
-                         help="overwrites existing translation terms on importing a CSV or a PO file.")
+        group.add_option("--i18n-overwrite", dest="overwrite_existing_translations", action="store_true", my_default=False,
+                         help="overwrites existing translation terms on updating a module or importing a CSV or a PO file.")
         group.add_option("--modules", dest="translate_modules",
                          help="specify modules to export. Use in combination with --i18n-export")
-        group.add_option("--addons-path", dest="addons_path",
-                         help="specify an alternative addons path.",
-                         action="callback", callback=self._check_addons_path, nargs=1, type="string")
         parser.add_option_group(group)
 
         security = optparse.OptionGroup(parser, 'Security-related options')
-        security.add_option('--no-database-list', action="store_false", dest='list_db', help="disable the ability to return the list of databases")
+        security.add_option('--no-database-list', action="store_false", dest='list_db', my_default=True,
+                            help="disable the ability to return the list of databases")
         parser.add_option_group(security)
 
         # Advanced options
         group = optparse.OptionGroup(parser, "Advanced options")
-        group.add_option("--cache-timeout", dest="cache_timeout",
-                          help="set the timeout for the cache system", type="int")
-        group.add_option('--debug', dest='debug_mode', action='store_true', default=False, help='enable debug mode')
-        group.add_option("--stop-after-init", action="store_true", dest="stop_after_init", default=False,
-                          help="stop the server after it initializes")
-        group.add_option("-t", "--timezone", dest="timezone", help="specify reference timezone for the server (e.g. Europe/Brussels")
-        group.add_option("--osv-memory-count-limit", dest="osv_memory_count_limit", default=False,
+        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")
+        group.add_option("-t", "--timezone", dest="timezone", my_default=False,
+                         help="specify reference timezone for the server (e.g. Europe/Brussels")
+        group.add_option("--osv-memory-count-limit", dest="osv_memory_count_limit", my_default=False,
                          help="Force a limit on the maximum number of records kept in the virtual "
                               "osv_memory tables. The default is False, which means no count-based limit.",
                          type="int")
-        group.add_option("--osv-memory-age-limit", dest="osv_memory_age_limit", default=1.0,
+        group.add_option("--osv-memory-age-limit", dest="osv_memory_age_limit", my_default=1.0,
                          help="Force a limit on the maximum age of records kept in the virtual "
                               "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=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)
 
-        self.parse_config()
+        group = optparse.OptionGroup(parser, "Multiprocessing options")
+        # TODO sensible default for the three following limits.
+        group.add_option("--workers", dest="workers", my_default=0,
+                         help="Specify the number of workers, 0 disable prefork mode.",
+                         type="int")
+        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("--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")
+        parser.add_option_group(group)
 
-    def parse_config(self, args=[]):
-        opt, args = self.parser.parse_args()
+        # Copy all optparse options (i.e. MyOption) into self.options.
+        for group in parser.option_groups:
+            for option in group.option_list:
+                if option.dest not in self.options:
+                    self.options[option.dest] = option.my_default
+                    self.casts[option.dest] = option
+
+        self.parse_config(None, False)
+
+    def parse_config(self, args=None, complete=True):
+        """ Parse the configuration file (if any) and the command-line
+        arguments.
+
+        This method initializes openerp.tools.config and openerp.conf (the
+        former should be removed in the furture) with library-wide
+        configuration values.
+
+        This method must be called before proper usage of this library can be
+        made.
+
+        Typical usage of this method:
+
+            openerp.tools.config.parse_config(sys.argv[1:])
+
+        :param complete: this is a hack used in __init__(), leave it to True.
+
+        """
+        if args is None:
+            args = []
+        opt, args = self.parser.parse_args(args)
 
         def die(cond, msg):
             if cond:
@@ -266,8 +343,8 @@ class configmanager(object):
         die(opt.translate_in and (not opt.language or not opt.db_name),
             "the i18n-import option cannot be used without the language (-l) and the database (-d) options")
 
-        die(opt.overwrite_existing_translations and (not opt.translate_in),
-            "the i18n-overwrite option cannot be used without the i18n-import option")
+        die(opt.overwrite_existing_translations and not (opt.translate_in or opt.update),
+            "the i18n-overwrite option cannot be used without the i18n-import option or without the update option")
 
         die(opt.translate_out and (not opt.db_name),
             "the i18n-export option cannot be used without the database (-d) option")
@@ -275,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)
@@ -299,42 +376,48 @@ class configmanager(object):
         if self.options['pidfile'] in ('None', 'False'):
             self.options['pidfile'] = False
 
+        # 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', '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',
                 'xmlrpcs_interface', 'xmlrpcs_port', 'xmlrpcs',
-                'secure_cert_file', 'secure_pkey_file',
-                'static_http_enable', 'static_http_document_root', 'static_http_url_prefix'
+                'static_http_enable', 'static_http_document_root', 'static_http_url_prefix',
+                'secure_cert_file', 'secure_pkey_file', 'dbfilter', 'log_handler', 'log_level'
                 ]
 
         for arg in keys:
-            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',
-            'test_file', 'test_disable', 'test_commit', 'test_report_directory',
-            'osv_memory_count_limit', 'osv_memory_age_limit',
+            'list_db', 'xmlrpcs', 'proxy_mode',
+            '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:
+            # Copy the command-line argument...
             if getattr(opt, arg) is not None:
                 self.options[arg] = getattr(opt, 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'])
-
-        if opt.log_level:
-            self.options['log_level'] = self._LOGLEVELS[opt.log_level]
-        else:
-            self.options['log_level'] = self._LOGLEVELS.get(self.options['log_level']) or int(self.options['log_level'])
+            # ... 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])
 
         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':
@@ -397,6 +480,15 @@ class configmanager(object):
         if opt.save:
             self.save()
 
+        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(','))
+        else:
+            openerp.conf.server_wide_modules = ['web']
+        if complete:
+            openerp.modules.module.initialize_sys_path()
+            openerp.modules.loading.open_openerp_namespace()
+
     def _generate_pgpassfile(self):
         """
         Generate the pgpass file with the parameters from the command line (db_host, db_user,
@@ -435,26 +527,28 @@ class configmanager(object):
             import stat
             os.chmod(filename, stat.S_IRUSR + stat.S_IWUSR)
 
-    def _check_addons_path(self, option, opt, value, parser):
-        res = os.path.abspath(os.path.expanduser(value))
-        if not os.path.exists(res):
-            raise optparse.OptionValueError("option %s: no such directory: %r" % (opt, value))
-
-        contains_addons = False
-        for f in os.listdir(res):
-            modpath = os.path.join(res, f)
-            if os.path.isdir(modpath) and \
-               os.path.exists(os.path.join(modpath, '__init__.py')) and \
-               (os.path.exists(os.path.join(modpath, '__openerp__.py')) or \
-                os.path.exists(os.path.join(modpath, '__terp__.py'))):
-
-                contains_addons = True
-                break
-
-        if not contains_addons:
-            raise optparse.OptionValueError("option %s: The addons-path %r does not seem to a be a valid Addons Directory!" % (opt, value))
+    def _is_addons_path(self, path):
+        for f in os.listdir(path):
+            modpath = os.path.join(path, f)
+            if os.path.isdir(modpath):
+                def hasfile(filename):
+                    return os.path.isfile(os.path.join(modpath, filename))
+                if hasfile('__init__.py') and (hasfile('__openerp__.py') or hasfile('__terp__.py')):
+                    return True
+        return False
 
-        setattr(parser.values, option.dest, res)
+    def _check_addons_path(self, option, opt, value, parser):
+        ad_paths = []
+        for path in value.split(','):
+            path = path.strip()
+            res = os.path.abspath(os.path.expanduser(path))
+            if not os.path.isdir(res):
+                raise optparse.OptionValueError("option %s: no such directory: %r" % (opt, path))
+            if not self._is_addons_path(res):
+                raise optparse.OptionValueError("option %s: The addons-path %r does not seem to a be a valid Addons Directory!" % (opt, path))
+            ad_paths.append(res)
+
+        setattr(parser.values, option.dest, ",".join(ad_paths))
 
     def load(self):
         p = ConfigParser.ConfigParser()
@@ -492,12 +586,13 @@ 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])
 
         for sec in sorted(self.misc.keys()):
+            p.add_section(sec)
             for opt in sorted(self.misc[sec].keys()):
                 p.set(sec,opt,self.misc[sec][opt])
 
@@ -525,9 +620,14 @@ 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]
 
 config = configmanager()
 
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: