mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 11:36:16 +00:00
Move user data to ~/.config/onlylegs location
Update location of default themes folder
This commit is contained in:
parent
828167f762
commit
512f6f623e
31 changed files with 158 additions and 110 deletions
|
@ -5,37 +5,96 @@ print("""
|
|||
| |_| | | | | | |_| | |__| __/ (_| \\__ \\
|
||||
\\___/|_| |_|_|\\__, |_____\\___|\\__, |___/
|
||||
|___/ |___/
|
||||
Created by Fluffy Bean - Version 23.03.01
|
||||
Created by Fluffy Bean - Version 23.03.02
|
||||
""")
|
||||
|
||||
from flask import Flask, render_template
|
||||
from flask_compress import Compress
|
||||
from flask.helpers import get_root_path
|
||||
|
||||
from dotenv import load_dotenv
|
||||
import platformdirs
|
||||
|
||||
import yaml
|
||||
import os
|
||||
|
||||
print(f"Running at {get_root_path(__name__)}\n")
|
||||
# I could use something other than the config dir, but this works well enough
|
||||
user_dir = platformdirs.user_config_dir('onlylegs')
|
||||
if not os.path.exists(user_dir):
|
||||
os.makedirs(user_dir)
|
||||
print("Created user directory")
|
||||
# Location of instance folder, where sqlite db is stored
|
||||
instance_path = os.path.join(user_dir, 'instance')
|
||||
if not os.path.exists(instance_path):
|
||||
os.makedirs(instance_path)
|
||||
print("Created instance directory")
|
||||
|
||||
# Get environment variables
|
||||
if os.path.exists(os.path.join(user_dir, '.env')):
|
||||
load_dotenv(os.path.join(user_dir, '.env'))
|
||||
print("Loaded environment variables")
|
||||
else:
|
||||
conf = {
|
||||
'FLASK_SECRETE': 'dev',
|
||||
}
|
||||
# Create .env file with default values
|
||||
with open(os.path.join(user_dir, '.env'), 'w') as f:
|
||||
for key, value in conf.items():
|
||||
f.write(f"{key}={value}\n")
|
||||
print("Created default environment variables at:",
|
||||
os.path.join(user_dir, '.env'),
|
||||
"\nCHANGE THESE VALUES USING TEHE GALLERY!")
|
||||
|
||||
# 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:
|
||||
conf = yaml.load(f, Loader=yaml.FullLoader)
|
||||
print("Loaded gallery config")
|
||||
else:
|
||||
conf = {
|
||||
'admin': {
|
||||
'name': 'Real Person',
|
||||
'username': 'User',
|
||||
'email': 'real-email@some.place'
|
||||
},
|
||||
'upload': {
|
||||
'allowed-extensions': {
|
||||
'jpg': 'jpeg',
|
||||
'jpeg': 'jpeg',
|
||||
'png': 'png',
|
||||
'webp': 'webp'
|
||||
},
|
||||
'max-size': 69,
|
||||
'rename': 'GWA_\{\{username\}\}_\{\{time\}\}'
|
||||
},
|
||||
'website': {
|
||||
'name': 'OnlyLegs',
|
||||
'motto': 'Gwa Gwa',
|
||||
'language': 'english'
|
||||
}
|
||||
}
|
||||
# Create yaml config file with default values
|
||||
with open(os.path.join(user_dir, 'conf.yml'), 'w') as f:
|
||||
yaml.dump(conf, f, default_flow_style=False)
|
||||
print("Created default gallery config at:",
|
||||
os.path.join(user_dir, 'conf.yml'),
|
||||
"\nCHANGE THESE VALUES USING TEHE GALLERY!")
|
||||
|
||||
# Load logger
|
||||
from .logger import logger
|
||||
|
||||
logger.innit_logger()
|
||||
|
||||
|
||||
def create_app(test_config=None):
|
||||
# create and configure the app
|
||||
app = Flask(__name__)
|
||||
app = Flask(__name__, instance_path=instance_path)
|
||||
compress = Compress()
|
||||
|
||||
# Get environment variables
|
||||
load_dotenv(os.path.join(app.root_path, 'user', '.env'))
|
||||
print("Loaded environment variables")
|
||||
|
||||
# Get config file
|
||||
with open(os.path.join(app.root_path, 'user', 'conf.yml'), 'r') as f:
|
||||
conf = yaml.load(f, Loader=yaml.FullLoader)
|
||||
print("Loaded gallery config")
|
||||
|
||||
# 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(app.root_path, 'user', 'uploads'),
|
||||
UPLOAD_FOLDER=os.path.join(user_dir, 'uploads'),
|
||||
MAX_CONTENT_LENGTH=1024 * 1024 * conf['upload']['max-size'],
|
||||
ALLOWED_EXTENSIONS=conf['upload']['allowed-extensions'],
|
||||
WEBSITE=conf['website'],
|
||||
|
@ -61,10 +120,6 @@ def create_app(test_config=None):
|
|||
# Load theme
|
||||
from . import sassy
|
||||
sassy.compile('default', app.root_path)
|
||||
|
||||
# Load logger
|
||||
from .logger import logger
|
||||
logger.innit_logger(app)
|
||||
|
||||
@app.errorhandler(405)
|
||||
def method_not_allowed(e):
|
||||
|
@ -104,7 +159,7 @@ def create_app(test_config=None):
|
|||
from . import routing
|
||||
app.register_blueprint(routing.blueprint)
|
||||
app.add_url_rule('/', endpoint='index')
|
||||
|
||||
|
||||
# Load routes for settings
|
||||
from . import settings
|
||||
app.register_blueprint(settings.blueprint)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue