本文整理汇总了Python中tornado.options.options.parse_config_file函数的典型用法代码示例。如果您正苦于以下问题:Python parse_config_file函数的具体用法?Python parse_config_file怎么用?Python parse_config_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_config_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_config_file
def parse_config_file(conf_file):
conf_file = os.path.join( config.uhphome ,"uhpweb","etc","uhpweb.conf" )
if os.path.exists(conf_file):
options.parse_config_file(conf_file)
gen_log.info("Load config file from %s" %(conf_file))
else:
gen_log.error("Cant load the config file from %s " % (conf_file))
示例2: boreas
def boreas():
from tornado.options import define, options
from boreas import server
define("config", help="Configuration module", type=str)
define("debug", default=True, help="Enable debugging urls", type=bool)
define("api_port", default=8001, help="API port", type=int)
define("api_host", default='127.0.0.1', help="API host", type=str)
define("ws_port", default=8002, help="Websocket port", type=int)
define("ws_host", default='127.0.0.1', help="Websocket host", type=str)
define("token_provider", default='boreas.utils.tokens:no_tokens', help="Function providing initial tokens", type=str)
define("require_auth", default=True, help="Flag indicating if user has to authenticate", type=bool)
options.parse_command_line()
if options.config is None:
# assume boreas.conf in working directory
conf_file = 'boreas.conf'
try:
options.parse_config_file(conf_file)
except IOError:
pass # just use defaults
else:
conf_file = options.config
options.parse_config_file(conf_file)
server.run(options)
示例3: main
def main():
# Defines
define("port", default=8082, help="run on the given port", type=int)
define("log_level", default="INFO", type=str,
help="[NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL]")
define("dbconf", default="sqlite:///vanzilla.db", type=str,
help="sqlalchemy db config string")
define("mail_server", default="localhost", help="server mail", type=str)
define("mail_from", default="", help="sender address for mail error reports", type=str)
define("mail_to", default="", help="recipient addresses for mail error reports", type=str)
define("root_ips", default=[], help="IPs with global access", type=list)
define("promiscuous_load", default=False,
help="load all apps, whether they are enabled or not", type=bool)
options.parse_config_file("vanzilla.conf")
options.parse_command_line()
logging.debug(options.logging)
# Initalising applications
apps = AppsLoader(options)
# Starting tornado server
http_server = tornado.httpserver.HTTPServer(apps)
http_server.listen(options.port)
ioloop = tornado.ioloop.IOLoop.instance()
tornado.autoreload.add_reload_hook(apps.reload_tasks)
tornado.autoreload.start(ioloop)
ioloop.start()
示例4: config_app
def config_app(config, default_options_file, replace_options):
init_env()
app_log.set_logging_level(app_common_const.LOG_LEVEL)
with open(default_options_file, 'r') as f:
default_options = json.load(f)
if default_options:
for option in default_options.get('global_option', {}):
if option:
define(option[0], default=option[1],
help=option[2], type=get_builtin_type(option[3]))
options.parse_config_file(config)
if not check_server_config():
raise EnvironmentError('app server config')
if app_common_const.OPTION_LOG_PATH in options:
app_log.define_file_logging()
options.template_path = str(os.path.join(app_common_const.PROJECT_BASE_FOLDER, options.template_path))
options.static_path = str(os.path.join(app_common_const.PROJECT_BASE_FOLDER, options.static_path))
if replace_options and replace_options['port']:
options.port = int(replace_options['port'])
config_jinja2()
示例5: main
def main():
if os.path.isfile(CONFIG_FILE_PATH):
options.parse_config_file(CONFIG_FILE_PATH, False)
options.parse_command_line()
if options.help:
return
start_worker()
start_web()
示例6: parse_config_file
def parse_config_file(conf_file):
if not conf_file:
conf_file = "/etc/uhp/uhpweb.conf"
conf_file_other = "etc/uhpweb.conf"
if os.path.exists(conf_file):
options.parse_config_file(conf_file)
gen_log.info("Load config file from %s" %(conf_file))
elif os.path.exists(conf_file_other):
options.parse_config_file(conf_file_other)
gen_log.info("Load config file from %s" %(conf_file_other))
else:
gen_log.error("Cant load the config file from %s or %s" % (conf_file, conf_file_other))
示例7: parse_options_config
def parse_options_config(path):
"""从配置文件读取配置参数.
:parameter path: 配置文件目录
"""
options.parse_command_line()
if options.config:
machine = os.getenv("service_host")
if machine:
options.config = "%s.%s" % (options.config, machine)
app_log.info("初始化配置文件:%s" % options.config)
options.parse_config_file(os.path.join(path, 'web_config.conf'))
示例8: main
def main():
parse_command_line()
options.parse_config_file(join(app_root, "conf/%s/server.conf" % options.env))
http_server = tornado.httpserver.HTTPServer(app.HelloWorldApplication(), xheaders=True)
http_server.listen(options.port, "0.0.0.0")
print("Starting Tornado with config {0} on http://localhost:{1}/".format(options.env, options.port))
try:
tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt:
sys.exit(0)
示例9: init_options
def init_options():
# maybe some options will be use before load config file
options.parse_command_line()
options.cfg_file = os.path.abspath(options.cfg_file)
options.parse_config_file(options.cfg_file)
if not options.log_path or not options.port:
options.print_help()
_usage()
options.log_path = os.path.abspath(options.log_path)
if not os.path.exists(options.log_path):
os.makedirs(options.log_path)
示例10: main
def main():
# Load config.
options.parse_config_file(opengb.config.CONFIG_FILE)
# Initialize database.
ODB.initialize(options.db_file)
# Initialize printer queues.
to_printer = multiprocessing.Queue()
from_printer = multiprocessing.Queue()
# Initialize printer using queue callbacks.
printer_callbacks = opengb.printer.QueuedPrinterCallbacks(from_printer)
printer_type = getattr(opengb.printer, options.printer)
printer = printer_type(to_printer, printer_callbacks,
baud_rate=options.baud_rate, port=options.serial_port)
printer.daemon = True
printer.start()
# Initialize web server.
install_dir = resource_filename(Requirement.parse('openGB'), 'opengb')
static_dir = os.path.join(install_dir, 'static')
handlers = [
(r"/ws", WebSocketHandler, {"to_printer": to_printer}),
(r"/api/status", StatusHandler),
(r"/fonts/(.*)", StaticFileHandler, {"path": os.path.join(static_dir, "fonts")}),
(r"/views/(.*)", StaticFileHandler, {"path": os.path.join(static_dir, "views")}),
(r"/images/(.*)", StaticFileHandler, {"path": os.path.join(static_dir, "images")}),
(r"/scripts/(.*)", StaticFileHandler, {"path": os.path.join(static_dir, "scripts")}),
(r"/styles/(.*)", StaticFileHandler, {"path": os.path.join(static_dir, "styles")}),
(r"/(.*)", StaticFileHandler, {"path": os.path.join(static_dir, "index.html")}),
]
app = Application(handlers=handlers, debug=options.debug)
httpServer = tornado.httpserver.HTTPServer(app)
httpServer.listen(options.http_port)
# Create event loop and periodic callbacks
main_loop = tornado.ioloop.IOLoop.instance()
printer_event_processor = tornado.ioloop.PeriodicCallback(
lambda: process_printer_events(from_printer), 10, io_loop=main_loop)
counter_updater = tornado.ioloop.PeriodicCallback(
lambda: update_counters(), 60000)
# TODO: ioloop for watchdog
# TODO: ioloop for camera
# Rock and roll.
printer_event_processor.start()
counter_updater.start()
main_loop.start()
return(os.EX_OK)
示例11: getTornadoUrl
def getTornadoUrl():
import socket
from tornado.options import options
ip = socket.gethostbyname(socket.gethostname())
# Check config file
SERVER_CONFIG = '/etc/domoweb.cfg'
if not os.path.isfile(SERVER_CONFIG):
sys.stderr.write("Error: Can't find the file '%s'\n" % SERVER_CONFIG)
sys.exit(1)
options.define("port", default=40404, help="Launch on the given port", type=int)
options.parse_config_file(SERVER_CONFIG)
return "http://%s:%s/" % (ip, options.port)
示例12: main
def main():
options.parse_command_line()
if not options.config_file is None:
options.parse_config_file(options.config_file)
options.parse_command_line()
if options.client_secret:
settings["cookie_secret"] = options.client_secret
logging.info("Starting Tornado web server on http://localhost:%s" % options.port)
logging.info("--data_path=%s" % options.data_path)
logging.info("--client_host=%s" % options.client_host)
logging.info("--authorized_users=%s" % options.authorized_users)
logging.info("--mongo_storage_uri=%s" % options.mongo_storage_uri)
logging.info("--mongo_storage_db=%s" % options.mongo_storage_db)
logging.info("--mongo_rows_limit=%s" % options.mongo_rows_limit)
if not options.config_file is None:
logging.info("--config_file=%s" % options.config_file)
if not options.github_repo_api_url is None:
logging.info("--github_repo_api_url=%s" % options.github_repo_api_url)
logging.info("--github_project_root=%s" % options.github_project_root)
logging.info("--github_branches_root=%s" % options.github_branches_root)
logging.info("--github_postproc_cmd=%s" % options.github_postproc_cmd)
logging.info("--github_git_cmd=%s" % options.github_git_cmd)
logging.info("--github_branches_json_path=%s" % options.github_branches_json_path)
logging.info("Starting GitHub Web Hook at http://localhost:%s/gitWebHook" % options.port)
MongoDbQueryHandler.datastores = parse_datastore_configuration()
TabixLookupHandler.tabix_file_map = parse_tabix_lookup_configuration()
application = tornado.web.Application([
(r"/", MainHandler),
(r"/auth/signin/google", GoogleOAuth2Handler),
(r"/auth/signin/google/oauth2_callback", GoogleOAuth2Handler),
(r"/auth/signout/google", GoogleSignoutHandler),
(r"/auth/whoami", WhoamiHandler),
(r"/auth/providers", AuthProvidersHandler),
(r"/datastores", MongoDbQueryHandler),
(r"/datastores/(.*)", MongoDbQueryHandler),
(r"/data?(.*)", LocalFileHandler),
(r"/storage/(.*)", MongoDbStorageHandler),
(r"/collections/(.*)", MongoDbCollectionsHandler),
(r"/tabix/(\w+)/(X|Y|M|\d{1,2})/(\d+)", TabixLookupHandler),
(r"/tabix/(\w+)/(X|Y|M|\d{1,2})/(\d+)/(\d+)", TabixLookupHandler),
(r"/gitWebHook?(.*)", GitWebHookHandler)
], **settings)
application.listen(options.port, **server_settings)
tornado.ioloop.IOLoop.instance().start()
示例13: parse_config_options
def parse_config_options():
''' Load up all of the cli and config file options '''
app_root = os.path.abspath(__file__)
os.chdir(os.path.dirname(app_root))
tornado.log.enable_pretty_logging()
try:
options.parse_command_line()
if os.path.isfile(options.config):
logging.debug("Parsing config file `%s`",
os.path.abspath(options.config))
options.parse_config_file(options.config)
options.parse_command_line() # CLI takes precedence
except Error as error:
logging.critical(str(error))
sys.exit()
示例14: load_config
def load_config():
"""
Use default.conf as the definition of options with default values
using tornado.options.define.
Then overrides the values from: local.conf.
This mapping allows to access the application configuration across the
application.
NOTE:
logging in load_config() is not going to work because logging is
configured only when tornado.options.parse_command_line(final=True)
"""
define_options()
local_conf = os.path.join(CONF_DIR, 'local.conf')
if os.path.isfile(local_conf):
options.parse_config_file(local_conf, final=False)
示例15: run
def run(args):
define_global_options()
options.parse_command_line(['server'] + args, final=False)
config_file = path.expanduser(options.config)
if path.isfile(config_file):
options.parse_config_file(config_file, final=False)
_set_x_display(options)
options.run_parse_callbacks()
try:
chmod(options.tmp_dir, 0o755)
except (NotImplementedError, OSError, IOError) as e:
gen_log.warn('Unable to chmod tmp dir: {}'.format(e))
if path.isfile(config_file):
gen_log.info('Config loaded from {}'.format(config_file))
build_app()
IOLoop.instance().start()