From 79db45f7a297abce4d9ced107f0ab9a3a79be7bb Mon Sep 17 00:00:00 2001 From: Fluffy-Bean Date: Sun, 12 Mar 2023 15:08:49 +0000 Subject: [PATCH] Move Gunicorn run file to setup --- run.py | 27 +++------------------------ setup/args.py | 3 +-- setup/configuration.py | 10 ++++------ setup/runner.py | 22 ++++++++++++++++++++++ 4 files changed, 30 insertions(+), 32 deletions(-) create mode 100644 setup/runner.py diff --git a/run.py b/run.py index 51a3187..3e55dfb 100644 --- a/run.py +++ b/run.py @@ -13,36 +13,15 @@ from setup.args import PORT, ADDRESS, WORKERS, DEBUG from setup.configuration import Configuration -# Run prechecks -Configuration() +Configuration() # Run prechecks if DEBUG: from gallery import create_app + create_app().run(host=ADDRESS, port=PORT, debug=True, threaded=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()') + from setup.runner import OnlyLegs options = { 'bind': f'{ADDRESS}:{PORT}', diff --git a/setup/args.py b/setup/args.py index 7b304df..05cacb5 100644 --- a/setup/args.py +++ b/setup/args.py @@ -24,5 +24,4 @@ args = parser.parse_args() PORT = args.port ADDRESS = args.address WORKERS = args.workers - -DEBUG = args.debug \ No newline at end of file +DEBUG = args.debug diff --git a/setup/configuration.py b/setup/configuration.py index f57cbf6..31008e3 100644 --- a/setup/configuration.py +++ b/setup/configuration.py @@ -109,16 +109,14 @@ class Configuration: continue # Check if user is happy with the values - _ = input("Is this correct? (y/n): ") - - if _ == 'y' or _ == 'Y': + if input("Is this correct? (y/n): ").lower() == 'y': is_correct = True yaml_conf = { 'admin': { - 'name': '%s' % name, - 'username': '%s' % username, - 'email': '%s' % email, + 'name': name, + 'username': username, + 'email': email, }, 'upload': { 'allowed-extensions': { diff --git a/setup/runner.py b/setup/runner.py new file mode 100644 index 0000000..86b20f4 --- /dev/null +++ b/setup/runner.py @@ -0,0 +1,22 @@ +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()')