mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 11:36:16 +00:00
Submitted to PyLints needs :3
This commit is contained in:
parent
4cfcd178f1
commit
7ed3b455dd
12 changed files with 509 additions and 460 deletions
|
@ -1,115 +1,131 @@
|
|||
print("""
|
||||
"""
|
||||
___ _ _
|
||||
/ _ \\ _ __ | |_ _| | ___ __ _ ___
|
||||
| | | | '_ \\| | | | | | / _ \\/ _` / __|
|
||||
| |_| | | | | | |_| | |__| __/ (_| \\__ \\
|
||||
\\___/|_| |_|_|\\__, |_____\\___|\\__, |___/
|
||||
/ _ \ _ __ | |_ _| | ___ __ _ ___
|
||||
| | | | '_ \| | | | | | / _ \/ _` / __|
|
||||
| |_| | | | | | |_| | |__| __/ (_| \__ \
|
||||
\___/|_| |_|_|\__, |_____\___|\__, |___/
|
||||
|___/ |___/
|
||||
Created by Fluffy Bean - Version 23.03.03
|
||||
""")
|
||||
Created by Fluffy Bean - Version 23.03.04
|
||||
"""
|
||||
|
||||
from flask import Flask, render_template
|
||||
# Import system modules
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
|
||||
# Flask
|
||||
from flask_compress import Compress
|
||||
from flask import Flask, render_template
|
||||
|
||||
# Configuration
|
||||
from dotenv import load_dotenv
|
||||
import platformdirs
|
||||
|
||||
from gallery.logger import logger
|
||||
logger.innit_logger()
|
||||
|
||||
import yaml
|
||||
import os
|
||||
|
||||
from . import theme_manager
|
||||
|
||||
|
||||
USER_DIR = platformdirs.user_config_dir('onlylegs')
|
||||
INSTANCE_PATH = os.path.join(USER_DIR, 'instance')
|
||||
|
||||
|
||||
# Check if any of the required files are missing
|
||||
if not os.path.exists(platformdirs.user_config_dir('onlylegs')):
|
||||
from .setup import setup
|
||||
setup()
|
||||
|
||||
|
||||
user_dir = platformdirs.user_config_dir('onlylegs')
|
||||
instance_path = os.path.join(user_dir, 'instance')
|
||||
from . import setup
|
||||
setup.SetupApp()
|
||||
|
||||
# Get environment variables
|
||||
if os.path.exists(os.path.join(user_dir, '.env')):
|
||||
load_dotenv(os.path.join(user_dir, '.env'))
|
||||
if os.path.exists(os.path.join(USER_DIR, '.env')):
|
||||
load_dotenv(os.path.join(USER_DIR, '.env'))
|
||||
print("Loaded environment variables")
|
||||
else:
|
||||
print("No environment variables found!")
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# Get config file
|
||||
if os.path.exists(os.path.join(user_dir, 'conf.yml')):
|
||||
with open(os.path.join(user_dir, 'conf.yml'), 'r') as f:
|
||||
if os.path.exists(os.path.join(USER_DIR, 'conf.yml')):
|
||||
with open(os.path.join(USER_DIR, 'conf.yml'), encoding='utf-8') as f:
|
||||
conf = yaml.load(f, Loader=yaml.FullLoader)
|
||||
print("Loaded gallery config")
|
||||
else:
|
||||
print("No config file found!")
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
|
||||
# Setup the logging config
|
||||
LOGS_PATH = os.path.join(platformdirs.user_config_dir('onlylegs'), 'logs')
|
||||
|
||||
if not os.path.isdir(LOGS_PATH):
|
||||
os.mkdir(LOGS_PATH)
|
||||
|
||||
logging.getLogger('werkzeug').disabled = True
|
||||
logging.basicConfig(
|
||||
filename=os.path.join(LOGS_PATH, 'only.log'),
|
||||
level=logging.INFO,
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
format='%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s',
|
||||
encoding='utf-8')
|
||||
|
||||
|
||||
def create_app(test_config=None):
|
||||
# create and configure the app
|
||||
app = Flask(__name__,instance_path=instance_path)
|
||||
"""
|
||||
Create and configure the main app
|
||||
"""
|
||||
app = Flask(__name__,instance_path=INSTANCE_PATH)
|
||||
compress = Compress()
|
||||
|
||||
# App configuration
|
||||
app.config.from_mapping(
|
||||
SECRET_KEY=os.environ.get('FLASK_SECRET'),
|
||||
DATABASE=os.path.join(app.instance_path, 'gallery.sqlite'),
|
||||
UPLOAD_FOLDER=os.path.join(user_dir, 'uploads'),
|
||||
UPLOAD_FOLDER=os.path.join(USER_DIR, 'uploads'),
|
||||
ALLOWED_EXTENSIONS=conf['upload']['allowed-extensions'],
|
||||
MAX_CONTENT_LENGTH=1024 * 1024 * conf['upload']['max-size'],
|
||||
WEBSITE=conf['website'],
|
||||
)
|
||||
|
||||
if test_config is None:
|
||||
# load the instance config, if it exists, when not testing
|
||||
app.config.from_pyfile('config.py', silent=True)
|
||||
else:
|
||||
# load the test config if passed in
|
||||
app.config.from_mapping(test_config)
|
||||
|
||||
# ensure the instance folder exists
|
||||
try:
|
||||
os.makedirs(app.instance_path)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
# Load theme
|
||||
from . import sassy
|
||||
sassy.compile('default', app.root_path)
|
||||
theme_manager.CompileTheme('default', app.root_path)
|
||||
|
||||
|
||||
@app.errorhandler(405)
|
||||
def method_not_allowed(e):
|
||||
def method_not_allowed(err):
|
||||
error = '405'
|
||||
msg = e.description
|
||||
return render_template('error.html', error=error, msg=e), 404
|
||||
msg = err.description
|
||||
return render_template('error.html', error=error, msg=msg), 404
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(e):
|
||||
def page_not_found(err):
|
||||
error = '404'
|
||||
msg = e.description
|
||||
msg = err.description
|
||||
return render_template('error.html', error=error, msg=msg), 404
|
||||
|
||||
@app.errorhandler(403)
|
||||
def forbidden(e):
|
||||
def forbidden(err):
|
||||
error = '403'
|
||||
msg = e.description
|
||||
msg = err.description
|
||||
return render_template('error.html', error=error, msg=msg), 403
|
||||
|
||||
@app.errorhandler(410)
|
||||
def gone(e):
|
||||
def gone(err):
|
||||
error = '410'
|
||||
msg = e.description
|
||||
msg = err.description
|
||||
return render_template('error.html', error=error, msg=msg), 410
|
||||
|
||||
@app.errorhandler(500)
|
||||
def internal_server_error(e):
|
||||
def internal_server_error(err):
|
||||
error = '500'
|
||||
msg = e.description
|
||||
msg = err.description
|
||||
return render_template('error.html', error=error, msg=msg), 500
|
||||
|
||||
# Load login, registration and logout manager
|
||||
|
@ -130,4 +146,4 @@ def create_app(test_config=None):
|
|||
app.register_blueprint(api.blueprint)
|
||||
|
||||
compress.init_app(app)
|
||||
return app
|
||||
return app
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue