You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bazarr/bazarr.py

101 lines
2.8 KiB

# coding=utf-8
5 years ago
from __future__ import absolute_import
from __future__ import print_function
5 years ago
import bazarr.libs
5 years ago
from six import PY3
import subprocess as sp
import time
import os
import sys
import platform
import re
from bazarr.get_args import args
def check_python_version():
python_version = platform.python_version_tuple()
minimum_python_version_tuple = (2, 7, 13)
5 years ago
minimum_python3_version_tuple = (3, 6, 0)
minimum_python_version = ".".join(str(i) for i in minimum_python_version_tuple)
5 years ago
minimum_python3_version = ".".join(str(i) for i in minimum_python3_version_tuple)
5 years ago
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)
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]:
5 years ago
print("Python " + minimum_python_version + " or greater required. Current version is " + platform.python_version() + ". Please upgrade Python.")
os._exit(0)
check_python_version()
dir_name = os.path.dirname(__file__)
def start_bazarr():
script = [sys.executable, "-u", os.path.normcase(os.path.join(dir_name, 'bazarr', 'main.py'))] + sys.argv[1:]
5 years ago
ep = sp.Popen(script, stdout=sp.PIPE, stderr=sp.STDOUT, stdin=sp.PIPE)
5 years ago
print("Bazarr starting...")
try:
while True:
line = ep.stdout.readline()
if line == '' or not line:
break
5 years ago
if PY3:
sys.stdout.buffer.write(line)
else:
sys.stdout.write(line)
sys.stdout.flush()
except KeyboardInterrupt:
pass
if __name__ == '__main__':
restartfile = os.path.normcase(os.path.join(args.config_dir, 'bazarr.restart'))
stopfile = os.path.normcase(os.path.join(args.config_dir, 'bazarr.stop'))
5 years ago
try:
os.remove(restartfile)
except:
pass
5 years ago
try:
os.remove(stopfile)
except:
pass
5 years ago
def daemon():
if os.path.exists(stopfile):
try:
os.remove(stopfile)
except:
5 years ago
print('Unable to delete stop file.')
else:
5 years ago
print('Bazarr exited.')
os._exit(0)
5 years ago
if os.path.exists(restartfile):
try:
os.remove(restartfile)
except:
5 years ago
print('Unable to delete restart file.')
else:
start_bazarr()
5 years ago
start_bazarr()
5 years ago
# Keep the script running forever.
while True:
daemon()
time.sleep(1)