Enhanced run_flaschengeist

This commit is contained in:
Ferdinand Thiessen 2020-10-15 18:11:27 +02:00
parent f03314efac
commit 60c2637784
1 changed files with 31 additions and 16 deletions

View File

@ -1,23 +1,38 @@
#!/usr/bin/python3 #!/usr/bin/python3
from flaschengeist.app import create_app, install_all import sys
import bjoern
import argparse import argparse
import bjoern
def install(arguments):
from flaschengeist.app import create_app, install_all
app = create_app()
with app.app_context():
install_all()
def run(arguments):
from flaschengeist.app import create_app
app = create_app()
with app.app_context():
if arguments.debug:
app.run(arguments.host, arguments.port, debug=True)
else:
bjoern.run(app, arguments.host, arguments.port, reuse_port=True)
if __name__ == '__main__': if __name__ == '__main__':
# create the top-level parser
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--host", help="set hostname to listen on", default="127.0.0.1") subparsers = parser.add_subparsers(help='sub-command help', dest="sub_command")
parser.add_argument("--port", help="set port to listen on", type=int, default=5000) subparsers.required = True
parser.add_argument("--debug", help="run in debug mode", action="store_true") parser_run = subparsers.add_parser('run', help='run flaschengeist')
parser.add_argument("--install", help="installer", action="store_true") parser_run.set_defaults(func=run)
args = parser.parse_args() parser_run.add_argument("--host", help="set hostname to listen on", default="127.0.0.1")
parser_run.add_argument("--port", help="set port to listen on", type=int, default=5000)
parser_run.add_argument("--debug", help="run in debug mode", action="store_true")
parser_install = subparsers.add_parser('install', help='run database setup for flaschengeist and all installed plugins')
parser_install.set_defaults(func=install)
app = create_app() args = parser.parse_args()
if args.install: args.func(args)
with app.app_context():
install_all()
else:
if args.debug:
app.run(args.host, args.port, debug=True)
else:
bjoern.run(app, args.host, args.port, reuse_port=True)