78
78
# Not exposed in the configuration file.
79
self.blacklist_for_save = set(
80
['publisher_warranty_url', 'load_language', 'root_path',
81
'init', 'save', 'config', 'update', 'stop_after_init'])
79
self.blacklist_for_save = set([
80
'publisher_warranty_url', 'load_language', 'root_path',
81
'init', 'save', 'config', 'update', 'stop_after_init'
83
84
# dictionary mapping option destination (keys in self.options) to MyOptions.
87
88
self.config_file = fname
88
89
self.has_ssl = check_ssl()
90
self._LOGLEVELS = dict([(getattr(loglevels, 'LOG_%s' % x), getattr(logging, x)) for x in ('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET')])
91
self._LOGLEVELS = dict([
92
(getattr(loglevels, 'LOG_%s' % x), getattr(logging, x))
93
for x in ('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET')
92
96
version = "%s %s" % (release.description, release.version)
93
97
self.parser = parser = optparse.OptionParser(version=version, option_class=MyOption)
148
152
parser.add_option_group(group)
151
# TODO move to web addons after MetaOption merge
152
155
group = optparse.OptionGroup(parser, "Web interface Configuration")
153
156
group.add_option("--db-filter", dest="dbfilter", default='.*',
154
157
help="Filter listed database", metavar="REGEXP")
155
158
parser.add_option_group(group)
158
group = optparse.OptionGroup(parser, "Static HTTP service")
159
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")
160
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/')")
161
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 '/')")
162
parser.add_option_group(group)
165
161
group = optparse.OptionGroup(parser, "Testing Configuration")
166
162
group.add_option("--test-file", dest="test_file", my_default=False,
179
175
group.add_option("--logrotate", dest="logrotate", action="store_true", my_default=False, help="enable logfile rotation")
180
176
group.add_option("--syslog", action="store_true", dest="syslog", my_default=False, help="Send the log to the syslog server")
181
177
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")')
182
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')
183
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')
184
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')
178
group.add_option('--log-request', action="append_const", dest="log_handler", const="openerp.http.rpc.request:DEBUG", help='shortcut for --log-handler=openerp.http.rpc.request:DEBUG')
179
group.add_option('--log-response', action="append_const", dest="log_handler", const="openerp.http.rpc.response:DEBUG", help='shortcut for --log-handler=openerp.http.rpc.response:DEBUG')
180
group.add_option('--log-web', action="append_const", dest="log_handler", const="openerp.http:DEBUG", help='shortcut for --log-handler=openerp.http:DEBUG')
185
181
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')
182
group.add_option('--log-db', dest='log_db', help="Logging database", my_default=False)
186
183
# For backward-compatibility, map the old log levels to something
188
levels = ['info', 'debug_rpc', 'warn', 'test', 'critical',
189
'debug_sql', 'error', 'debug', 'debug_rpc_answer', 'notset']
190
group.add_option('--log-level', dest='log_level', type='choice', choices=levels,
191
my_default='info', help='specify the level of the logging. Accepted values: ' + str(levels) + ' (deprecated option).')
186
'info', 'debug_rpc', 'warn', 'test', 'critical',
187
'debug_sql', 'error', 'debug', 'debug_rpc_answer', 'notset'
189
group.add_option('--log-level', dest='log_level', type='choice',
190
choices=levels, my_default='info',
191
help='specify the level of the logging. Accepted values: %s (deprecated option).' % (levels,))
193
193
parser.add_option_group(group)
253
253
# Advanced options
254
254
group = optparse.OptionGroup(parser, "Advanced options")
255
group.add_option('--auto-reload', dest='auto_reload', action='store_true', my_default=False, help='enable auto reload')
255
if os.name == 'posix':
256
group.add_option('--auto-reload', dest='auto_reload', action='store_true', my_default=False, help='enable auto reload')
256
257
group.add_option('--debug', dest='debug_mode', action='store_true', my_default=False, help='enable debug mode')
257
258
group.add_option("--stop-after-init", action="store_true", dest="stop_after_init", my_default=False,
258
259
help="stop the server after its initialization")
274
275
help="Use the unaccent function provided by the database when available.")
275
276
parser.add_option_group(group)
277
group = optparse.OptionGroup(parser, "Multiprocessing options")
278
# TODO sensible default for the three following limits.
279
group.add_option("--workers", dest="workers", my_default=0,
280
help="Specify the number of workers, 0 disable prefork mode.",
282
group.add_option("--limit-memory-soft", dest="limit_memory_soft", my_default=2048 * 1024 * 1024,
283
help="Maximum allowed virtual memory per worker, when reached the worker be reset after the current request (default 671088640 aka 640MB).",
285
group.add_option("--limit-memory-hard", dest="limit_memory_hard", my_default=2560 * 1024 * 1024,
286
help="Maximum allowed virtual memory per worker, when reached, any memory allocation will fail (default 805306368 aka 768MB).",
288
group.add_option("--limit-time-cpu", dest="limit_time_cpu", my_default=60,
289
help="Maximum allowed CPU time per request (default 60).",
291
group.add_option("--limit-time-real", dest="limit_time_real", my_default=120,
292
help="Maximum allowed Real time per request (default 120).",
294
group.add_option("--limit-request", dest="limit_request", my_default=8192,
295
help="Maximum number of request to be processed per worker (default 8192).",
297
parser.add_option_group(group)
278
if os.name == 'posix':
279
group = optparse.OptionGroup(parser, "Multiprocessing options")
280
# TODO sensible default for the three following limits.
281
group.add_option("--workers", dest="workers", my_default=0,
282
help="Specify the number of workers, 0 disable prefork mode.",
284
group.add_option("--limit-memory-soft", dest="limit_memory_soft", my_default=2048 * 1024 * 1024,
285
help="Maximum allowed virtual memory per worker, when reached the worker be reset after the current request (default 671088640 aka 640MB).",
287
group.add_option("--limit-memory-hard", dest="limit_memory_hard", my_default=2560 * 1024 * 1024,
288
help="Maximum allowed virtual memory per worker, when reached, any memory allocation will fail (default 805306368 aka 768MB).",
290
group.add_option("--limit-time-cpu", dest="limit_time_cpu", my_default=60,
291
help="Maximum allowed CPU time per request (default 60).",
293
group.add_option("--limit-time-real", dest="limit_time_real", my_default=120,
294
help="Maximum allowed Real time per request (default 120).",
296
group.add_option("--limit-request", dest="limit_request", my_default=8192,
297
help="Maximum number of request to be processed per worker (default 8192).",
299
parser.add_option_group(group)
299
301
# Copy all optparse options (i.e. MyOption) into self.options.
300
302
for group in parser.option_groups:
381
386
'db_maxconn', 'import_partial', 'addons_path',
382
387
'xmlrpc', 'syslog', 'without_demo', 'timezone',
383
388
'xmlrpcs_interface', 'xmlrpcs_port', 'xmlrpcs',
384
'static_http_enable', 'static_http_document_root', 'static_http_url_prefix',
385
'secure_cert_file', 'secure_pkey_file', 'dbfilter', 'log_handler', 'log_level'
389
'secure_cert_file', 'secure_pkey_file', 'dbfilter', 'log_handler', 'log_level', 'log_db'
405
409
'list_db', 'xmlrpcs', 'proxy_mode',
406
410
'test_file', 'test_enable', 'test_commit', 'test_report_directory',
407
411
'osv_memory_count_limit', 'osv_memory_age_limit', 'max_cron_threads', 'unaccent',
408
'workers', 'limit_memory_hard', 'limit_memory_soft', 'limit_time_cpu', 'limit_time_real', 'limit_request',
409
'auto_reload', 'data_dir',
416
'auto_reload', 'workers',
417
'limit_memory_hard', 'limit_memory_soft',
418
'limit_time_cpu', 'limit_time_real', 'limit_request',
421
if os.name == 'posix':
424
self.options.update(dict.fromkeys(posix_keys, None))
426
# Copy the command-line arguments...
413
# Copy the command-line argument...
414
428
if getattr(opt, arg) is not None:
415
429
self.options[arg] = getattr(opt, arg)
416
430
# ... or keep, but cast, the config file value.