From 09c8f3be63d03d25947fe92730db1f2a013e0f84 Mon Sep 17 00:00:00 2001 From: Fluffy-Bean Date: Sat, 11 Mar 2023 23:16:27 +0000 Subject: [PATCH] Add run file --- README.md | 10 ++++---- gallery/__init__.py | 9 ++------ run.py | 56 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 run.py diff --git a/README.md b/README.md index fbd8d4f..a03f00c 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,10 @@ Image view ![screenshot](.github/images/imageview.png) ## Running -Currently only for reference +By default, the app runs on port 5000 with 4 workers, you can pass in arguments to change that, use `-h` or `--help` to see all the options. - poetry install - poetry run python3 -m flask --app gallery --debug run --host 0.0.0.0 - poetry run python3 -m gunicorn -w 4 -b 0.0.0.0:5000 'gallery:create_app()' \ No newline at end of file +Once you clone the repo to your desired location and have installed python `poetry`, install the requirements with `poetry install`. From there you can run the app with Gunicorn using `poetry run python3 run.py`! + +You can also run the app in debug mode using `-d` or `--debug`, but its best to look into the logs file located under `~/.config/onlylegs/only.log` + +Enjoy using OnlyLegs! \ No newline at end of file diff --git a/gallery/__init__.py b/gallery/__init__.py index e8b31b8..10c34b9 100644 --- a/gallery/__init__.py +++ b/gallery/__init__.py @@ -1,11 +1,6 @@ """ - ___ _ _ - / _ \ _ __ | |_ _| | ___ __ _ ___ -| | | | '_ \| | | | | | / _ \/ _` / __| -| |_| | | | | | |_| | |__| __/ (_| \__ \ - \___/|_| |_|_|\__, |_____\___|\__, |___/ - |___/ |___/ -Created by Fluffy Bean - Version 23.03.11 +Onlylegs Gallery +This is the main app file, it loads all the other files and sets up the app """ # Import system modules diff --git a/run.py b/run.py new file mode 100644 index 0000000..e62b4dd --- /dev/null +++ b/run.py @@ -0,0 +1,56 @@ +print(""" + ___ _ _ + / _ \ _ __ | |_ _| | ___ __ _ ___ +| | | | '_ \| | | | | | / _ \/ _` / __| +| |_| | | | | | |_| | |__| __/ (_| \__ \ + \___/|_| |_|_|\__, |_____\___|\__, |___/ + |___/ |___/ +Created by Fluffy Bean - Version 23.03.11 +""") + + +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='0.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', type=bool, default=False, help='Run as Flask app in debug mode') +args = parser.parse_args() + +PORT = args.port +ADDRESS = args.address +WORKERS = args.workers + + +if args.debug: + from gallery import create_app + create_app().run(host=ADDRESS, port=PORT, debug=True) +else: + from gunicorn.app.base import Application + from gunicorn import util + + class OnlyLegs(Application): + def __init__(self, options={}): + self.usage = None + self.callable = None + self.options = options + self.do_load_config() + + def init(self, *args): + cfg = {} + for k, v in self.options.items(): + if k.lower() in self.cfg.settings and v is not None: + cfg[k.lower()] = v + return cfg + + def prog(self): + return 'OnlyLegs' + + def load(self): + return util.import_app('gallery:create_app()') + + OnlyLegs({'bind': f'{ADDRESS}:{PORT}', 'workers': WORKERS}).run() + +# uwu