diff --git a/gallery/auth.py b/gallery/auth.py index 0518a60..3e13334 100644 --- a/gallery/auth.py +++ b/gallery/auth.py @@ -104,9 +104,6 @@ def register(): db_session.commit() except exc.IntegrityError: return f'User {username} is already registered!' - except Exception as err: - logging.error('User %s could not be registered: %s', username, err) - return 'Something went wrong!' logging.info('User %s registered', username) return 'gwa gwa' diff --git a/gallery/routes/api.py b/gallery/routes/api.py index a7c9303..2c50364 100644 --- a/gallery/routes/api.py +++ b/gallery/routes/api.py @@ -114,7 +114,7 @@ def delete_image(image_id): # Delete file try: - os.remove(os.path.join(current_app.config['UPLOAD_FOLDER'],img.file_name)) + os.remove(os.path.join(current_app.config['UPLOAD_FOLDER'], img.file_name)) except FileNotFoundError: logging.warning('File not found: %s, already deleted or never existed', img.file_name) diff --git a/gallery/utils/contrast.py b/gallery/utils/contrast.py index 27b5d9b..fb3115c 100644 --- a/gallery/utils/contrast.py +++ b/gallery/utils/contrast.py @@ -3,7 +3,7 @@ Calculate the contrast between two colors """ -def contrast(background, light, dark, threshold = 0.179): +def contrast(background, light, dark, threshold=0.179): """ background: tuple of (r, g, b) values light: color to use if the background is light diff --git a/gallery/utils/generate_image.py b/gallery/utils/generate_image.py index 00a1083..6b5a517 100644 --- a/gallery/utils/generate_image.py +++ b/gallery/utils/generate_image.py @@ -4,7 +4,7 @@ Tools for generating images and thumbnails import os import platformdirs -from PIL import Image, ImageOps #, ImageFilter +from PIL import Image, ImageOps from werkzeug.utils import secure_filename @@ -65,13 +65,13 @@ def generate_thumbnail(file_name, resolution, ext=None): # Save image to cache directory try: image.save(os.path.join(CACHE_PATH, f'{file_name}_{res_x}x{res_y}.{ext}'), - icc_profile=image_icc) + icc_profile=image_icc) except OSError: # This usually happens when saving a JPEG with an ICC profile, # so we convert to RGB and try again image = image.convert('RGB') image.save(os.path.join(CACHE_PATH, f'{file_name}_{res_x}x{res_y}.{ext}'), - icc_profile=image_icc) + icc_profile=image_icc) # No need to keep the image in memory, learned the hard way image.close() diff --git a/run.py b/run.py index e36cb39..2261f0f 100644 --- a/run.py +++ b/run.py @@ -24,19 +24,14 @@ Configuration() if DEBUG: from gallery import create_app - - # If no address is specified, use localhost - if not ADDRESS: - ADDRESS = 'localhost' - create_app().run(host=ADDRESS, port=PORT, debug=True, threaded=True) else: from setup.runner import OnlyLegs # pylint: disable=C0412 - - # If no address is specified, bind the server to all interfaces - if not ADDRESS: - ADDRESS = '0.0.0.0' - + import sys + + # Stop Gunicorn from reading the command line arguments as it causes errors + sys.argv = [sys.argv[0]] + options = { 'bind': f'{ADDRESS}:{PORT}', 'workers': WORKERS, diff --git a/setup/args.py b/setup/args.py index af2f6dc..bfc299f 100644 --- a/setup/args.py +++ b/setup/args.py @@ -2,7 +2,7 @@ Startup arguments for the OnlyLegs gallery -p, --port: Port to run on (default: 5000) - -a, --address: Address to run on (default: For Debug: localhost, For Production: 0.0.0.0) + -a, --address: Address to run on (default: 127.0.0.0) -w, --workers: Number of workers to run (default: 4) -d, --debug: Run as Flask app in debug mode (default: False) @@ -15,7 +15,7 @@ import argparse parser = argparse.ArgumentParser(description='Run the OnlyLegs gallery') parser.add_argument('-p', '--port', type=int, default=5000, help='Port to run on') -parser.add_argument('-a', '--address', type=str, default=None, help='Address to run on') +parser.add_argument('-a', '--address', type=str, default='127.0.0.0', help='Address to run on') parser.add_argument('-w', '--workers', type=int, default=4, help='Number of workers to run') parser.add_argument('-d', '--debug', action='store_true', help='Run as Flask app in debug mode') args = parser.parse_args() diff --git a/setup/runner.py b/setup/runner.py index 45271ca..84c0f9f 100644 --- a/setup/runner.py +++ b/setup/runner.py @@ -9,7 +9,7 @@ class OnlyLegs(Application): """ Gunicorn application """ - def __init__(self, options={}): # pylint: disable=W0102, W0231 # noqa + def __init__(self, options={}): # pylint: disable=W0102, W0231 self.usage = None self.callable = None self.options = options @@ -25,7 +25,8 @@ class OnlyLegs(Application): cfg[setting.lower()] = value return cfg - def prog(self): # pylint: disable=C0116, E0202 # noqa + @staticmethod + def prog(self): # pylint: disable=C0116, E0202 return 'OnlyLegs' def load(self):