mirror of
https://github.com/morpheus65535/bazarr
synced 2024-12-28 10:38:26 +00:00
WIP
This commit is contained in:
parent
1cb0799d23
commit
cdf614192e
1 changed files with 53 additions and 66 deletions
119
bazarr/main.py
119
bazarr/main.py
|
@ -464,83 +464,70 @@ def test_notification(protocol, provider):
|
||||||
return '', 200
|
return '', 200
|
||||||
|
|
||||||
|
|
||||||
class Server(object):
|
class Server:
|
||||||
class __Server:
|
def __init__(self):
|
||||||
def __init__(self):
|
# Mute DeprecationWarning
|
||||||
# Mute DeprecationWarning
|
warnings.simplefilter("ignore", DeprecationWarning)
|
||||||
warnings.simplefilter("ignore", DeprecationWarning)
|
# Mute Insecure HTTPS requests made to Sonarr and Radarr
|
||||||
# Mute Insecure HTTPS requests made to Sonarr and Radarr
|
warnings.filterwarnings('ignore', message='Unverified HTTPS request')
|
||||||
warnings.filterwarnings('ignore', message='Unverified HTTPS request')
|
# Mute Python3 BrokenPipeError
|
||||||
# Mute Python3 BrokenPipeError
|
warnings.simplefilter("ignore", BrokenPipeError)
|
||||||
warnings.simplefilter("ignore", BrokenPipeError)
|
|
||||||
|
|
||||||
if args.dev:
|
if args.dev:
|
||||||
self.server = app.run(host=str(settings.general.ip),
|
self.server = app.run(host=str(settings.general.ip),
|
||||||
port=(int(args.port) if args.port else int(settings.general.port)))
|
port=(int(args.port) if args.port else int(settings.general.port)))
|
||||||
else:
|
else:
|
||||||
self.server = create_server(app,
|
self.server = create_server(app,
|
||||||
host=str(settings.general.ip),
|
host=str(settings.general.ip),
|
||||||
port=int(args.port) if args.port else int(settings.general.port),
|
port=int(args.port) if args.port else int(settings.general.port),
|
||||||
threads=24)
|
threads=24)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
try:
|
||||||
|
logging.info(
|
||||||
|
'BAZARR is started and waiting for request on http://' + str(settings.general.ip) + ':' + (str(
|
||||||
|
args.port) if args.port else str(settings.general.port)) + str(base_url))
|
||||||
|
if not args.dev:
|
||||||
|
self.server.run()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
self.shutdown()
|
||||||
|
|
||||||
|
def shutdown(self):
|
||||||
|
try:
|
||||||
|
self.server.close()
|
||||||
|
except Exception as e:
|
||||||
|
logging.error('BAZARR Cannot stop Waitress: ' + repr(e))
|
||||||
|
else:
|
||||||
|
database.close()
|
||||||
try:
|
try:
|
||||||
logging.info(
|
stop_file = io.open(os.path.join(args.config_dir, "bazarr.stop"), "w", encoding='UTF-8')
|
||||||
'BAZARR is started and waiting for request on http://' + str(settings.general.ip) + ':' + (str(
|
|
||||||
args.port) if args.port else str(settings.general.port)) + str(base_url))
|
|
||||||
if not args.dev:
|
|
||||||
self.server.run()
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
self.shutdown()
|
|
||||||
|
|
||||||
def shutdown(self):
|
|
||||||
try:
|
|
||||||
self.server.close()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error('BAZARR Cannot stop Waitress: ' + repr(e))
|
logging.error('BAZARR Cannot create bazarr.stop file: ' + repr(e))
|
||||||
else:
|
else:
|
||||||
database.close()
|
logging.info('Bazarr is being shutdown...')
|
||||||
try:
|
stop_file.write(str(''))
|
||||||
stop_file = io.open(os.path.join(args.config_dir, "bazarr.stop"), "w", encoding='UTF-8')
|
stop_file.close()
|
||||||
except Exception as e:
|
os._exit(0)
|
||||||
logging.error('BAZARR Cannot create bazarr.stop file: ' + repr(e))
|
|
||||||
else:
|
|
||||||
logging.info('Bazarr is being shutdown...')
|
|
||||||
stop_file.write(str(''))
|
|
||||||
stop_file.close()
|
|
||||||
os._exit(0)
|
|
||||||
|
|
||||||
def restart(self):
|
def restart(self):
|
||||||
|
try:
|
||||||
|
self.server.close()
|
||||||
|
except Exception as e:
|
||||||
|
logging.error('BAZARR Cannot stop Waitress: ' + repr(e))
|
||||||
|
else:
|
||||||
|
database.close()
|
||||||
try:
|
try:
|
||||||
self.server.close()
|
restart_file = io.open(os.path.join(args.config_dir, "bazarr.restart"), "w", encoding='UTF-8')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error('BAZARR Cannot stop Waitress: ' + repr(e))
|
logging.error('BAZARR Cannot create bazarr.restart file: ' + repr(e))
|
||||||
else:
|
else:
|
||||||
database.close()
|
logging.info('Bazarr is being restarted...')
|
||||||
try:
|
restart_file.write(str(''))
|
||||||
restart_file = io.open(os.path.join(args.config_dir, "bazarr.restart"), "w", encoding='UTF-8')
|
restart_file.close()
|
||||||
except Exception as e:
|
os._exit(0)
|
||||||
logging.error('BAZARR Cannot create bazarr.restart file: ' + repr(e))
|
|
||||||
else:
|
|
||||||
logging.info('Bazarr is being restarted...')
|
|
||||||
restart_file.write(str(''))
|
|
||||||
restart_file.close()
|
|
||||||
os._exit(0)
|
|
||||||
|
|
||||||
instance = None
|
|
||||||
|
|
||||||
def __new__(cls): # __new__ always a classmethod
|
|
||||||
if not Server.instance:
|
|
||||||
Server.instance = Server.__Server()
|
|
||||||
return Server.instance
|
|
||||||
|
|
||||||
def __getattr__(self, name):
|
|
||||||
return getattr(self.instance, name)
|
|
||||||
|
|
||||||
def __setattr__(self, name):
|
|
||||||
return setattr(self.instance, name)
|
|
||||||
|
|
||||||
|
|
||||||
|
global webserver
|
||||||
webserver = Server()
|
webserver = Server()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue