diff --git a/bazarr.py b/bazarr.py index 405158a2b..5411e6585 100644 --- a/bazarr.py +++ b/bazarr.py @@ -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 ' - 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 ' - 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..." diff --git a/bazarr/__init__.py b/bazarr/__init__.py new file mode 100644 index 000000000..9bad5790a --- /dev/null +++ b/bazarr/__init__.py @@ -0,0 +1 @@ +# coding=utf-8 diff --git a/bazarr/get_argv.py b/bazarr/get_argv.py index 5a2b27587..4b24615f2 100644 --- a/bazarr/get_argv.py +++ b/bazarr/get_argv.py @@ -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 ' 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 ' sys.exit() - elif opt in ("--no-update"): + elif opt in "--no-update": no_update = True - elif opt in ("--config"): - config_dir = arg \ No newline at end of file + elif opt in "--config": + config_dir = arg + elif opt in "--debug": + console_debug = True diff --git a/bazarr/main.py b/bazarr/main.py index ed698df59..5d4b6a927 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -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':