~openerp-dev/openobject-server/trunk-imp-onchange-behave-darshan

« back to all changes in this revision

Viewing changes to openerp/tools/config.py

  • Committer: Darshan Kalola(OpenERP)
  • Date: 2014-04-09 08:44:52 UTC
  • mfrom: (4936.1.232 openobject-server)
  • Revision ID: dka@tinyerp.com-20140409084452-w1e499j21i3eli9d
[MERGE]sync with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
 
1
#openerp.loggers.handlers. -*- coding: utf-8 -*-
2
2
##############################################################################
3
3
#
4
4
#    OpenERP, Open Source Management Solution
76
76
        }
77
77
 
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'
 
82
        ])
82
83
 
83
84
        # dictionary mapping option destination (keys in self.options) to MyOptions.
84
85
        self.casts = {}
87
88
        self.config_file = fname
88
89
        self.has_ssl = check_ssl()
89
90
 
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')
 
94
        ])
91
95
 
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)
149
153
 
150
154
        # WEB
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)
156
159
 
157
 
        # Static HTTP
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)
163
 
 
164
160
        # Testing 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
187
184
        # quite close.
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).')
 
185
        levels = [
 
186
            'info', 'debug_rpc', 'warn', 'test', 'critical',
 
187
            'debug_sql', 'error', 'debug', 'debug_rpc_answer', 'notset'
 
188
        ]
 
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,))
192
192
 
193
193
        parser.add_option_group(group)
194
194
 
252
252
 
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)
276
277
 
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.",
281
 
                         type="int")
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).",
284
 
                         type="int")
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).",
287
 
                         type="int")
288
 
        group.add_option("--limit-time-cpu", dest="limit_time_cpu", my_default=60,
289
 
                         help="Maximum allowed CPU time per request (default 60).",
290
 
                         type="int")
291
 
        group.add_option("--limit-time-real", dest="limit_time_real", my_default=120,
292
 
                         help="Maximum allowed Real time per request (default 120).",
293
 
                         type="int")
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).",
296
 
                         type="int")
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.",
 
283
                             type="int")
 
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).",
 
286
                             type="int")
 
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).",
 
289
                             type="int")
 
290
            group.add_option("--limit-time-cpu", dest="limit_time_cpu", my_default=60,
 
291
                             help="Maximum allowed CPU time per request (default 60).",
 
292
                             type="int")
 
293
            group.add_option("--limit-time-real", dest="limit_time_real", my_default=120,
 
294
                             help="Maximum allowed Real time per request (default 120).",
 
295
                             type="int")
 
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).",
 
298
                             type="int")
 
299
            parser.add_option_group(group)
298
300
 
299
301
        # Copy all optparse options (i.e. MyOption) into self.options.
300
302
        for group in parser.option_groups:
303
305
                    self.options[option.dest] = option.my_default
304
306
                    self.casts[option.dest] = option
305
307
 
306
 
        self.parse_config(None, False)
 
308
        # generate default config
 
309
        self._parse_config()
307
310
 
308
 
    def parse_config(self, args=None, complete=True):
 
311
    def parse_config(self, args=None):
309
312
        """ Parse the configuration file (if any) and the command-line
310
313
        arguments.
311
314
 
319
322
        Typical usage of this method:
320
323
 
321
324
            openerp.tools.config.parse_config(sys.argv[1:])
322
 
 
323
 
        :param complete: this is a hack used in __init__(), leave it to True.
324
 
 
325
325
        """
 
326
        self._parse_config(args)
 
327
        openerp.netsvc.init_logger()
 
328
        openerp.modules.module.initialize_sys_path()
 
329
 
 
330
    def _parse_config(self, args=None):
326
331
        if args is None:
327
332
            args = []
328
333
        opt, args = self.parser.parse_args(args)
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'
386
390
                ]
387
391
 
388
392
        for arg in keys:
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',
410
 
        ]
411
 
 
 
412
            'data_dir',
 
413
        ]
 
414
 
 
415
        posix_keys = [
 
416
            'auto_reload', 'workers',
 
417
            'limit_memory_hard', 'limit_memory_soft',
 
418
            'limit_time_cpu', 'limit_time_real', 'limit_request',
 
419
        ]
 
420
 
 
421
        if os.name == 'posix':
 
422
            keys += posix_keys
 
423
        else:
 
424
            self.options.update(dict.fromkeys(posix_keys, None))
 
425
 
 
426
        # Copy the command-line arguments...
412
427
        for arg in keys:
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.
483
497
            openerp.conf.server_wide_modules = map(lambda m: m.strip(), opt.server_wide_modules.split(','))
484
498
        else:
485
499
            openerp.conf.server_wide_modules = ['web','web_kanban']
486
 
        if complete:
487
 
            openerp.modules.module.initialize_sys_path()
488
500
 
489
501
    def _generate_pgpassfile(self):
490
502
        """
642
654
            os.chmod(d, 0700)
643
655
        return d
644
656
 
 
657
    def filestore(self, dbname):
 
658
        return os.path.join(self['data_dir'], 'filestore', dbname)
 
659
 
645
660
config = configmanager()
646
661
 
647
662