Remove Verbose option temporarilly

Gunicorn is really not happy with anything I try and parse through it
This commit is contained in:
Michał Gdula 2023-03-12 13:12:38 +00:00
parent 2eec988815
commit dea3cca4a6
5 changed files with 28 additions and 36 deletions

View file

@ -22,7 +22,7 @@ from yaml import FullLoader, load
USER_DIR = platformdirs.user_config_dir('onlylegs') USER_DIR = platformdirs.user_config_dir('onlylegs')
def create_app(test_config=None, verbose=False): def create_app(test_config=None):
""" """
Create and configure the main app Create and configure the main app
""" """
@ -33,14 +33,12 @@ def create_app(test_config=None, verbose=False):
# Get environment variables # Get environment variables
load_dotenv(os.path.join(USER_DIR, '.env')) load_dotenv(os.path.join(USER_DIR, '.env'))
if verbose: 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 f:
conf = load(f, Loader=FullLoader) conf = load(f, Loader=FullLoader)
if verbose: print("Loaded gallery config")
print("Loaded gallery config")
# App configuration # App configuration
app.config.from_mapping( app.config.from_mapping(
@ -64,7 +62,7 @@ def create_app(test_config=None, verbose=False):
# Load theme # Load theme
from . import theme_manager from . import theme_manager
theme_manager.CompileTheme('default', app.root_path, verbose) theme_manager.CompileTheme('default', app.root_path)
# Bundle JS files # Bundle JS files
js = Bundle('js/*.js', output='gen/packed.js') js = Bundle('js/*.js', output='gen/packed.js')

View file

@ -12,14 +12,13 @@ class CompileTheme:
""" """
Compiles the theme into the static folder Compiles the theme into the static folder
""" """
def __init__(self, theme_name, app_path, verbose=False): def __init__(self, theme_name, app_path):
""" """
Initialize the theme manager Initialize the theme manager
Compiles the theme into the static folder and loads the fonts Compiles the theme into the static folder and loads the fonts
""" """
if verbose: print(f"Loading '{theme_name}' theme...")
print(f"Loading '{theme_name}' theme...")
theme_path = os.path.join(app_path, 'themes', theme_name) theme_path = os.path.join(app_path, 'themes', theme_name)
theme_dest = os.path.join(app_path, 'static', 'theme') theme_dest = os.path.join(app_path, 'static', 'theme')
@ -28,14 +27,16 @@ class CompileTheme:
print("Theme does not exist!") print("Theme does not exist!")
sys.exit(1) sys.exit(1)
if not os.path.exists(theme_dest):
os.makedirs(theme_dest)
self.load_sass(theme_path, theme_dest) self.load_sass(theme_path, theme_dest)
self.load_fonts(theme_path, theme_dest) self.load_fonts(theme_path, theme_dest)
if verbose: print(f"{datetime.now().hour}:{datetime.now().minute}:{datetime.now().second} - Done!\n")
print(f"{datetime.now().hour}:{datetime.now().minute}:{datetime.now().second} - Done!\n")
@staticmethod @staticmethod
def load_sass(source_path, css_dest, verbose=False): def load_sass(source_path, css_dest):
""" """
Compile the sass (or scss) file into css and save it to the static folder Compile the sass (or scss) file into css and save it to the static folder
""" """
@ -47,9 +48,6 @@ class CompileTheme:
print("No sass file found!") print("No sass file found!")
sys.exit(1) sys.exit(1)
if not os.path.exists(css_dest):
os.makedirs(css_dest)
with open(os.path.join(css_dest, 'style.css'), encoding='utf-8', mode='w+') as file: with open(os.path.join(css_dest, 'style.css'), encoding='utf-8', mode='w+') as file:
try: try:
file.write(sass.compile(filename=sass_path,output_style='compressed')) file.write(sass.compile(filename=sass_path,output_style='compressed'))
@ -57,11 +55,10 @@ class CompileTheme:
print("Failed to compile!\n", err) print("Failed to compile!\n", err)
sys.exit(1) sys.exit(1)
if verbose: print("Compiled successfully!")
print("Compiled successfully!")
@staticmethod @staticmethod
def load_fonts(source_path, font_dest, verbose=False): def load_fonts(source_path, font_dest):
""" """
Copy the fonts folder to the static folder Copy the fonts folder to the static folder
""" """
@ -82,5 +79,4 @@ class CompileTheme:
print("Failed to copy fonts!\n", err) print("Failed to copy fonts!\n", err)
sys.exit(1) sys.exit(1)
if verbose: print("Fonts copied successfully!")
print("Fonts copied successfully!")

9
run.py
View file

@ -8,17 +8,18 @@ print("""
Created by Fluffy Bean - Version 23.03.12 Created by Fluffy Bean - Version 23.03.12
""") """)
from setup.args import PORT, ADDRESS, WORKERS, DEBUG, VERBOSE
from setup.args import PORT, ADDRESS, WORKERS, DEBUG
from setup.configuration import Configuration from setup.configuration import Configuration
# Run prechecks # Run prechecks
Configuration(verbose=VERBOSE) Configuration()
if DEBUG: if DEBUG:
from gallery import create_app from gallery import create_app
create_app(verbose=VERBOSE).run(host=ADDRESS, port=PORT, debug=True, threaded=True) create_app().run(host=ADDRESS, port=PORT, debug=True, threaded=True)
else: else:
from gunicorn.app.base import Application from gunicorn.app.base import Application
from gunicorn import util from gunicorn import util
@ -41,7 +42,7 @@ else:
return 'OnlyLegs' return 'OnlyLegs'
def load(self): def load(self):
return util.import_app(f'gallery:create_app(verbose={VERBOSE})') return util.import_app('gallery:create_app()')
options = { options = {
'bind': f'{ADDRESS}:{PORT}', 'bind': f'{ADDRESS}:{PORT}',

View file

@ -6,7 +6,7 @@ Startup arguments for the OnlyLegs gallery
-w, --workers: Number of workers to run (default: 4) -w, --workers: Number of workers to run (default: 4)
-d, --debug: Run as Flask app in debug mode (default: False) -d, --debug: Run as Flask app in debug mode (default: False)
-V, --verbose: Show verbose output (default: False) -S, --scream: Show verbose output (default: False)
-h, --help: Show a help message -h, --help: Show a help message
""" """
@ -18,7 +18,6 @@ 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('-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('-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') parser.add_argument('-d', '--debug', action='store_true', help='Run as Flask app in debug mode')
parser.add_argument('-V', '--verbose', action='store_true', help='Show verbose output')
args = parser.parse_args() args = parser.parse_args()
@ -27,4 +26,3 @@ ADDRESS = args.address
WORKERS = args.workers WORKERS = args.workers
DEBUG = args.debug DEBUG = args.debug
VERBOSE = args.verbose

View file

@ -17,12 +17,11 @@ class Configuration:
""" """
Setup the application on first run Setup the application on first run
""" """
def __init__(self, verbose=False): def __init__(self):
""" """
Main setup function Main setup function
""" """
if verbose: print("Running startup checks...")
print("Running startup checks...")
# Check if the user directory exists # Check if the user directory exists
if not os.path.exists(USER_DIR): if not os.path.exists(USER_DIR):
@ -71,11 +70,11 @@ class Configuration:
sys.exit(1) sys.exit(1)
print(""" print("""
#################################################### ####################################################
# PLEASE NOTE DOWN THE FLASK_SECRET KEY LOCARED IN # # PLEASE NOTE DOWN THE FLASK_SECRET KEY LOCARED IN #
# YOUR .config/onlylegs/.env FILE! A NEW KEY WAS # # YOUR .config/onlylegs/.env FILE! A NEW KEY WAS #
# GENERATED FOR YOU! # # GENERATED FOR YOU! #
#################################################### ####################################################
""") """)
@staticmethod @staticmethod