make bazarr a module; use centralized getopt in daemon; add --debug option for console handler; add logging dependencies

pull/292/head
panni 6 years ago
parent d8c6570b49
commit 6cc97a17cd

@ -3,35 +3,14 @@ import threading
import time
import os
import sys
import getopt
config_dir = os.path.join(os.path.dirname(__file__), 'data/')
no_update = False
arguments = []
try:
opts, args = getopt.getopt(sys.argv[1:],"h:",["no-update", "config="])
except getopt.GetoptError:
print 'bazarr.py -h --no-update --config <config_directory>'
sys.exit(2)
for opt, arg in opts:
arguments.append(opt)
if arg != '':
arguments.append(arg)
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
from bazarr.get_argv import config_dir, arguments
dir_name = os.path.dirname(__file__)
def start_bazarr():
script = [sys.executable, "-u", os.path.normcase(os.path.join(globals()['dir_name'], 'bazarr/main.py'))] + globals()['arguments']
script = [sys.executable, "-u", os.path.normcase(os.path.join(globals()['dir_name'], 'bazarr/main.py'))] + arguments
ep = sp.Popen(script, stdout=sp.PIPE, stderr=sp.STDOUT, stdin=sp.PIPE)
print "Bazarr starting..."

@ -0,0 +1 @@
# coding=utf-8

@ -4,17 +4,26 @@ import getopt
config_dir = os.path.join(os.path.dirname(__file__), '../data/')
no_update = False
console_debug = False
arguments = []
try:
opts, args = getopt.getopt(sys.argv[1:],"h:",["no-update", "config="])
opts, args = getopt.getopt(sys.argv[1:],"h:",["no-update", "config=", "debug"])
except getopt.GetoptError:
print 'bazarr.py -h --no-update --config <config_directory>'
sys.exit(2)
for opt, arg in opts:
arguments.append(opt)
if arg != '':
arguments.append(arg)
if opt == '-h':
print 'bazarr.py -h --no-update --config <config_directory>'
sys.exit()
elif opt in ("--no-update"):
elif opt in "--no-update":
no_update = True
elif opt in ("--config"):
config_dir = arg
elif opt in "--config":
config_dir = arg
elif opt in "--debug":
console_debug = True

@ -3,7 +3,7 @@ bazarr_version = '0.6.7'
import gc
gc.enable()
from get_argv import config_dir, no_update
from get_argv import config_dir, no_update, console_debug
import os
import sys
@ -29,6 +29,7 @@ log_level = get_general_settings()[4]
if log_level is None:
log_level = "INFO"
class OneLineExceptionFormatter(logging.Formatter):
def formatException(self, exc_info):
"""
@ -43,8 +44,8 @@ class OneLineExceptionFormatter(logging.Formatter):
s = s.replace('\n', '') + '|'
return s
def configure_logging():
global fh
def configure_logging(console_debug=False):
fh = TimedRotatingFileHandler(os.path.join(config_dir, 'log/bazarr.log'), when="midnight", interval=1, backupCount=7)
f = OneLineExceptionFormatter('%(asctime)s|%(levelname)s|%(message)s|',
'%d/%m/%Y %H:%M:%S')
@ -52,14 +53,29 @@ def configure_logging():
logging.getLogger("enzyme").setLevel(logging.CRITICAL)
logging.getLogger("apscheduler").setLevel(logging.WARNING)
logging.getLogger("subliminal").setLevel(logging.CRITICAL)
logging.getLogger("subliminal_patch").setLevel(logging.CRITICAL)
logging.getLogger("subzero").setLevel(logging.WARNING)
logging.getLogger("guessit").setLevel(logging.WARNING)
logging.getLogger("rebulk").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)
logging.getLogger("stevedore.extension").setLevel(logging.CRITICAL)
root = logging.getLogger()
root.setLevel(log_level)
root.addHandler(fh)
configure_logging()
if console_debug:
logging.getLogger("subliminal").setLevel(logging.DEBUG)
logging.getLogger("subliminal_patch").setLevel(logging.DEBUG)
logging.getLogger("subzero").setLevel(logging.DEBUG)
sh = logging.StreamHandler(sys.stdout)
cf = logging.Formatter('%(asctime)-15s - %(name)-32s (%(thread)x) : %(levelname)s (%(module)s:%(lineno)d) '
'- %(message)s')
sh.setFormatter(cf)
root.addHandler(sh)
configure_logging(console_debug=console_debug)
import requests
if get_proxy_settings()[0] != 'None':

Loading…
Cancel
Save