43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
#!/usr/bin/env python
|
|
import os
|
|
import sys
|
|
from logging.config import dictConfig
|
|
from importlib import import_module
|
|
|
|
import click
|
|
import tornado.ioloop
|
|
import tornado.web
|
|
#from raven.contrib.tornado import AsyncSentryClient
|
|
|
|
|
|
def make_app(debug=None):
|
|
from project_src.url import urls
|
|
assert isinstance(urls, (list, tuple)), 'urls must be list or tuple'
|
|
return tornado.web.Application(urls, debug=debug)
|
|
|
|
|
|
def init_log():
|
|
dictConfig(tornado.settings.LOGGING)
|
|
|
|
|
|
@click.command()
|
|
@click.option('--port', default=9090)
|
|
@click.option('--profile', default='develop')
|
|
def serve(port, profile):
|
|
settings = import_module(f'project_src.settings.{profile}')
|
|
tornado.settings = settings
|
|
init_log()
|
|
|
|
app = make_app(settings.DEBUG)
|
|
app.listen(port)
|
|
# app.sentry_client = AsyncSentryClient(
|
|
# '<sentry>'
|
|
# )
|
|
sys.stdout.write(f"Start server at:http://0.0.0.0:{port} \nProfile: {profile}\n")
|
|
tornado.ioloop.IOLoop.current().start()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
current_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
sys.path.insert(0, current_path)
|
|
serve() |