mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-21 13:53:15 -07:00
Use format()
instead of %
for string formatting
This commit is contained in:
parent
94e8a45c62
commit
1cd073cd52
21 changed files with 317 additions and 287 deletions
|
@ -52,42 +52,49 @@ def autoFork(section, inputCategory):
|
|||
|
||||
detected = False
|
||||
if section == "NzbDrone":
|
||||
logger.info("Attempting to verify %s fork" % inputCategory)
|
||||
url = "%s%s:%s%s/api/rootfolder" % (protocol, host, port, web_root)
|
||||
logger.info("Attempting to verify {category} fork".format
|
||||
(category=inputCategory))
|
||||
url = "{protocol}{host}:{port}{root}/api/rootfolder".format(
|
||||
protocol=protocol, host=host, port=port, root=web_root)
|
||||
headers = {"X-Api-Key": apikey}
|
||||
try:
|
||||
r = requests.get(url, headers=headers, stream=True, verify=False)
|
||||
except requests.ConnectionError:
|
||||
logger.warning("Could not connect to %s:%s to verify fork!" % (section, inputCategory))
|
||||
logger.warning("Could not connect to {0}:{1} to verify fork!".format(section, inputCategory))
|
||||
|
||||
if not r.ok:
|
||||
logger.warning("Connection to %s:%s failed! Check your configuration" % (section, inputCategory))
|
||||
logger.warning("Connection to {section}:{category} failed! "
|
||||
"Check your configuration".format
|
||||
(section=section, category=inputCategory))
|
||||
|
||||
fork = ['default', {}]
|
||||
|
||||
elif fork == "auto":
|
||||
params = core.ALL_FORKS
|
||||
rem_params = []
|
||||
logger.info("Attempting to auto-detect %s fork" % inputCategory)
|
||||
logger.info("Attempting to auto-detect {category} fork".format(category=inputCategory))
|
||||
# define the order to test. Default must be first since the default fork doesn't reject parameters.
|
||||
# then in order of most unique parameters.
|
||||
url = "%s%s:%s%s/home/postprocess/" % (protocol, host, port, web_root)
|
||||
url = "{protocol}{host}:{port}{root}/home/postprocess/".format(
|
||||
protocol=protocol, host=host, port=port, root=web_root)
|
||||
# attempting to auto-detect fork
|
||||
try:
|
||||
if username and password:
|
||||
s = requests.Session()
|
||||
login = "%s%s:%s%s/login" % (protocol, host, port, web_root)
|
||||
login = "{protocol}{host}:{port}{root}/login".format(
|
||||
protocol=protocol, host=host, port=port, root=web_root)
|
||||
login_params = {'username': username, 'password': password}
|
||||
s.post(login, data=login_params, stream=True, verify=False)
|
||||
r = s.get(url, auth=(username, password), verify=False)
|
||||
else:
|
||||
r = requests.get(url, verify=False)
|
||||
except requests.ConnectionError:
|
||||
logger.info("Could not connect to %s:%s to perform auto-fork detection!" % (section, inputCategory))
|
||||
logger.info("Could not connect to {section}:{category} to perform auto-fork detection!".format
|
||||
(section=section, category=inputCategory))
|
||||
r = []
|
||||
if r and r.ok:
|
||||
for param in params:
|
||||
if not 'name="%s"' % (param) in r.text:
|
||||
if not 'name={param!r}'.format(param=param) in r.text:
|
||||
rem_params.append(param)
|
||||
for param in rem_params:
|
||||
params.pop(param)
|
||||
|
@ -96,13 +103,17 @@ def autoFork(section, inputCategory):
|
|||
detected = True
|
||||
break
|
||||
if detected:
|
||||
logger.info("%s:%s fork auto-detection successful ..." % (section, inputCategory))
|
||||
logger.info("{section}:{category} fork auto-detection successful ...".format
|
||||
(section=section, category=inputCategory))
|
||||
elif rem_params:
|
||||
logger.info("%s:%s fork auto-detection found custom params %s" % (section, inputCategory, params))
|
||||
logger.info("{section}:{category} fork auto-detection found custom params {params}".format
|
||||
(section=section, category=inputCategory, params=params))
|
||||
fork = ['custom', params]
|
||||
else:
|
||||
logger.info("%s:%s fork auto-detection failed" % (section, inputCategory))
|
||||
logger.info("{section}:{category} fork auto-detection failed".format
|
||||
(section=section, category=inputCategory))
|
||||
fork = core.FORKS.items()[core.FORKS.keys().index(core.FORK_DEFAULT)]
|
||||
|
||||
logger.info("%s:%s fork set to %s" % (section, inputCategory, fork[0]))
|
||||
logger.info("{section}:{category} fork set to {fork}".format
|
||||
(section=section, category=inputCategory, fork=fork[0]))
|
||||
return fork[0], fork[1]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue