spectra/config.py
2024-11-05 14:02:00 -05:00

29 lines
776 B
Python

import toml
import os
import secrets
CONFIG_FILE = 'config.toml'
def load_or_create_config():
if not os.path.exists(CONFIG_FILE):
admin_password = secrets.token_urlsafe(16)
config = {
'admin': {
'password': admin_password
},
'directories': {
'upload': 'uploads',
'thumbnail': 'thumbnails'
},
'appearance': {
'accent_color': '{{ accent_color }}'
}
}
with open(CONFIG_FILE, 'w') as f:
toml.dump(config, f)
print(f"Generated new config file with admin password: {admin_password}")
else:
with open(CONFIG_FILE, 'r') as f:
config = toml.load(f)
return config