[REF] config: removed duplicated list of options

- the list is still reconstructed from the optparse options.

bzr revid: vmt@openerp.com-20110419134016-og6ye1hjrb0j52cl
This commit is contained in:
Vo Minh Thu 2011-04-19 15:40:16 +02:00
parent 342f2047cf
commit 7410d8e410
1 changed files with 78 additions and 87 deletions

View File

@ -39,67 +39,21 @@ def check_ssl():
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'])
self.misc = {}
self.config_file = fname
@ -122,15 +76,18 @@ class configmanager(object):
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)
group.add_option("-P", "--import-partial", dest="import_partial", 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")
parser.add_option_group(group)
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", 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", default=8069,
help="specify the TCP port for the XML-RPC protocol", type="int")
group.add_option("--no-xmlrpc", dest="xmlrpc", action="store_false", default=True,
help="disable the XML-RPC protocol")
parser.add_option_group(group)
title = "XML-RPC Secure Configuration"
@ -138,18 +95,26 @@ class configmanager(object):
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", 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", 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", default=True,
help="disable the XML-RPC Secure protocol")
group.add_option("--cert-file", dest="secure_cert_file", default='server.cert',
help="specify the certificate file for the SSL connection")
group.add_option("--pkey-file", dest="secure_pkey_file", 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", default='',
help="specify the TCP IP address for the NETRPC protocol")
group.add_option("--netrpc-port", dest="netrpc_port", default=8070,
help="specify the TCP port for the NETRPC protocol", type="int")
group.add_option("--no-netrpc", dest="netrpc", action="store_false", default=True,
help="disable the NETRPC protocol")
parser.add_option_group(group)
# Static HTTP
@ -161,45 +126,60 @@ class configmanager(object):
# 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-file", dest="test_file", default=False,
help="Launch a YML test file.")
group.add_option("--test-report-directory", dest="test_report_directory", 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",
default=False, help="Disable loading test files.")
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(),))
default='error',
help="specify the level at which a failed assertion will stop the server. Accepted values: %s" % (self._LOGLEVELS.keys(),))
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",
group.add_option("--no-logrotate", dest="logrotate", action="store_false", default=True,
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(),
default='info',
help='specify the level of the logging. Accepted values: ' + str(self._LOGLEVELS.keys()))
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', default=False,
help='specify the SMTP email address for sending email')
group.add_option('--smtp', dest='smtp_server', default='localhost',
help='specify the SMTP server for sending email')
group.add_option('--smtp-port', dest='smtp_port', default=25,
help='specify the SMTP port', type="int")
group.add_option('--smtp-ssl', dest='smtp_ssl', action='store_true', default=False,
help='specify the SMTP server support SSL or not')
group.add_option('--smtp-user', dest='smtp_user', default=False,
help='specify the SMTP username for sending email')
group.add_option('--smtp-password', dest='smtp_password', 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", default=False,
help="specify the database name")
group.add_option("-r", "--db_user", dest="db_user", default=False,
help="specify the database user name")
group.add_option("-w", "--db_password", dest="db_password", 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", default=False,
help="specify the database host")
group.add_option("--db_port", dest="db_port", default=False,
help="specify the database port", type="int")
group.add_option("--db_maxconn", dest="db_maxconn", type='int', default=64,
help="specify the the maximum number of physical connections to posgresql")
parser.add_option_group(group)
@ -211,6 +191,7 @@ class configmanager(object):
group.add_option('--load-language', dest="load_language",
help="specifies the languages for the translations you want to be loaded")
group.add_option('-l', "--language", dest="language",
default=None,
help="specify the language of the translation file. Use it with --i18n-export or --i18n-import")
group.add_option("--i18n-export", dest="translate_out",
help="export all sentences to be translated to a CSV file, a PO file or a TGZ archive and exit")
@ -226,17 +207,19 @@ class configmanager(object):
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', 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",
group.add_option("--cache-timeout", dest="cache_timeout", default=100000,
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")
help="stop the server after its initialization")
group.add_option("-t", "--timezone", dest="timezone", 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", 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.",
@ -248,6 +231,14 @@ class configmanager(object):
type="float")
parser.add_option_group(group)
# Copy all optparse options into self.options.
for group in parser.option_groups:
for option in group.option_list:
if option.default == ('NO', 'DEFAULT'):
self.options[option.dest] = None
else:
self.options[option.dest] = option.default
self.parse_config()
def parse_config(self, args=[]):