Make port of web server configurable

This commit is contained in:
Christian Wolf 2023-09-29 16:41:07 +02:00
parent da7a15fc0e
commit 5140244d13
3 changed files with 15 additions and 3 deletions

View File

@ -20,7 +20,11 @@ def main():
if cli.showGUI(): if cli.showGUI():
raise Exception('Not yet implemented') raise Exception('Not yet implemented')
elif cli.startFlaskServer(): elif cli.startFlaskServer():
solo_turnier.flask.startFlask(batchWorker, cli.getLogLevel() > 0) solo_turnier.flask.startFlask(
batchWorker,
debug=cli.getLogLevel() > 0,
port=cli.getPort()
)
else: else:
combinedData = batchWorker.run() combinedData = batchWorker.run()

View File

@ -8,6 +8,7 @@ class Cli:
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
# parser.add_argument('--gui', help='Show the GUI', action='store_true') # parser.add_argument('--gui', help='Show the GUI', action='store_true')
parser.add_argument('--no-flask', action='store_false', dest='flask', help='Disable the internal flask web server') parser.add_argument('--no-flask', action='store_false', dest='flask', help='Disable the internal flask web server')
parser.add_argument('--port', help='The port to listen for incoming requests')
parser.add_argument('html', help='The path from where to look for HTML export files', nargs=1, default=['.']) parser.add_argument('html', help='The path from where to look for HTML export files', nargs=1, default=['.'])
parser.add_argument('-o', '--output', help='Set the output path of the script', nargs=1, default=[None]) parser.add_argument('-o', '--output', help='Set the output path of the script', nargs=1, default=[None])
@ -52,3 +53,6 @@ class Cli:
def showAllParticipants(self): def showAllParticipants(self):
return self.__args.all_participants return self.__args.all_participants
def getPort(self):
return int(self.__args.port)

View File

@ -1,7 +1,11 @@
import flask import flask
import solo_turnier import solo_turnier
def startFlask(batchWorker: solo_turnier.batch.BatchWorker, debug: bool = False): def startFlask(
batchWorker: solo_turnier.batch.BatchWorker,
debug: bool = False,
port: int = 8082
):
app = flask.Flask(__name__) app = flask.Flask(__name__)
@app.route('/') @app.route('/')
@ -10,4 +14,4 @@ def startFlask(batchWorker: solo_turnier.batch.BatchWorker, debug: bool = False)
return flask.render_template('index.html', data=combinedData) return flask.render_template('index.html', data=combinedData)
app.run(host='0.0.0.0', port=8082, debug=debug) app.run(host='0.0.0.0', port=port, debug=debug)