Commit 6ae8de89 authored by Fence's avatar Fence 🌈

make flake8 happy

parent ac55b393
[flake8]
ignore = E722
inline-quotes = double
exclude = scripts
......@@ -16,3 +16,8 @@ Then run the serve script:
```bash
pipenv run serve
```
To run the linter:
```bash
pipenv run flake8
```
import json
from flask import Flask
from minor.model import db
from minor.controller import ApiController, MusicController, CoverController
from minor.controller import AuthController
from minor.error_handlers import set_error_handlers
config = {}
with open('config.json') as json_file:
with open("config.json") as json_file:
config = json.load(json_file)
app = Flask(__name__)
app.config['MONGODB_SETTINGS'] = {'db': 'minor'}
app.config['JWT_SEKRIT'] = "sekrit"
app.config["MONGODB_SETTINGS"] = {"db": "minor"}
app.config["JWT_SEKRIT"] = "sekrit"
app.config.update(config)
set_error_handlers(app)
from minor.model import db
db.init_app(app)
ApiController().register(app)
......@@ -28,4 +28,3 @@ MusicController(
CoverController(
config["IMAGE_UPLOAD_DIR"]
).register(app)
......@@ -25,7 +25,7 @@ def add_login(email):
try:
AdminLogin.objects.get(email=email)
click.echo(
"A login for the email \"{}\" does already exist".format(email)
'A login for the email "{}" does already exist'.format(email)
)
return sys.exit(1)
except AdminLogin.DoesNotExist:
......@@ -39,7 +39,7 @@ def add_login(email):
login.set_new_password(password)
login.save()
click.echo("login for email \"{}\" added".format(email))
click.echo('login for email "{}" added'.format(email))
@admin.command("rm")
......@@ -48,7 +48,7 @@ def rm_login(email):
try:
key = AdminLogin.objects.get(email=email)
key.delete()
click.echo("login for\"{}\" deleted".format(email))
click.echo('login for"{}" deleted'.format(email))
except AdminLogin.DoesNotExist:
click.echo("login for \"{}\" does not exist".format(email))
click.echo('login for "{}" does not exist'.format(email))
return sys.exit(1)
......@@ -48,7 +48,7 @@ def add_rsa_key(issuer, file):
# only add if the issuer does not exist already
try:
TrustedRsaKey.objects.get(issuer=issuer)
click.echo("issuer \"{}\" does already have a rsa_key".format(issuer))
click.echo('issuer "{}" does already have a rsa_key'.format(issuer))
return sys.exit(1)
except TrustedRsaKey.DoesNotExist:
key = file.read()
......@@ -63,7 +63,7 @@ def rm_rsa_key(issuer):
try:
key = TrustedRsaKey.objects.get(issuer=issuer)
key.delete()
click.echo("key of issuer \"{}\" deleted".format(issuer))
click.echo('key of issuer "{}" deleted'.format(issuer))
except TrustedRsaKey.DoesNotExist:
click.echo("issuer \"{}\" does not exist".format(issuer))
click.echo('issuer "{}" does not exist'.format(issuer))
return sys.exit(1)
......@@ -2,3 +2,10 @@ from minor.controller.api import ApiController
from minor.controller.music import MusicController
from minor.controller.covers import CoverController
from minor.controller.auth import AuthController
__all__ = [
"ApiController",
"MusicController",
"CoverController",
"AuthController",
]
......@@ -93,10 +93,10 @@ class CoverController(FlaskController):
@auth_required
@route("/", methods=["POST"])
def cover_upload(self, payload=None):
if 'file' in request.files:
if "file" in request.files:
file = request.files["file"]
if file.filename != '':
if file.filename != "":
ext = get_ext(file.filename, img_exts)
if ext is not None:
name = secure_filename(generate_file_name(ext))
......
......@@ -145,7 +145,7 @@ class MusicController(FlaskController):
@auth_required
@route("/songs/<id>/upload", methods=["POST"])
def song_file(self, id, payload=None):
if 'file' in request.files:
if "file" in request.files:
file = request.files["file"]
try:
......@@ -153,7 +153,7 @@ class MusicController(FlaskController):
except Song.DoesNotExist:
return jsonify({"code": 404, "message": "not found"}), 404
if file.filename != '':
if file.filename != "":
ext = get_ext(file.filename)
if ext is not None:
name = secure_filename(str(db_song.id) + "." + ext)
......
......@@ -28,7 +28,7 @@ def get_symetric_jwt_payload(token, secret):
def get_asymetric_jwt_payload(token):
payload = jwt.decode(token, "", verify=False)
payload = jwt.decode(token, "", verify=False)
try:
issuer = TrustedRsaKey.objects.get(issuer=payload["iss"])
......@@ -54,5 +54,5 @@ def issue_token(email, secret):
payload["iat"] = datetime.utcnow()
payload["exp"] = datetime.utcnow() + timedelta(minutes=30)
# TODO maybe add jti?
token = jwt.encode(payload, secret, algorithm='HS256')
token = jwt.encode(payload, secret, algorithm="HS256")
return token.decode("utf-8")
......@@ -5,8 +5,8 @@ song_exts = ["mp3", "ogg", "flac"]
def get_ext(filename, exts=song_exts):
if '.' in filename and filename.rsplit('.', 1)[1].lower() in exts:
return filename.rsplit('.', 1)[1].lower()
if "." in filename and filename.rsplit(".", 1)[1].lower() in exts:
return filename.rsplit(".", 1)[1].lower()
else:
return None
......
number = 0.5
name = "minor"
\ No newline at end of file
name = "minor"
......@@ -6,7 +6,7 @@ from minor import version
setup(
name=version.name,
version=version.number,
description='some cool microservice or what ever this is...',
author='fence',
description="some cool microservice or what ever this is...",
author="fence",
packages=find_packages(),
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment