bazarr/bazarr.py

66 lines
1.5 KiB
Python
Raw Normal View History

# coding=utf-8
import subprocess as sp
import time
import os
import sys
from bazarr import libs
from bazarr.get_args import args
2018-10-11 01:23:30 +00:00
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:]
2019-06-11 18:45:48 +00:00
ep = sp.Popen(script, stdout=sp.PIPE, stderr=sp.STDOUT, stdin=sp.PIPE)
2018-10-16 12:48:25 +00:00
print "Bazarr starting..."
try:
for line in iter(ep.stdout.readline, ''):
sys.stdout.write(line)
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'))
2019-06-11 18:45:48 +00:00
try:
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:
os.remove(stopfile)
except:
pass
2019-06-11 18:45:48 +00:00
def daemon():
if os.path.exists(stopfile):
try:
os.remove(stopfile)
except:
2018-10-16 12:48:25 +00:00
print 'Unable to delete stop file.'
else:
2018-10-16 12:48:25 +00:00
print 'Bazarr exited.'
os._exit(0)
2019-06-11 18:45:48 +00:00
if os.path.exists(restartfile):
try:
os.remove(restartfile)
except:
2018-10-16 12:48:25 +00:00
print 'Unable to delete restart file.'
else:
start_bazarr()
2019-06-11 18:45:48 +00:00
start_bazarr()
2019-06-11 18:45:48 +00:00
# Keep the script running forever.
while True:
2019-05-31 23:00:32 +00:00
daemon()
time.sleep(1)