79 lines
2 KiB
Python
79 lines
2 KiB
Python
import sys
|
|
import os
|
|
|
|
import logging as logger
|
|
|
|
from os import environ as env
|
|
from os.path import isdir, isfile, abspath, dirname, basename
|
|
from envbash import load_envbash
|
|
|
|
from .functions import bool_check
|
|
|
|
VERSION = '0.2-beta'
|
|
|
|
full_path = abspath(sys.executable) if getattr(sys, 'frozen', False) else abspath(__file__)
|
|
script_path = getattr(sys, '_MEIPASS', dirname(abspath(__file__)))
|
|
script_name = basename(full_path)
|
|
stor_path = abspath(f'{script_path}/../data')
|
|
|
|
|
|
if not isdir(stor_path):
|
|
os.makedirs(stor_path, exist_ok=True)
|
|
|
|
|
|
if not bool_check(env.get('LOGDATE', 'yes').lower()):
|
|
log_date = ''
|
|
|
|
else:
|
|
log_date = '[%(asctime)s] '
|
|
|
|
|
|
logging = logger.getLogger()
|
|
logging.setLevel(logger.DEBUG)
|
|
log_format = f'{log_date} %(levelname)s: %(message)s'
|
|
|
|
logger.addLevelName(5, 'VERBOSE')
|
|
logger.addLevelName(30, 'WARN')
|
|
logger.addLevelName(50, 'CRIT')
|
|
|
|
console = logger.StreamHandler()
|
|
console.name = 'Console Log'
|
|
console.level = logger.INFO
|
|
console.formatter = logger.Formatter(log_format)
|
|
|
|
logging.addHandler(console)
|
|
|
|
|
|
if not isfile(f'{stor_path}/production.env'):
|
|
logging.error(f'PAWS environment file doesn\'t exist: {stor_path}/production.env')
|
|
|
|
else:
|
|
load_envbash(f'{stor_path}/production.env')
|
|
|
|
PAWSCONFIG = {
|
|
'host': env.get('PAWS_HOST', '127.0.0.1'),
|
|
'port': int(env.get('PAWS_PORT', 3001)),
|
|
'admin': env.get('PAWS_ADMIN', None),
|
|
'mastopath': env.get('MASTOPATH', os.getcwd()),
|
|
}
|
|
|
|
|
|
masto_path = PAWSCONFIG['mastopath']
|
|
|
|
if not isfile(f'{masto_path}/.env.production'):
|
|
logging.error(f'Mastodon environment file doesn\'t exist: {masto_path}/.env.production')
|
|
|
|
else:
|
|
load_envbash(f'{masto_path}/.env.production')
|
|
|
|
MASTOCONFIG={
|
|
'domain': env.get('WEB_DOMAIN', env.get('LOCAL_DOMAIN', 'localhost:3000')),
|
|
'auth_fetch': bool_check(env.get('AUTHORIZED_FETCH')),
|
|
'dbhost': env.get('DB_HOST', '/var/run/postgresql'),
|
|
'dbport': int(env.get('DB_PORT', 5432)),
|
|
'dbname': env.get('DB_NAME', 'mastodon_production'),
|
|
'dbuser': env.get('DB_USER', env.get('USER')),
|
|
'dbpass': env.get('DB_PASS')
|
|
}
|
|
|