117 lines
5.3 KiB
Python
Executable File
117 lines
5.3 KiB
Python
Executable File
#!/usr/bin/env python
|
|
import json
|
|
import logging
|
|
import logging.config
|
|
import optparse
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
|
|
import werkzeug.serving
|
|
import werkzeug.contrib.fixers
|
|
|
|
optparser = optparse.OptionParser()
|
|
optparser.add_option("-s", "--session-path", dest="session_storage",
|
|
default=os.path.join(tempfile.gettempdir(), "oe-sessions"),
|
|
help="Directory used for session storage", metavar="DIR")
|
|
optparser.add_option("--server-host", dest="server_host",
|
|
default='127.0.0.1', help="OpenERP server hostname", metavar="HOST")
|
|
optparser.add_option("--server-port", dest="server_port", default=8069,
|
|
help="OpenERP server port", type="int", metavar="NUMBER")
|
|
optparser.add_option("--db-filter", dest="dbfilter", default='.*',
|
|
help="Filter listed databases", metavar="REGEXP")
|
|
optparser.add_option('--addons-path', dest='addons_path', default=[], action='append',
|
|
help="Path to addons directory", metavar="PATH")
|
|
optparser.add_option('--load', dest='server_wide_modules', default=['web'], action='append',
|
|
help="Load an additional module before login (by default only 'web' is loaded)", metavar="MODULE")
|
|
|
|
server_options = optparse.OptionGroup(optparser, "Server configuration")
|
|
server_options.add_option("-p", "--port", dest="socket_port", default=8002,
|
|
help="listening port", type="int", metavar="NUMBER")
|
|
server_options.add_option('--reloader', dest='reloader',
|
|
default=False, action='store_true',
|
|
help="Reload application when python files change")
|
|
server_options.add_option('--no-serve-static', dest='serve_static',
|
|
default=True, action='store_false',
|
|
help="Do not serve static files via this server")
|
|
server_options.add_option('--multi-threaded', dest='threaded',
|
|
default=False, action='store_true',
|
|
help="Spawn one thread per HTTP request")
|
|
server_options.add_option('--proxy-mode', dest='proxy_mode',
|
|
default=False, action='store_true',
|
|
help="Enable correct behavior when behind a reverse proxy")
|
|
optparser.add_option_group(server_options)
|
|
|
|
logging_opts = optparse.OptionGroup(optparser, "Logging")
|
|
logging_opts.add_option("--log-level", dest="log_level", type="choice",
|
|
default='debug', help="Global logging level", metavar="LOG_LEVEL",
|
|
choices=['debug', 'info', 'warning', 'error', 'critical'])
|
|
logging_opts.add_option("--log-config", dest="log_config", default=os.path.join(os.path.dirname(__file__), "logging.json"),
|
|
help="Logging configuration file", metavar="FILE")
|
|
optparser.add_option_group(logging_opts)
|
|
|
|
testing_opts = optparse.OptionGroup(optparser, "Testing")
|
|
testing_opts.add_option('--test-mode', dest='test_mode',
|
|
action='store_true', default=False,
|
|
help="Starts test mode, which provides a few"
|
|
" (utterly unsafe) APIs for testing purposes and"
|
|
" sets up a special connector which always raises"
|
|
" errors on tentative server access. These errors"
|
|
" serialize RPC query information (service,"
|
|
" method, arguments list) in the fault_code"
|
|
" attribute of the error object returned to the"
|
|
" client. This lets javascript code assert the" \
|
|
" XMLRPC consequences of its queries.")
|
|
optparser.add_option_group(testing_opts)
|
|
|
|
if __name__ == "__main__":
|
|
(options, args) = optparser.parse_args(sys.argv[1:])
|
|
|
|
if not options.addons_path:
|
|
path_root = os.path.dirname(os.path.abspath(__file__))
|
|
path_addons = os.path.join(path_root, 'addons')
|
|
if os.path.exists(path_addons):
|
|
options.addons_path.append(path_addons)
|
|
|
|
options.addons_path = [
|
|
path[:-1] if path[-1] in r'\/' else path
|
|
for path in options.addons_path
|
|
if os.path.exists(path)
|
|
]
|
|
|
|
for path_addons in options.addons_path:
|
|
if path_addons not in sys.path:
|
|
sys.path.insert(0, path_addons)
|
|
|
|
try:
|
|
import web.common.http
|
|
except ImportError:
|
|
optparser.error('Error Importing base web module. Check correctness of --addons-path.')
|
|
|
|
options.backend = 'xmlrpc'
|
|
os.environ["TZ"] = "UTC"
|
|
|
|
if options.test_mode:
|
|
import web.test_support
|
|
import web.test_support.controllers
|
|
options.connector = web.test_support.TestConnector()
|
|
logging.getLogger('werkzeug').setLevel(logging.WARNING)
|
|
|
|
if sys.version_info >= (2, 7) and os.path.exists(options.log_config):
|
|
with open(options.log_config) as file:
|
|
dct = json.load(file)
|
|
logging.config.dictConfig(dct)
|
|
logging.getLogger().setLevel(getattr(logging, options.log_level.upper()))
|
|
else:
|
|
logging.basicConfig(level=getattr(logging, options.log_level.upper()))
|
|
|
|
app = web.common.http.Root(options)
|
|
|
|
if options.proxy_mode:
|
|
app = werkzeug.contrib.fixers.ProxyFix(app)
|
|
|
|
werkzeug.serving.run_simple(
|
|
'0.0.0.0', options.socket_port, app,
|
|
use_reloader=options.reloader, threaded=options.threaded)
|
|
|