2018-10-03 10:53:22 +00:00
|
|
|
import subprocess as sp
|
|
|
|
import threading
|
|
|
|
import time
|
2018-09-12 02:32:09 +00:00
|
|
|
import os
|
2018-10-03 10:53:22 +00:00
|
|
|
import sys
|
|
|
|
import getopt
|
|
|
|
|
2018-10-17 01:15:42 +00:00
|
|
|
config_dir = os.path.join(os.path.dirname(__file__), 'data/')
|
|
|
|
no_update = False
|
|
|
|
|
2018-10-03 10:53:22 +00:00
|
|
|
arguments = []
|
|
|
|
try:
|
|
|
|
opts, args = getopt.getopt(sys.argv[1:],"h:",["no-update", "config="])
|
|
|
|
except getopt.GetoptError:
|
2018-10-04 18:16:49 +00:00
|
|
|
print 'bazarr.py -h --no-update --config <config_directory>'
|
2018-10-03 10:53:22 +00:00
|
|
|
sys.exit(2)
|
|
|
|
for opt, arg in opts:
|
|
|
|
arguments.append(opt)
|
2018-10-17 01:55:30 +00:00
|
|
|
if arg != '':
|
|
|
|
arguments.append(arg)
|
|
|
|
|
2018-10-17 01:15:42 +00:00
|
|
|
if opt == '-h':
|
|
|
|
print 'bazarr.py -h --no-update --config <config_directory>'
|
|
|
|
sys.exit()
|
|
|
|
elif opt in ("--no-update"):
|
|
|
|
no_update = True
|
|
|
|
elif opt in ("--config"):
|
|
|
|
config_dir = arg
|
2018-10-03 10:53:22 +00:00
|
|
|
|
|
|
|
|
2018-10-11 01:23:30 +00:00
|
|
|
dir_name = os.path.dirname(__file__)
|
|
|
|
|
2018-10-03 10:53:22 +00:00
|
|
|
def start_bazarr():
|
2018-10-16 14:58:25 +00:00
|
|
|
script = [sys.executable, "-u", os.path.normcase(os.path.join(globals()['dir_name'], 'bazarr/main.py'))] + globals()['arguments']
|
2018-10-03 10:53:22 +00:00
|
|
|
|
2018-10-14 13:32:16 +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..."
|
2018-10-14 13:32:16 +00:00
|
|
|
try:
|
|
|
|
for line in iter(ep.stdout.readline, ''):
|
|
|
|
sys.stdout.write(line)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
2018-10-04 18:16:49 +00:00
|
|
|
|
|
|
|
|
2018-10-03 10:53:22 +00:00
|
|
|
if __name__ == '__main__':
|
2018-10-17 01:15:42 +00:00
|
|
|
restartfile = os.path.normcase(os.path.join(config_dir, 'bazarr.restart'))
|
|
|
|
stopfile = os.path.normcase(os.path.join(config_dir, 'bazarr.stop'))
|
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
|
|
|
|
|
|
|
|
try:
|
2018-10-03 10:53:22 +00:00
|
|
|
os.remove(stopfile)
|
|
|
|
except:
|
2018-09-12 02:32:09 +00:00
|
|
|
pass
|
|
|
|
|
2018-10-03 10:53:22 +00:00
|
|
|
def daemon():
|
|
|
|
threading.Timer(1.0, daemon).start()
|
|
|
|
if os.path.exists(stopfile):
|
|
|
|
try:
|
|
|
|
os.remove(stopfile)
|
|
|
|
except:
|
2018-10-16 12:48:25 +00:00
|
|
|
print 'Unable to delete stop file.'
|
2018-10-03 10:53:22 +00:00
|
|
|
else:
|
2018-10-16 12:48:25 +00:00
|
|
|
print 'Bazarr exited.'
|
2018-10-03 10:53:22 +00:00
|
|
|
os._exit(0)
|
|
|
|
|
|
|
|
if os.path.exists(restartfile):
|
|
|
|
try:
|
|
|
|
os.remove(restartfile)
|
|
|
|
except:
|
2018-10-16 12:48:25 +00:00
|
|
|
print 'Unable to delete restart file.'
|
2018-10-03 10:53:22 +00:00
|
|
|
else:
|
|
|
|
start_bazarr()
|
2018-09-13 11:28:15 +00:00
|
|
|
|
|
|
|
|
2018-10-03 10:53:22 +00:00
|
|
|
daemon()
|
2018-09-13 03:25:12 +00:00
|
|
|
|
2018-10-03 10:53:22 +00:00
|
|
|
start_bazarr()
|
2018-09-13 03:25:12 +00:00
|
|
|
|
2018-10-11 01:23:30 +00:00
|
|
|
|
2018-10-03 10:53:22 +00:00
|
|
|
# Keep the script running forever.
|
|
|
|
while True:
|
|
|
|
time.sleep(0.001)
|