mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 03:26:16 +00:00
Bendover for PyLint
This commit is contained in:
parent
e784ca3011
commit
b426a6f6c4
8 changed files with 65 additions and 48 deletions
|
@ -4,10 +4,10 @@ Runs when the app detects that there is no user directory
|
|||
"""
|
||||
import os
|
||||
import sys
|
||||
import platformdirs
|
||||
import logging
|
||||
import yaml
|
||||
import re
|
||||
import platformdirs
|
||||
import yaml
|
||||
|
||||
|
||||
USER_DIR = platformdirs.user_config_dir('onlylegs')
|
||||
|
@ -22,19 +22,19 @@ class Configuration:
|
|||
Main setup function
|
||||
"""
|
||||
print("Running startup checks...")
|
||||
|
||||
|
||||
# Check if the user directory exists
|
||||
if not os.path.exists(USER_DIR):
|
||||
self.make_dir()
|
||||
|
||||
|
||||
# Check if the .env file exists
|
||||
if not os.path.exists(os.path.join(USER_DIR, '.env')):
|
||||
self.make_env()
|
||||
|
||||
|
||||
# Check if the conf.yml file exists
|
||||
if not os.path.exists(os.path.join(USER_DIR, 'conf.yml')):
|
||||
self.make_yaml()
|
||||
|
||||
|
||||
# Load the config files
|
||||
self.logging_config()
|
||||
|
||||
|
@ -50,7 +50,7 @@ class Configuration:
|
|||
except Exception as err:
|
||||
print("Error creating user directory:", err)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
print("Created user directory at:", USER_DIR)
|
||||
|
||||
@staticmethod
|
||||
|
@ -61,7 +61,7 @@ class Configuration:
|
|||
env_conf = {
|
||||
'FLASK_SECRET': os.urandom(32).hex(),
|
||||
}
|
||||
|
||||
|
||||
try:
|
||||
with open(os.path.join(USER_DIR, '.env'), encoding='utf-8', mode='w+') as file:
|
||||
for key, value in env_conf.items():
|
||||
|
@ -69,7 +69,7 @@ class Configuration:
|
|||
except Exception as err:
|
||||
print("Error creating environment variables:", err)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
print("""
|
||||
####################################################
|
||||
# A NEW KEY WAS GENERATED FOR YOU! PLEASE NOTE #
|
||||
|
@ -87,7 +87,7 @@ class Configuration:
|
|||
is_correct = False
|
||||
email_regex = re.compile(r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b')
|
||||
username_regex = re.compile(r'\b[A-Za-z0-9._%+-]+\b')
|
||||
|
||||
|
||||
print("\nNo config file found, please enter the following information:")
|
||||
while not is_correct:
|
||||
username = input("Admin username: ")
|
||||
|
@ -98,7 +98,7 @@ class Configuration:
|
|||
if not username or not username_regex.match(username):
|
||||
print("Username is invalid!")
|
||||
continue
|
||||
|
||||
|
||||
if not name:
|
||||
print("Name is invalid!")
|
||||
continue
|
||||
|
@ -106,11 +106,11 @@ class Configuration:
|
|||
if not email or not email_regex.match(email):
|
||||
print("Email is invalid!")
|
||||
continue
|
||||
|
||||
|
||||
# Check if user is happy with the values
|
||||
if input("Is this correct? (y/n): ").lower() == 'y':
|
||||
is_correct = True
|
||||
|
||||
|
||||
yaml_conf = {
|
||||
'admin': {
|
||||
'name': name,
|
||||
|
@ -133,7 +133,7 @@ class Configuration:
|
|||
'language': 'en',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try:
|
||||
with open(os.path.join(USER_DIR, 'conf.yml'), encoding='utf-8', mode='w+') as file:
|
||||
yaml.dump(yaml_conf, file, default_flow_style=False)
|
||||
|
@ -145,6 +145,9 @@ class Configuration:
|
|||
|
||||
@staticmethod
|
||||
def logging_config():
|
||||
"""
|
||||
Set the logging config
|
||||
"""
|
||||
logs_path = os.path.join(platformdirs.user_config_dir('onlylegs'), 'logs')
|
||||
|
||||
if not os.path.isdir(logs_path):
|
||||
|
|
|
@ -1,23 +1,32 @@
|
|||
"""
|
||||
Gunicorn configuration file
|
||||
"""
|
||||
from gunicorn.app.base import Application
|
||||
from gunicorn import util
|
||||
|
||||
|
||||
class OnlyLegs(Application):
|
||||
def __init__(self, options={}):
|
||||
"""
|
||||
Gunicorn application
|
||||
"""
|
||||
def __init__(self, options={}): # pylint: disable=W0102, W0231
|
||||
self.usage = None
|
||||
self.callable = None
|
||||
self.options = options
|
||||
self.do_load_config()
|
||||
|
||||
|
||||
def init(self, *args):
|
||||
"""
|
||||
Initialize the application
|
||||
"""
|
||||
cfg = {}
|
||||
for k, v in self.options.items():
|
||||
if k.lower() in self.cfg.settings and v is not None:
|
||||
cfg[k.lower()] = v
|
||||
for setting, value in self.options.items():
|
||||
if setting.lower() in self.cfg.settings and value is not None:
|
||||
cfg[setting.lower()] = value
|
||||
return cfg
|
||||
|
||||
def prog(self):
|
||||
|
||||
def prog(self): # pylint: disable=C0116, E0202
|
||||
return 'OnlyLegs'
|
||||
|
||||
|
||||
def load(self):
|
||||
return util.import_app('gallery:create_app()')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue