|
|
@ -8,12 +8,14 @@ import sys
|
|
|
|
import time
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
|
from bazarr.app.get_args import args
|
|
|
|
from bazarr.app.get_args import args
|
|
|
|
from bazarr.literals import *
|
|
|
|
from bazarr.literals import EXIT_PYTHON_UPGRADE_NEEDED, EXIT_NORMAL, FILE_RESTART, FILE_STOP, ENV_RESTARTFILE, ENV_STOPFILE, EXIT_INTERRUPT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def exit_program(status_code):
|
|
|
|
def exit_program(status_code):
|
|
|
|
print(f'Bazarr exited with status code {status_code}.')
|
|
|
|
print(f'Bazarr exited with status code {status_code}.')
|
|
|
|
raise SystemExit(status_code)
|
|
|
|
raise SystemExit(status_code)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_python_version():
|
|
|
|
def check_python_version():
|
|
|
|
python_version = platform.python_version_tuple()
|
|
|
|
python_version = platform.python_version_tuple()
|
|
|
|
minimum_py3_tuple = (3, 8, 0)
|
|
|
|
minimum_py3_tuple = (3, 8, 0)
|
|
|
@ -52,9 +54,10 @@ check_python_version()
|
|
|
|
|
|
|
|
|
|
|
|
dir_name = os.path.dirname(__file__)
|
|
|
|
dir_name = os.path.dirname(__file__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def start_bazarr():
|
|
|
|
def start_bazarr():
|
|
|
|
script = [get_python_path(), "-u", os.path.normcase(os.path.join(dir_name, 'bazarr', 'main.py'))] + sys.argv[1:]
|
|
|
|
script = [get_python_path(), "-u", os.path.normcase(os.path.join(dir_name, 'bazarr', 'main.py'))] + sys.argv[1:]
|
|
|
|
ep = subprocess.Popen(script, stdout=None, stderr=None, stdin=subprocess.DEVNULL)
|
|
|
|
ep = subprocess.Popen(script, stdout=None, stderr=None, stdin=subprocess.DEVNULL, env=os.environ)
|
|
|
|
print(f"Bazarr starting child process with PID {ep.pid}...")
|
|
|
|
print(f"Bazarr starting child process with PID {ep.pid}...")
|
|
|
|
return ep
|
|
|
|
return ep
|
|
|
|
|
|
|
|
|
|
|
@ -81,21 +84,21 @@ def get_stop_status_code(input_file):
|
|
|
|
|
|
|
|
|
|
|
|
def check_status():
|
|
|
|
def check_status():
|
|
|
|
global child_process
|
|
|
|
global child_process
|
|
|
|
if os.path.exists(stopfile):
|
|
|
|
if os.path.exists(stop_file):
|
|
|
|
status_code = get_stop_status_code(stopfile)
|
|
|
|
status_code = get_stop_status_code(stop_file)
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
print(f"Deleting stop file...")
|
|
|
|
print(f"Deleting stop file...")
|
|
|
|
os.remove(stopfile)
|
|
|
|
os.remove(stop_file)
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
print('Unable to delete stop file.')
|
|
|
|
print('Unable to delete stop file.')
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
|
terminate_child()
|
|
|
|
terminate_child()
|
|
|
|
exit_program(status_code)
|
|
|
|
exit_program(status_code)
|
|
|
|
|
|
|
|
|
|
|
|
if os.path.exists(restartfile):
|
|
|
|
if os.path.exists(restart_file):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
print(f"Deleting restart file...")
|
|
|
|
print(f"Deleting restart file...")
|
|
|
|
os.remove(restartfile)
|
|
|
|
os.remove(restart_file)
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
print('Unable to delete restart file.')
|
|
|
|
print('Unable to delete restart file.')
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
@ -119,19 +122,19 @@ def interrupt_handler(signum, frame):
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
interrupted = False
|
|
|
|
interrupted = False
|
|
|
|
signal.signal(signal.SIGINT, interrupt_handler)
|
|
|
|
signal.signal(signal.SIGINT, interrupt_handler)
|
|
|
|
restartfile = os.path.join(args.config_dir, FILE_RESTART)
|
|
|
|
restart_file = os.path.join(args.config_dir, FILE_RESTART)
|
|
|
|
stopfile = os.path.join(args.config_dir, FILE_STOP)
|
|
|
|
stop_file = os.path.join(args.config_dir, FILE_STOP)
|
|
|
|
os.environ[ENV_STOPFILE] = stopfile
|
|
|
|
os.environ[ENV_STOPFILE] = stop_file
|
|
|
|
os.environ[ENV_RESTARTFILE] = restartfile
|
|
|
|
os.environ[ENV_RESTARTFILE] = restart_file
|
|
|
|
|
|
|
|
|
|
|
|
# Cleanup leftover files
|
|
|
|
# Cleanup leftover files
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
os.remove(restartfile)
|
|
|
|
os.remove(restart_file)
|
|
|
|
except FileNotFoundError:
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
os.remove(stopfile)
|
|
|
|
os.remove(stop_file)
|
|
|
|
except FileNotFoundError:
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|