parent
c4553452a5
commit
9ae684240b
@ -0,0 +1,30 @@
|
||||
# coding=utf-8
|
||||
|
||||
# only primitive types can be specified here
|
||||
# for other derived values, use constants.py
|
||||
|
||||
# bazarr environment variable names
|
||||
ENV_STOPFILE = 'STOPFILE'
|
||||
ENV_RESTARTFILE = 'RESTARTFILE'
|
||||
ENV_BAZARR_ROOT_DIR = 'BAZARR_ROOT'
|
||||
|
||||
# bazarr subdirectories
|
||||
DIR_BACKUP = 'backup'
|
||||
DIR_CACHE = 'cache'
|
||||
DIR_CONFIG = 'config'
|
||||
DIR_DB = 'db'
|
||||
DIR_LOG = 'log'
|
||||
DIR_RESTORE = 'restore'
|
||||
|
||||
# bazarr special files
|
||||
FILE_LOG = 'bazarr.log'
|
||||
FILE_RESTART = 'bazarr.restart'
|
||||
FILE_STOP = 'bazarr.stop'
|
||||
|
||||
# bazarr exit codes
|
||||
EXIT_NORMAL = 0
|
||||
EXIT_INTERRUPT = -100
|
||||
EXIT_VALIDATION_ERROR = -101
|
||||
EXIT_CONFIG_CREATE_ERROR = -102
|
||||
EXIT_PYTHON_UPGRADE_NEEDED = -103
|
||||
EXIT_REQUIREMENTS_ERROR = -104
|
@ -0,0 +1,49 @@
|
||||
# coding=utf-8
|
||||
|
||||
# only methods can be specified here that do not cause other moudules to be loaded
|
||||
# for other methods that use settings, etc., use utilities/helper.py
|
||||
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
from literals import *
|
||||
|
||||
def get_bazarr_dir(sub_dir):
|
||||
path = os.path.join(os.environ[ENV_BAZARR_ROOT_DIR], sub_dir)
|
||||
return path
|
||||
|
||||
def make_bazarr_dir(sub_dir):
|
||||
path = get_bazarr_dir(sub_dir)
|
||||
if not os.path.exists(path):
|
||||
os.mkdir(path)
|
||||
|
||||
def get_log_file_path():
|
||||
path = os.path.join(get_bazarr_dir(DIR_LOG), FILE_LOG)
|
||||
return path
|
||||
|
||||
def get_stop_file_path():
|
||||
return os.environ[ENV_STOPFILE]
|
||||
|
||||
def get_restart_file_path():
|
||||
return os.environ[ENV_RESTARTFILE]
|
||||
|
||||
def stop_bazarr(status_code=EXIT_NORMAL, exit_main=True):
|
||||
try:
|
||||
with open(get_stop_file_path(),'w', encoding='UTF-8') as file:
|
||||
# write out status code for final exit
|
||||
file.write(f'{status_code}\n')
|
||||
file.close()
|
||||
except Exception as e:
|
||||
logging.error(f'BAZARR Cannot create stop file: {repr(e)}')
|
||||
logging.info('Bazarr is being shutdown...')
|
||||
if exit_main:
|
||||
raise SystemExit(status_code)
|
||||
|
||||
def restart_bazarr():
|
||||
try:
|
||||
Path(get_restart_file_path()).touch()
|
||||
except Exception as e:
|
||||
logging.error(f'BAZARR Cannot create restart file: {repr(e)}')
|
||||
logging.info('Bazarr is being restarted...')
|
||||
raise SystemExit(EXIT_NORMAL)
|
||||
|
Loading…
Reference in new issue