Bendover for PyLint

This commit is contained in:
Michał Gdula 2023-03-20 17:19:42 +00:00
parent e784ca3011
commit b426a6f6c4
8 changed files with 65 additions and 48 deletions

View file

@ -13,12 +13,13 @@ from flask_caching import Cache
from flask_assets import Environment, Bundle from flask_assets import Environment, Bundle
from flask import Flask, render_template from flask import Flask, render_template
from gallery.utils import theme_manager
# Configuration # Configuration
from dotenv import load_dotenv
import platformdirs import platformdirs
from yaml import FullLoader, load from dotenv import load_dotenv
from yaml import FullLoader, safe_load
# Utils
from gallery.utils import theme_manager
USER_DIR = platformdirs.user_config_dir('onlylegs') USER_DIR = platformdirs.user_config_dir('onlylegs')
@ -38,8 +39,8 @@ def create_app(test_config=None):
print("Loaded environment variables") print("Loaded environment variables")
# Get config file # Get config file
with open(os.path.join(USER_DIR, 'conf.yml'), encoding='utf-8') as f: with open(os.path.join(USER_DIR, 'conf.yml'), encoding='utf-8') as file:
conf = load(f, Loader=FullLoader) conf = safe_load(file, loader=FullLoader)
print("Loaded gallery config") print("Loaded gallery config")
# App configuration # App configuration
@ -66,8 +67,8 @@ def create_app(test_config=None):
theme_manager.CompileTheme('default', app.root_path) theme_manager.CompileTheme('default', app.root_path)
# Bundle JS files # Bundle JS files
js = Bundle('js/*.js', output='gen/packed.js') js_scripts = Bundle('js/*.js', output='gen/packed.js')
assets.register('js_all', js) assets.register('js_all', js_scripts)
# Error handlers # Error handlers
@app.errorhandler(403) @app.errorhandler(403)

View file

@ -4,7 +4,8 @@ OnlyLegs - Database models and functions for SQLAlchemy
import os import os
import platformdirs import platformdirs
from sqlalchemy import create_engine, Column, Integer, String, Boolean, DateTime, ForeignKey, PickleType from sqlalchemy import (
create_engine, Column, Integer, String, Boolean, DateTime, ForeignKey, PickleType)
from sqlalchemy.orm import declarative_base, relationship from sqlalchemy.orm import declarative_base, relationship

View file

@ -279,7 +279,7 @@ def lens_specification(value):
""" """
try: try:
return str(value[0] / value[1]) + 'mm - ' + str(value[2] / value[3]) + 'mm' return str(value[0] / value[1]) + 'mm - ' + str(value[2] / value[3]) + 'mm'
except Exception as err: except Exception:
return None return None

13
run.py
View file

@ -1,3 +1,10 @@
"""
Run script for OnlyLegs
"""
from setup.args import PORT, ADDRESS, WORKERS, DEBUG
from setup.configuration import Configuration
print(""" print("""
___ _ _ ___ _ _
/ _ \ _ __ | |_ _| | ___ __ _ ___ / _ \ _ __ | |_ _| | ___ __ _ ___
@ -9,10 +16,6 @@ Created by Fluffy Bean - Version 23.03.20
""") """)
from setup.args import PORT, ADDRESS, WORKERS, DEBUG
from setup.configuration import Configuration
Configuration() # Run pre-checks Configuration() # Run pre-checks
@ -25,7 +28,7 @@ if DEBUG:
create_app().run(host=ADDRESS, port=PORT, debug=True, threaded=True) create_app().run(host=ADDRESS, port=PORT, debug=True, threaded=True)
else: else:
from setup.runner import OnlyLegs from setup.runner import OnlyLegs # pylint: disable=C0412
# If no address is specified, bind the server to all interfaces # If no address is specified, bind the server to all interfaces
if not ADDRESS: if not ADDRESS:

View file

@ -4,10 +4,10 @@ Runs when the app detects that there is no user directory
""" """
import os import os
import sys import sys
import platformdirs
import logging import logging
import yaml
import re import re
import platformdirs
import yaml
USER_DIR = platformdirs.user_config_dir('onlylegs') USER_DIR = platformdirs.user_config_dir('onlylegs')
@ -145,6 +145,9 @@ class Configuration:
@staticmethod @staticmethod
def logging_config(): def logging_config():
"""
Set the logging config
"""
logs_path = os.path.join(platformdirs.user_config_dir('onlylegs'), 'logs') logs_path = os.path.join(platformdirs.user_config_dir('onlylegs'), 'logs')
if not os.path.isdir(logs_path): if not os.path.isdir(logs_path):

View file

@ -1,22 +1,31 @@
"""
Gunicorn configuration file
"""
from gunicorn.app.base import Application from gunicorn.app.base import Application
from gunicorn import util from gunicorn import util
class OnlyLegs(Application): class OnlyLegs(Application):
def __init__(self, options={}): """
Gunicorn application
"""
def __init__(self, options={}): # pylint: disable=W0102, W0231
self.usage = None self.usage = None
self.callable = None self.callable = None
self.options = options self.options = options
self.do_load_config() self.do_load_config()
def init(self, *args): def init(self, *args):
"""
Initialize the application
"""
cfg = {} cfg = {}
for k, v in self.options.items(): for setting, value in self.options.items():
if k.lower() in self.cfg.settings and v is not None: if setting.lower() in self.cfg.settings and value is not None:
cfg[k.lower()] = v cfg[setting.lower()] = value
return cfg return cfg
def prog(self): def prog(self): # pylint: disable=C0116, E0202
return 'OnlyLegs' return 'OnlyLegs'
def load(self): def load(self):