2018-10-31 19:34:40 +00:00
|
|
|
# coding=utf-8
|
|
|
|
|
2019-09-13 19:12:26 +00:00
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import print_function
|
2019-09-28 16:38:26 +00:00
|
|
|
|
|
|
|
import bazarr.libs
|
2019-09-23 20:21:24 +00:00
|
|
|
from six import PY3
|
2018-10-03 10:53:22 +00:00
|
|
|
import subprocess as sp
|
|
|
|
import time
|
2018-09-12 02:32:09 +00:00
|
|
|
import os
|
2018-10-03 10:53:22 +00:00
|
|
|
import sys
|
2019-09-05 15:30:14 +00:00
|
|
|
import platform
|
2019-09-18 15:35:19 +00:00
|
|
|
import re
|
2018-10-03 10:53:22 +00:00
|
|
|
|
2018-10-31 19:34:40 +00:00
|
|
|
from bazarr.get_args import args
|
2018-10-03 10:53:22 +00:00
|
|
|
|
2019-09-05 15:30:14 +00:00
|
|
|
|
|
|
|
def check_python_version():
|
|
|
|
python_version = platform.python_version_tuple()
|
|
|
|
minimum_python_version_tuple = (2, 7, 13)
|
2019-09-13 19:12:26 +00:00
|
|
|
minimum_python3_version_tuple = (3, 6, 0)
|
2019-09-05 15:30:14 +00:00
|
|
|
minimum_python_version = ".".join(str(i) for i in minimum_python_version_tuple)
|
2019-09-13 19:12:26 +00:00
|
|
|
minimum_python3_version = ".".join(str(i) for i in minimum_python3_version_tuple)
|
2019-09-05 15:30:14 +00:00
|
|
|
|
2019-09-23 02:27:23 +00:00
|
|
|
if int(python_version[0]) == minimum_python3_version_tuple[0]:
|
|
|
|
if int(python_version[1]) >= minimum_python3_version_tuple[1]:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
print("Python " + minimum_python3_version + " or greater required. Current version is " + platform.python_version() + ". Please upgrade Python.")
|
|
|
|
os._exit(0)
|
2019-09-05 15:30:14 +00:00
|
|
|
|
2019-09-18 15:35:19 +00:00
|
|
|
elif int(python_version[1]) < minimum_python_version_tuple[1] or int(re.search(r'\d+', python_version[2]).group()) < minimum_python_version_tuple[2]:
|
2019-09-13 19:12:26 +00:00
|
|
|
print("Python " + minimum_python_version + " or greater required. Current version is " + platform.python_version() + ". Please upgrade Python.")
|
2019-09-05 15:30:14 +00:00
|
|
|
os._exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
check_python_version()
|
|
|
|
|
2018-10-11 01:23:30 +00:00
|
|
|
dir_name = os.path.dirname(__file__)
|
|
|
|
|
2018-10-31 17:09:46 +00:00
|
|
|
|
2018-10-03 10:53:22 +00:00
|
|
|
def start_bazarr():
|
2018-10-31 19:34:40 +00:00
|
|
|
script = [sys.executable, "-u", os.path.normcase(os.path.join(dir_name, 'bazarr', 'main.py'))] + sys.argv[1:]
|
2019-06-11 18:45:48 +00:00
|
|
|
|
2018-10-14 13:32:16 +00:00
|
|
|
ep = sp.Popen(script, stdout=sp.PIPE, stderr=sp.STDOUT, stdin=sp.PIPE)
|
2019-09-13 19:12:26 +00:00
|
|
|
print("Bazarr starting...")
|
2018-10-14 13:32:16 +00:00
|
|
|
try:
|
2019-12-07 03:40:40 +00:00
|
|
|
while True:
|
|
|
|
line = ep.stdout.readline()
|
|
|
|
if line == '' or not line:
|
|
|
|
break
|
2019-09-23 20:21:24 +00:00
|
|
|
if PY3:
|
|
|
|
sys.stdout.buffer.write(line)
|
|
|
|
else:
|
|
|
|
sys.stdout.write(line)
|
2018-10-14 13:32:16 +00:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
2018-10-04 18:16:49 +00:00
|
|
|
|
|
|
|
|
2018-10-03 10:53:22 +00:00
|
|
|
if __name__ == '__main__':
|
2018-10-31 19:34:40 +00:00
|
|
|
restartfile = os.path.normcase(os.path.join(args.config_dir, 'bazarr.restart'))
|
|
|
|
stopfile = os.path.normcase(os.path.join(args.config_dir, 'bazarr.stop'))
|
2019-06-11 18:45:48 +00:00
|
|
|
|
2018-09-12 02:32:09 +00:00
|
|
|
try:
|
2018-10-03 10:53:22 +00:00
|
|
|
os.remove(restartfile)
|
2018-10-11 01:23:30 +00:00
|
|
|
except:
|
|
|
|
pass
|
2019-06-11 18:45:48 +00:00
|
|
|
|
2018-10-11 01:23:30 +00:00
|
|
|
try:
|
2018-10-03 10:53:22 +00:00
|
|
|
os.remove(stopfile)
|
|
|
|
except:
|
2018-09-12 02:32:09 +00:00
|
|
|
pass
|
2019-06-11 18:45:48 +00:00
|
|
|
|
|
|
|
|
2018-10-03 10:53:22 +00:00
|
|
|
def daemon():
|
|
|
|
if os.path.exists(stopfile):
|
|
|
|
try:
|
|
|
|
os.remove(stopfile)
|
|
|
|
except:
|
2019-09-13 19:12:26 +00:00
|
|
|
print('Unable to delete stop file.')
|
2018-10-03 10:53:22 +00:00
|
|
|
else:
|
2019-09-13 19:12:26 +00:00
|
|
|
print('Bazarr exited.')
|
2018-10-03 10:53:22 +00:00
|
|
|
os._exit(0)
|
2019-06-11 18:45:48 +00:00
|
|
|
|
2018-10-03 10:53:22 +00:00
|
|
|
if os.path.exists(restartfile):
|
|
|
|
try:
|
|
|
|
os.remove(restartfile)
|
|
|
|
except:
|
2019-09-13 19:12:26 +00:00
|
|
|
print('Unable to delete restart file.')
|
2018-10-03 10:53:22 +00:00
|
|
|
else:
|
|
|
|
start_bazarr()
|
2019-06-11 18:45:48 +00:00
|
|
|
|
|
|
|
|
2018-10-03 10:53:22 +00:00
|
|
|
start_bazarr()
|
2019-06-11 18:45:48 +00:00
|
|
|
|
2018-10-03 10:53:22 +00:00
|
|
|
# Keep the script running forever.
|
|
|
|
while True:
|
2019-05-31 23:00:32 +00:00
|
|
|
daemon()
|
|
|
|
time.sleep(1)
|