From b0eefa8590c2b65e8b03ae7a75dd46dbf4242e68 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Mon, 14 Sep 2020 15:04:54 +0200 Subject: [PATCH] Lint code --- .gitlab-ci.yml | 13 +++++++++++++ ghostream/__init__.py | 7 +++++-- tox.ini | 26 ++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 .gitlab-ci.yml create mode 100644 tox.ini diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..5c88183 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,13 @@ +stages: + - quality-assurance + +linters: + image: python:3.7 + stage: quality-assurance + before_script: + - pip install tox + script: + - tox -e linters + + # Be nice to new contributors, but please use `tox` before commit + allow_failure: true diff --git a/ghostream/__init__.py b/ghostream/__init__.py index c32fd9b..27a02f7 100644 --- a/ghostream/__init__.py +++ b/ghostream/__init__.py @@ -1,20 +1,23 @@ -from flask import Flask, request, redirect, render_template +from flask import Flask, redirect, render_template, request import ldap app = Flask(__name__) app.logger.setLevel(20) # log info app.config.from_object('ghostream.default_settings') + @app.route('/') def index(): """Welcome page""" return render_template('index.html') + @app.route('/') def viewer(path): """Show stream that match this path""" return render_template('viewer.html', path=path) + @app.route('/app/auth', methods=['POST']) def auth(): """Authentication on stream start""" @@ -38,6 +41,6 @@ def auth(): app.logger.info("%s logged in successfully", name) # Remove "?pass=xxx" from RTMP URL return redirect(f"rtmp://127.0.0.1:1925/app/{name}", code=302) - except: + except Exception: app.logger.warning("%s failed to log in", name) return 'Incorrect credentials', 401 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..8b9084e --- /dev/null +++ b/tox.ini @@ -0,0 +1,26 @@ +[tox] +envlist = + linters +skipsdist = True + +[testenv:linters] +deps = + flake8 + flake8-colors + flake8-import-order + flake8-typing-imports + pep8-naming + pyflakes +commands = + flake8 ghostream + +[flake8] +exclude = + __pycache__, + *.pyc, + *.egg-info, + .cache, + .eggs +import-order-style = google +application-import-names = flake8 +format = ${cyan}%(path)s${reset}:${yellow_bold}%(row)d${reset}:${green_bold}%(col)d${reset}: ${red_bold}%(code)s${reset} %(text)s