mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 03:26:16 +00:00
Format code with Black
This commit is contained in:
parent
fef8a557d2
commit
128464d43f
18 changed files with 697 additions and 604 deletions
|
@ -13,11 +13,17 @@ Startup arguments for the OnlyLegs gallery
|
|||
import argparse
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description='Run the OnlyLegs gallery')
|
||||
parser.add_argument('-p', '--port', type=int, default=5000, help='Port to run on')
|
||||
parser.add_argument('-a', '--address', type=str, default='127.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('-d', '--debug', action='store_true', help='Run as Flask app in debug mode')
|
||||
parser = argparse.ArgumentParser(description="Run the OnlyLegs gallery")
|
||||
parser.add_argument("-p", "--port", type=int, default=5000, help="Port to run on")
|
||||
parser.add_argument(
|
||||
"-a", "--address", type=str, default="127.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(
|
||||
"-d", "--debug", action="store_true", help="Run as Flask app in debug mode"
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
|
|
|
@ -9,13 +9,14 @@ import platformdirs
|
|||
import yaml
|
||||
|
||||
|
||||
USER_DIR = platformdirs.user_config_dir('onlylegs')
|
||||
USER_DIR = platformdirs.user_config_dir("onlylegs")
|
||||
|
||||
|
||||
class Configuration:
|
||||
"""
|
||||
Setup the application on first run
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Main setup function
|
||||
|
@ -27,11 +28,11 @@ class Configuration:
|
|||
self.make_dir()
|
||||
|
||||
# Check if the .env file exists
|
||||
if not os.path.exists(os.path.join(USER_DIR, '.env')):
|
||||
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')):
|
||||
if not os.path.exists(os.path.join(USER_DIR, "conf.yml")):
|
||||
self.make_yaml()
|
||||
|
||||
# Load the config files
|
||||
|
@ -43,8 +44,8 @@ class Configuration:
|
|||
Create the user directory
|
||||
"""
|
||||
os.makedirs(USER_DIR)
|
||||
os.makedirs(os.path.join(USER_DIR, 'instance'))
|
||||
os.makedirs(os.path.join(USER_DIR, 'uploads'))
|
||||
os.makedirs(os.path.join(USER_DIR, "instance"))
|
||||
os.makedirs(os.path.join(USER_DIR, "uploads"))
|
||||
|
||||
print("Created user directory at:", USER_DIR)
|
||||
|
||||
|
@ -54,21 +55,23 @@ class Configuration:
|
|||
Create the .env file with default values
|
||||
"""
|
||||
env_conf = {
|
||||
'FLASK_SECRET': os.urandom(32).hex(),
|
||||
"FLASK_SECRET": os.urandom(32).hex(),
|
||||
}
|
||||
|
||||
with open(os.path.join(USER_DIR, '.env'), encoding='utf-8', mode='w+') as file:
|
||||
with open(os.path.join(USER_DIR, ".env"), encoding="utf-8", mode="w+") as file:
|
||||
for key, value in env_conf.items():
|
||||
file.write(f"{key}={value}\n")
|
||||
|
||||
print("""
|
||||
print(
|
||||
"""
|
||||
####################################################
|
||||
# A NEW KEY WAS GENERATED FOR YOU! PLEASE NOTE #
|
||||
# DOWN THE FLASK_SECRET KEY LOCATED IN YOUR #
|
||||
# .config/onlylegs/.env FOLDER! LOOSING THIS KEY #
|
||||
# WILL RESULT IN YOU BEING UNABLE TO LOG IN! #
|
||||
####################################################
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def make_yaml():
|
||||
|
@ -76,8 +79,8 @@ class Configuration:
|
|||
Create the YAML config file with default values
|
||||
"""
|
||||
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')
|
||||
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:
|
||||
|
@ -99,47 +102,52 @@ class Configuration:
|
|||
continue
|
||||
|
||||
# Check if user is happy with the values
|
||||
if input("Is this correct? (y/n): ").lower() == 'y':
|
||||
if input("Is this correct? (y/n): ").lower() == "y":
|
||||
is_correct = True
|
||||
|
||||
yaml_conf = {
|
||||
'admin': {
|
||||
'name': name,
|
||||
'username': username,
|
||||
'email': email,
|
||||
"admin": {
|
||||
"name": name,
|
||||
"username": username,
|
||||
"email": email,
|
||||
},
|
||||
'upload': {
|
||||
'allowed-extensions': {
|
||||
'jpg': 'jpeg',
|
||||
'jpeg': 'jpeg',
|
||||
'png': 'png',
|
||||
'webp': 'webp',
|
||||
"upload": {
|
||||
"allowed-extensions": {
|
||||
"jpg": "jpeg",
|
||||
"jpeg": "jpeg",
|
||||
"png": "png",
|
||||
"webp": "webp",
|
||||
},
|
||||
'max-size': 69,
|
||||
'max-load': 50,
|
||||
'rename': 'GWA_{{username}}_{{time}}',
|
||||
"max-size": 69,
|
||||
"max-load": 50,
|
||||
"rename": "GWA_{{username}}_{{time}}",
|
||||
},
|
||||
"website": {
|
||||
"name": "OnlyLegs",
|
||||
"motto": "A gallery built for fast and simple image management!",
|
||||
"language": "en",
|
||||
},
|
||||
'website': {
|
||||
'name': 'OnlyLegs',
|
||||
'motto': 'A gallery built for fast and simple image management!',
|
||||
'language': 'en',
|
||||
}
|
||||
}
|
||||
|
||||
with open(os.path.join(USER_DIR, 'conf.yml'), encoding='utf-8', mode='w+') as file:
|
||||
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)
|
||||
|
||||
print("Generated config file, you can change these values in the settings of the app")
|
||||
print(
|
||||
"Generated config file, you can change these values in the settings of the app"
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def logging_config():
|
||||
"""
|
||||
Set the logging config
|
||||
"""
|
||||
logging.getLogger('werkzeug').disabled = True
|
||||
logging.getLogger("werkzeug").disabled = True
|
||||
logging.basicConfig(
|
||||
filename=os.path.join(USER_DIR, 'only.log'),
|
||||
filename=os.path.join(USER_DIR, "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')
|
||||
datefmt="%Y-%m-%d %H:%M:%S",
|
||||
format="%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
|
|
@ -9,6 +9,7 @@ class OnlyLegs(Application):
|
|||
"""
|
||||
Gunicorn application
|
||||
"""
|
||||
|
||||
def __init__(self, options={}): # pylint: disable=W0102, W0231
|
||||
self.usage = None
|
||||
self.callable = None
|
||||
|
@ -27,7 +28,7 @@ class OnlyLegs(Application):
|
|||
|
||||
@staticmethod
|
||||
def prog(): # pylint: disable=C0116, E0202
|
||||
return 'OnlyLegs'
|
||||
return "OnlyLegs"
|
||||
|
||||
def load(self):
|
||||
return util.import_app('gallery:create_app()')
|
||||
return util.import_app("gallery:create_app()")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue