mirror of
https://github.com/morpheus65535/bazarr
synced 2025-01-03 05:25:28 +00:00
make bazarr a module; use centralized getopt in daemon; add --debug option for console handler; add logging dependencies
This commit is contained in:
parent
d8c6570b49
commit
6cc97a17cd
4 changed files with 37 additions and 32 deletions
27
bazarr.py
27
bazarr.py
|
@ -3,35 +3,14 @@ import threading
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
import sys
|
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__)
|
dir_name = os.path.dirname(__file__)
|
||||||
|
|
||||||
|
|
||||||
def start_bazarr():
|
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)
|
ep = sp.Popen(script, stdout=sp.PIPE, stderr=sp.STDOUT, stdin=sp.PIPE)
|
||||||
print "Bazarr starting..."
|
print "Bazarr starting..."
|
||||||
|
|
1
bazarr/__init__.py
Normal file
1
bazarr/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
# coding=utf-8
|
|
@ -4,17 +4,26 @@ import getopt
|
||||||
|
|
||||||
config_dir = os.path.join(os.path.dirname(__file__), '../data/')
|
config_dir = os.path.join(os.path.dirname(__file__), '../data/')
|
||||||
no_update = False
|
no_update = False
|
||||||
|
console_debug = False
|
||||||
|
arguments = []
|
||||||
|
|
||||||
|
|
||||||
try:
|
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:
|
except getopt.GetoptError:
|
||||||
print 'bazarr.py -h --no-update --config <config_directory>'
|
print 'bazarr.py -h --no-update --config <config_directory>'
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
for opt, arg in opts:
|
for opt, arg in opts:
|
||||||
|
arguments.append(opt)
|
||||||
|
if arg != '':
|
||||||
|
arguments.append(arg)
|
||||||
if opt == '-h':
|
if opt == '-h':
|
||||||
print 'bazarr.py -h --no-update --config <config_directory>'
|
print 'bazarr.py -h --no-update --config <config_directory>'
|
||||||
sys.exit()
|
sys.exit()
|
||||||
elif opt in ("--no-update"):
|
elif opt in "--no-update":
|
||||||
no_update = True
|
no_update = True
|
||||||
elif opt in ("--config"):
|
elif opt in "--config":
|
||||||
config_dir = arg
|
config_dir = arg
|
||||||
|
elif opt in "--debug":
|
||||||
|
console_debug = True
|
||||||
|
|
|
@ -3,7 +3,7 @@ bazarr_version = '0.6.7'
|
||||||
import gc
|
import gc
|
||||||
gc.enable()
|
gc.enable()
|
||||||
|
|
||||||
from get_argv import config_dir, no_update
|
from get_argv import config_dir, no_update, console_debug
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -29,6 +29,7 @@ log_level = get_general_settings()[4]
|
||||||
if log_level is None:
|
if log_level is None:
|
||||||
log_level = "INFO"
|
log_level = "INFO"
|
||||||
|
|
||||||
|
|
||||||
class OneLineExceptionFormatter(logging.Formatter):
|
class OneLineExceptionFormatter(logging.Formatter):
|
||||||
def formatException(self, exc_info):
|
def formatException(self, exc_info):
|
||||||
"""
|
"""
|
||||||
|
@ -43,8 +44,8 @@ class OneLineExceptionFormatter(logging.Formatter):
|
||||||
s = s.replace('\n', '') + '|'
|
s = s.replace('\n', '') + '|'
|
||||||
return s
|
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)
|
fh = TimedRotatingFileHandler(os.path.join(config_dir, 'log/bazarr.log'), when="midnight", interval=1, backupCount=7)
|
||||||
f = OneLineExceptionFormatter('%(asctime)s|%(levelname)s|%(message)s|',
|
f = OneLineExceptionFormatter('%(asctime)s|%(levelname)s|%(message)s|',
|
||||||
'%d/%m/%Y %H:%M:%S')
|
'%d/%m/%Y %H:%M:%S')
|
||||||
|
@ -52,14 +53,29 @@ def configure_logging():
|
||||||
logging.getLogger("enzyme").setLevel(logging.CRITICAL)
|
logging.getLogger("enzyme").setLevel(logging.CRITICAL)
|
||||||
logging.getLogger("apscheduler").setLevel(logging.WARNING)
|
logging.getLogger("apscheduler").setLevel(logging.WARNING)
|
||||||
logging.getLogger("subliminal").setLevel(logging.CRITICAL)
|
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("guessit").setLevel(logging.WARNING)
|
||||||
logging.getLogger("rebulk").setLevel(logging.WARNING)
|
logging.getLogger("rebulk").setLevel(logging.WARNING)
|
||||||
|
logging.getLogger("urllib3").setLevel(logging.WARNING)
|
||||||
logging.getLogger("stevedore.extension").setLevel(logging.CRITICAL)
|
logging.getLogger("stevedore.extension").setLevel(logging.CRITICAL)
|
||||||
root = logging.getLogger()
|
root = logging.getLogger()
|
||||||
root.setLevel(log_level)
|
root.setLevel(log_level)
|
||||||
root.addHandler(fh)
|
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
|
import requests
|
||||||
if get_proxy_settings()[0] != 'None':
|
if get_proxy_settings()[0] != 'None':
|
||||||
|
|
Loading…
Reference in a new issue