From 1cd073cd52bd2622c51c95fc0451f37a37b89173 Mon Sep 17 00:00:00 2001 From: Labrys Date: Tue, 31 May 2016 08:20:06 -0400 Subject: [PATCH] Use `format()` instead of `%` for string formatting --- TorrentToMedia.py | 64 +++++----- core/__init__.py | 18 +-- core/extractor/extractor.py | 35 ++++-- core/linktastic/linktastic.py | 10 +- core/logger.py | 4 +- core/nzbToMediaAutoFork.py | 37 +++--- core/nzbToMediaConfig.py | 21 ++-- core/nzbToMediaDB.py | 8 +- core/nzbToMediaSceneExceptions.py | 24 ++-- core/nzbToMediaUserScript.py | 28 ++--- core/nzbToMediaUtil.py | 173 ++++++++++++++-------------- core/synchronousdeluge/rencode.py | 2 +- core/transcoder/transcoder.py | 71 ++++++------ core/transmissionrpc/client.py | 15 +-- core/transmissionrpc/error.py | 8 +- core/transmissionrpc/httphandler.py | 4 +- core/transmissionrpc/session.py | 4 +- core/transmissionrpc/torrent.py | 8 +- core/transmissionrpc/utils.py | 18 ++- core/utorrent/upload.py | 8 +- nzbToMedia.py | 44 +++---- 21 files changed, 317 insertions(+), 287 deletions(-) diff --git a/TorrentToMedia.py b/TorrentToMedia.py index f82b9b10..b1a317ae 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -18,7 +18,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, uniquePath = 1 if clientAgent != 'manual' and not core.DOWNLOADINFO: - logger.debug('Adding TORRENT download info for directory %s to database' % (inputDirectory)) + logger.debug('Adding TORRENT download info for directory {0} to database'.format(inputDirectory)) myDB = nzbToMediaDB.DBConnection() @@ -42,7 +42,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, } myDB.upsert("downloads", newValueDict, controlValueDict) - logger.debug("Received Directory: %s | Name: %s | Category: %s" % (inputDirectory, inputName, inputCategory)) + logger.debug("Received Directory: {0} | Name: {1} | Category: {2}".format(inputDirectory, inputName, inputCategory)) inputDirectory, inputName, inputCategory, root = core.category_search(inputDirectory, inputName, inputCategory, root, @@ -58,7 +58,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, inputDirectory = inputDirectory.encode(core.SYS_ENCODING) except: pass - logger.debug("Determined Directory: %s | Name: %s | Category: %s" % (inputDirectory, inputName, inputCategory)) + logger.debug("Determined Directory: {0} | Name: {1} | Category: {2}".format(inputDirectory, inputName, inputCategory)) # auto-detect section section = core.CFG.findsection(inputCategory).isenabled() @@ -66,7 +66,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, section = core.CFG.findsection("ALL").isenabled() if section is None: logger.error( - 'Category:[%s] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.' % ( + 'Category:[{0}] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.'.format( inputCategory)) return [-1, ""] else: @@ -74,15 +74,15 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, if len(section) > 1: logger.error( - 'Category:[%s] is not unique, %s are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.' % ( + 'Category:[{0}] is not unique, {1} are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.'.format( usercat, section.keys())) return [-1, ""] if section: sectionName = section.keys()[0] - logger.info('Auto-detected SECTION:%s' % (sectionName)) + logger.info('Auto-detected SECTION:{0}'.format(sectionName)) else: - logger.error("Unable to locate a section with subsection:%s enabled in your autoProcessMedia.cfg, exiting!" % ( + logger.error("Unable to locate a section with subsection:{0} enabled in your autoProcessMedia.cfg, exiting!".format( inputCategory)) return [-1, ""] @@ -129,15 +129,15 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, if outputDestination in inputDirectory: outputDestination = inputDirectory - logger.info("Output directory set to: %s" % (outputDestination)) + logger.info("Output directory set to: {0}".format(outputDestination)) if core.SAFE_MODE and outputDestination == core.TORRENT_DEFAULTDIR: logger.error( - 'The output directory:[%s] is the Download Directory. Edit outputDirectory in autoProcessMedia.cfg. Exiting' % ( + 'The output directory:[{0}] is the Download Directory. Edit outputDirectory in autoProcessMedia.cfg. Exiting'.format( inputDirectory)) return [-1, ""] - logger.debug("Scanning files in directory: %s" % (inputDirectory)) + logger.debug("Scanning files in directory: {0}".format(inputDirectory)) if sectionName == 'HeadPhones': core.NOFLATTEN.extend( @@ -149,7 +149,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, inputFiles = core.listMediaFiles(inputDirectory, archives=False) else: inputFiles = core.listMediaFiles(inputDirectory) - logger.debug("Found %s files in %s" % (str(len(inputFiles)), inputDirectory)) + logger.debug("Found {0} files in {1}".format(len(inputFiles), inputDirectory)) for inputFile in inputFiles: filePath = os.path.dirname(inputFile) fileName, fileExt = os.path.splitext(os.path.basename(inputFile)) @@ -161,17 +161,17 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, targetFile = core.os.path.join( core.os.path.join(outputDestination, os.path.basename(filePath)), fullFileName) logger.debug( - "Setting outputDestination to %s to preserve folder structure" % (os.path.dirname(targetFile))) + "Setting outputDestination to {0} to preserve folder structure".format(os.path.dirname(targetFile))) try: targetFile = targetFile.encode(core.SYS_ENCODING) except: pass if root == 1: if not foundFile: - logger.debug("Looking for %s in: %s" % (inputName, inputFile)) + logger.debug("Looking for {0} in: {1}".format(inputName, inputFile)) if (core.sanitizeName(inputName) in core.sanitizeName(inputFile)) or ( core.sanitizeName(fileName) in core.sanitizeName(inputName)): foundFile = True - logger.debug("Found file %s that matches Torrent Name %s" % (fullFileName, inputName)) + logger.debug("Found file {0} that matches Torrent Name {1}".format(fullFileName, inputName)) else: continue @@ -183,7 +183,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, logger.debug("Looking for files with modified/created dates less than 5 minutes old.") if (mtime_lapse < datetime.timedelta(minutes=5)) or (ctime_lapse < datetime.timedelta(minutes=5)): foundFile = True - logger.debug("Found file %s with date modifed/created less than 5 minutes ago." % (fullFileName)) + logger.debug("Found file {0} with date modifed/created less than 5 minutes ago.".format(fullFileName)) else: continue # This file has not been recently moved or created, skip it @@ -192,12 +192,12 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, core.copy_link(inputFile, targetFile, core.USELINK) core.rmReadOnly(targetFile) except: - logger.error("Failed to link: %s to %s" % (inputFile, targetFile)) + logger.error("Failed to link: {0} to {1}".format(inputFile, targetFile)) inputName, outputDestination = convert_to_ascii(inputName, outputDestination) if extract == 1: - logger.debug('Checking for archives to extract in directory: %s' % (inputDirectory)) + logger.debug('Checking for archives to extract in directory: {0}'.format(inputDirectory)) core.extractFiles(inputDirectory, outputDestination, keep_archive) if not inputCategory in core.NOFLATTEN: #don't flatten hp in case multi cd albums, and we need to copy this back later. @@ -208,19 +208,19 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, numVideos = len( core.listMediaFiles(outputDestination, media=True, audio=False, meta=False, archives=False)) if numVideos > 0: - logger.info("Found %s media files in %s" % (numVideos, outputDestination)) + logger.info("Found {0} media files in {1}".format(numVideos, outputDestination)) status = 0 elif extract != 1: - logger.info("Found no media files in %s. Sending to %s to process" % (outputDestination, sectionName)) + logger.info("Found no media files in {0}. Sending to {1} to process".format(outputDestination, sectionName)) status = 0 else: - logger.warning("Found no media files in %s" % outputDestination) + logger.warning("Found no media files in {0}".format(outputDestination)) # Only these sections can handling failed downloads so make sure everything else gets through without the check for failed if not sectionName in ['CouchPotato', 'SickBeard', 'NzbDrone']: status = 0 - logger.info("Calling %s:%s to post-process:%s" % (sectionName, usercat, inputName)) + logger.info("Calling {0}:{1} to post-process:{2}".format(sectionName, usercat, inputName)) if core.TORRENT_CHMOD_DIRECTORY: core.rchmod(outputDestination, core.TORRENT_CHMOD_DIRECTORY) @@ -262,10 +262,10 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, # remove torrent if core.USELINK == 'move-sym' and not core.DELETE_ORIGINAL == 1: - logger.debug('Checking for sym-links to re-direct in: %s' % (inputDirectory)) + logger.debug('Checking for sym-links to re-direct in: {0}'.format(inputDirectory)) for dirpath, dirs, files in os.walk(inputDirectory): for file in files: - logger.debug('Checking symlink: %s' % (os.path.join(dirpath,file))) + logger.debug('Checking symlink: {0}'.format(os.path.join(dirpath,file))) core.replace_links(os.path.join(dirpath,file)) core.remove_torrent(clientAgent, inputHash, inputID, inputName) @@ -284,11 +284,11 @@ def main(args): clientAgent = core.TORRENT_CLIENTAGENT logger.info("#########################################################") - logger.info("## ..::[%s]::.. ##" % os.path.basename(__file__)) + logger.info("## ..::[{0}]::.. ##".format(os.path.basename(__file__))) logger.info("#########################################################") # debug command line options - logger.debug("Options passed into TorrentToMedia: %s" % (args)) + logger.debug("Options passed into TorrentToMedia: {0}".format(args)) # Post-Processing Result result = [ 0, "" ] @@ -310,16 +310,16 @@ def main(args): if not core.CFG[section][subsection].isenabled(): continue for dirName in core.getDirs(section, subsection, link='hard'): - logger.info("Starting manual run for %s:%s - Folder:%s" % (section, subsection, dirName)) + logger.info("Starting manual run for {0}:{1} - Folder:{2}".format(section, subsection, dirName)) - logger.info("Checking database for download info for %s ..." % (os.path.basename(dirName))) + logger.info("Checking database for download info for {0} ...".format(os.path.basename(dirName))) core.DOWNLOADINFO = core.get_downloadInfo(os.path.basename(dirName), 0) if core.DOWNLOADINFO: logger.info( - "Found download info for %s, setting variables now ..." % (os.path.basename(dirName))) + "Found download info for {0}, setting variables now ...".format(os.path.basename(dirName))) else: logger.info( - 'Unable to locate download info for %s, continuing to try and process this release ...' % ( + 'Unable to locate download info for {0}, continuing to try and process this release ...'.format( os.path.basename(dirName)) ) @@ -350,14 +350,14 @@ def main(args): results = processTorrent(dirName, inputName, subsection, inputHash, inputID, clientAgent) if results[0] != 0: - logger.error("A problem was reported when trying to perform a manual run for %s:%s." % ( + logger.error("A problem was reported when trying to perform a manual run for {0}:{1}.".format( section, subsection)) result = results if result[0] == 0: - logger.info("The %s script completed successfully." % (args[0])) + logger.info("The {0} script completed successfully.".format(args[0])) else: - logger.error("A problem was reported in the %s script." % (args[0])) + logger.error("A problem was reported in the {0} script.".format(args[0])) del core.MYAPP return result[0] diff --git a/core/__init__.py b/core/__init__.py index 6b3ca265..b71a3b53 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -276,7 +276,7 @@ def initialize(section=None): # run migrate to convert old cfg to new style cfg plus fix any cfg missing values/options. if not config.migrate(): - logger.error("Unable to migrate config file %s, exiting ..." % (CONFIG_FILE)) + logger.error("Unable to migrate config file {0}, exiting ...".format(CONFIG_FILE)) if 'NZBOP_SCRIPTDIR' in os.environ: pass # We will try and read config from Environment. else: @@ -287,7 +287,7 @@ def initialize(section=None): CFG = config.addnzbget() else: # load newly migrated config - logger.info("Loading config from [%s]" % (CONFIG_FILE)) + logger.info("Loading config from [{0}]".format(CONFIG_FILE)) CFG = config() # Enable/Disable DEBUG Logging @@ -298,7 +298,7 @@ def initialize(section=None): if LOG_ENV: for item in os.environ: - logger.info("%s: %s" % (item, os.environ[item]), "ENVIRONMENT") + logger.info("{0}: {1}".format(item, os.environ[item]), "ENVIRONMENT") # initialize the main SB database nzbToMediaDB.upgradeDatabase(nzbToMediaDB.DBConnection(), mainDB.InitialSchema) @@ -399,20 +399,20 @@ def initialize(section=None): devnull = open(os.devnull, 'w') try: subprocess.Popen(["nice"], stdout=devnull, stderr=devnull).communicate() - NICENESS.extend(['nice', '-n%s' % (int(CFG["Posix"]["niceness"]))]) + NICENESS.extend(['nice', '-n{0}'.format(int(CFG["Posix"]["niceness"]))]) except: pass try: subprocess.Popen(["ionice"], stdout=devnull, stderr=devnull).communicate() try: - NICENESS.extend(['ionice', '-c%s' % (int(CFG["Posix"]["ionice_class"]))]) + NICENESS.extend(['ionice', '-c{0}'.format(int(CFG["Posix"]["ionice_class"]))]) except: pass try: if 'ionice' in NICENESS: - NICENESS.extend(['-n%s' % (int(CFG["Posix"]["ionice_classdata"]))]) + NICENESS.extend(['-n{0}'.format(int(CFG["Posix"]["ionice_classdata"]))]) else: - NICENESS.extend(['ionice', '-n%s' % (int(CFG["Posix"]["ionice_classdata"]))]) + NICENESS.extend(['ionice', '-n{0}'.format(int(CFG["Posix"]["ionice_classdata"]))]) except: pass except: @@ -422,7 +422,7 @@ def initialize(section=None): COMPRESSEDCONTAINER = [re.compile('.r\d{2}$', re.I), re.compile('.part\d+.rar$', re.I), re.compile('.rar$', re.I)] - COMPRESSEDCONTAINER += [re.compile('%s$' % ext, re.I) for ext in CFG["Extensions"]["compressedExtensions"]] + COMPRESSEDCONTAINER += [re.compile('{0}$'.format(ext), re.I) for ext in CFG["Extensions"]["compressedExtensions"]] MEDIACONTAINER = CFG["Extensions"]["mediaExtensions"] AUDIOCONTAINER = CFG["Extensions"]["audioExtensions"] METACONTAINER = CFG["Extensions"]["metaExtensions"] # .nfo,.sub,.srt @@ -851,7 +851,7 @@ def restart(): def rchmod(path, mod): - logger.log("Changing file mode of %s to %s" % (path, oct(mod))) + logger.log("Changing file mode of {0} to {1}".format(path, oct(mod))) os.chmod(path, mod) if not os.path.isdir(path): return # Skip files diff --git a/core/extractor/extractor.py b/core/extractor/extractor.py index 865802ba..08011706 100644 --- a/core/extractor/extractor.py +++ b/core/extractor/extractor.py @@ -1,4 +1,5 @@ # coding=utf-8 + import os import platform import shutil @@ -53,7 +54,9 @@ def extract(filePath, outputDestination): else: for k, v in EXTRACT_COMMANDS.items(): if cmd in v[0]: - core.logger.error("EXTRACTOR: %s not found, disabling support for %s" % (cmd, k)) + core.logger.error("EXTRACTOR: {cmd} not found, " + "disabling support for {feature}".format + (cmd=cmd, feature=k)) del EXTRACT_COMMANDS[k] devnull.close() else: @@ -76,10 +79,11 @@ def extract(filePath, outputDestination): if ext[1] in EXTRACT_COMMANDS: cmd = EXTRACT_COMMANDS[ext[1]] else: - core.logger.debug("EXTRACTOR: Unknown file type: %s" % ext[1]) + core.logger.debug("EXTRACTOR: Unknown file type: {ext}".format + (ext=ext[1])) return False - # Create outputDestination folder + # Create outputDestination folder core.makeDir(outputDestination) if core.PASSWORDSFILE != "" and os.path.isfile(os.path.normpath(core.PASSWORDSFILE)): @@ -87,8 +91,10 @@ def extract(filePath, outputDestination): else: passwords = [] - core.logger.info("Extracting %s to %s" % (filePath, outputDestination)) - core.logger.debug("Extracting %s %s %s" % (cmd, filePath, outputDestination)) + core.logger.info("Extracting {file} to {destination}".format + (file=filePath, destination=outputDestination)) + core.logger.debug("Extracting {cmd} {file} {destination}".format + (cmd=cmd, file=filePath, destination=outputDestination)) origFiles = [] origDirs = [] @@ -114,9 +120,9 @@ def extract(filePath, outputDestination): cmd2.append("-p-") # don't prompt for password. p = Popen(cmd2, stdout=devnull, stderr=devnull, startupinfo=info) # should extract files fine. res = p.wait() - if ( - res >= 0 and os.name == 'nt') or res == 0: # for windows chp returns process id if successful or -1*Error code. Linux returns 0 for successful. - core.logger.info("EXTRACTOR: Extraction was successful for %s to %s" % (filePath, outputDestination)) + if (res >= 0 and os.name == 'nt') or res == 0: # for windows chp returns process id if successful or -1*Error code. Linux returns 0 for successful. + core.logger.info("EXTRACTOR: Extraction was successful for {file} to {destination}".format + (file=filePath, destination=outputDestination)) success = 1 elif len(passwords) > 0: core.logger.info("EXTRACTOR: Attempting to extract with passwords") @@ -130,14 +136,17 @@ def extract(filePath, outputDestination): p = Popen(cmd2, stdout=devnull, stderr=devnull, startupinfo=info) # should extract files fine. res = p.wait() if (res >= 0 and platform == 'Windows') or res == 0: - core.logger.info("EXTRACTOR: Extraction was successful for %s to %s using password: %s" % ( - filePath, outputDestination, password)) + core.logger.info("EXTRACTOR: Extraction was successful " + "for {file} to {destination} using password: {pwd}".format + (file=filePath, destination=outputDestination, pwd=password)) success = 1 break else: continue except: - core.logger.error("EXTRACTOR: Extraction failed for %s. Could not call command %s" % (filePath, cmd)) + core.logger.error("EXTRACTOR: Extraction failed for {file}. " + "Could not call command {cmd}".format + (file=filePath, cmd=cmd)) os.chdir(pwd) return False @@ -162,5 +171,7 @@ def extract(filePath, outputDestination): pass return True else: - core.logger.error("EXTRACTOR: Extraction failed for %s. Result was %s" % (filePath, res)) + core.logger.error("EXTRACTOR: Extraction failed for {file}. " + "Result was {result}".format + (file=filePath, result=res)) return False diff --git a/core/linktastic/linktastic.py b/core/linktastic/linktastic.py index af690158..95d2f8c6 100644 --- a/core/linktastic/linktastic.py +++ b/core/linktastic/linktastic.py @@ -33,14 +33,14 @@ if os.name == 'nt': # Prevent spaces from messing with us! def _escape_param(param): - return '"%s"' % param + return '"{0}"'.format(param) # Private function to create link on nt-based systems def _link_windows(src, dest): try: subprocess.check_output( - 'cmd /C mklink /H %s %s' % (_escape_param(dest), _escape_param(src)), + 'cmd /C mklink /H {0} {1}'.format(_escape_param(dest), _escape_param(src)), stderr=subprocess.STDOUT, startupinfo=info) except CalledProcessError as err: @@ -54,7 +54,7 @@ def _link_windows(src, dest): def _symlink_windows(src, dest): try: subprocess.check_output( - 'cmd /C mklink %s %s' % (_escape_param(dest), _escape_param(src)), + 'cmd /C mklink {0} {1}'.format(_escape_param(dest), _escape_param(src)), stderr=subprocess.STDOUT, startupinfo=info) except CalledProcessError as err: raise IOError(err.output.decode('utf-8')) @@ -67,7 +67,7 @@ def _symlink_windows(src, dest): def _dirlink_windows(src, dest): try: subprocess.check_output( - 'cmd /C mklink /J %s %s' % (_escape_param(dest), _escape_param(src)), + 'cmd /C mklink /J {0} {1}'.format(_escape_param(dest), _escape_param(src)), stderr=subprocess.STDOUT, startupinfo=info) except CalledProcessError as err: raise IOError(err.output.decode('utf-8')) @@ -80,7 +80,7 @@ def _dirlink_windows(src, dest): def _junctionlink_windows(src, dest): try: subprocess.check_output( - 'cmd /C mklink /D %s %s' % (_escape_param(dest), _escape_param(src)), + 'cmd /C mklink /D {0} {1}'.format(_escape_param(dest), _escape_param(src)), stderr=subprocess.STDOUT, startupinfo=info) except CalledProcessError as err: raise IOError(err.output.decode('utf-8')) diff --git a/core/logger.py b/core/logger.py index 86772c15..94d1764f 100644 --- a/core/logger.py +++ b/core/logger.py @@ -193,9 +193,9 @@ class NTMRotatingLogHandler(object): self.writes_since_check += 1 try: - message = u"%s: %s" % (str(section).upper(), toLog) + message = u"{0}: {1}".format(str(section).upper(), toLog) except: - message = u"%s: Message contains non-utf-8 string" % (str(section).upper()) + message = u"{0}: Message contains non-utf-8 string".format(str(section).upper()) out_line = message diff --git a/core/nzbToMediaAutoFork.py b/core/nzbToMediaAutoFork.py index ce1949c5..76a11204 100644 --- a/core/nzbToMediaAutoFork.py +++ b/core/nzbToMediaAutoFork.py @@ -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] diff --git a/core/nzbToMediaConfig.py b/core/nzbToMediaConfig.py index badc597f..00aed989 100644 --- a/core/nzbToMediaConfig.py +++ b/core/nzbToMediaConfig.py @@ -118,16 +118,16 @@ class ConfigObj(configobj.ConfigObj, Section): if not os.path.isfile(core.CONFIG_FILE): shutil.copyfile(core.CONFIG_SPEC_FILE, core.CONFIG_FILE) CFG_OLD = config(core.CONFIG_FILE) - except Exception as e: - logger.debug("Error %s when copying to .cfg" % (e)) + except Exception as error: + logger.debug("Error {msg} when copying to .cfg".format(msg=error)) try: # check for autoProcessMedia.cfg.spec and create if it does not exist if not os.path.isfile(core.CONFIG_SPEC_FILE): shutil.copyfile(core.CONFIG_FILE, core.CONFIG_SPEC_FILE) CFG_NEW = config(core.CONFIG_SPEC_FILE) - except Exception as e: - logger.debug("Error %s when copying to .spec" % (e)) + except Exception as error: + logger.debug("Error {msg} when copying to .spec".format(msg=error)) # check for autoProcessMedia.cfg and autoProcessMedia.cfg.spec and if they don't exist return and fail if CFG_NEW is None or CFG_OLD is None: @@ -255,8 +255,9 @@ class ConfigObj(configobj.ConfigObj, Section): try: if 'NZBPO_NDCATEGORY' in os.environ and 'NZBPO_SBCATEGORY' in os.environ: if os.environ['NZBPO_NDCATEGORY'] == os.environ['NZBPO_SBCATEGORY']: - logger.warning("%s category is set for SickBeard and NzbDrone. " - "Please check your config in NZBGet" % (os.environ['NZBPO_NDCATEGORY'])) + logger.warning("{x} category is set for SickBeard and NzbDrone. " + "Please check your config in NZBGet".format + (x=os.environ['NZBPO_NDCATEGORY'])) section = "Nzb" key = 'NZBOP_DESTDIR' @@ -462,15 +463,15 @@ class ConfigObj(configobj.ConfigObj, Section): CFG_NEW[section][os.environ[envCatKey]][option] = value CFG_NEW[section][os.environ[envCatKey]]['enabled'] = 1 - except Exception as e: - logger.debug("Error %s when applying NZBGet config" % (e)) + except Exception as error: + logger.debug("Error {msg} when applying NZBGet config".format(msg=error)) try: # write our new config to autoProcessMedia.cfg CFG_NEW.filename = core.CONFIG_FILE CFG_NEW.write() - except Exception as e: - logger.debug("Error %s when writing changes to .cfg" % (e)) + except Exception as error: + logger.debug("Error {msg} when writing changes to .cfg".format(msg=error)) return CFG_NEW diff --git a/core/nzbToMediaDB.py b/core/nzbToMediaDB.py index 4445b6e1..de7fd825 100644 --- a/core/nzbToMediaDB.py +++ b/core/nzbToMediaDB.py @@ -19,7 +19,7 @@ def dbFilename(filename="nzbtomedia.db", suffix=None): @return: the correct location of the database file. """ if suffix: - filename = "%s.%s" % (filename, suffix) + filename = "{0}.{1}".format(filename, suffix) return core.os.path.join(core.PROGRAM_DIR, filename) @@ -181,7 +181,7 @@ class DBConnection(object): def tableInfo(self, tableName): # FIXME ? binding is not supported here, but I cannot find a way to escape a string manually - cursor = self.connection.execute("PRAGMA table_info(%s)" % tableName) + cursor = self.connection.execute("PRAGMA table_info({0})".format(tableName)) columns = {} for column in cursor: columns[column['name']] = {'type': column['type']} @@ -250,8 +250,8 @@ class SchemaUpgrade(object): return column in self.connection.tableInfo(tableName) def addColumn(self, table, column, type="NUMERIC", default=0): - self.connection.action("ALTER TABLE %s ADD %s %s" % (table, column, type)) - self.connection.action("UPDATE %s SET %s = ?" % (table, column), (default,)) + self.connection.action("ALTER TABLE {0} ADD {1} {2}".format(table, column, type)) + self.connection.action("UPDATE {0} SET {1} = ?".format(table, column), (default,)) def checkDBVersion(self): result = self.connection.select("SELECT db_version FROM db_version") diff --git a/core/nzbToMediaSceneExceptions.py b/core/nzbToMediaSceneExceptions.py index 40700961..71ac28b2 100644 --- a/core/nzbToMediaSceneExceptions.py +++ b/core/nzbToMediaSceneExceptions.py @@ -61,23 +61,25 @@ def strip_groups(filename): def rename_file(filename, newfilePath): - logger.debug("Replacing file name %s with download name %s" % (filename, newfilePath), "EXCEPTION") + logger.debug("Replacing file name {old} with download name {new}".format + (old=filename, new=newfilePath), "EXCEPTION") try: os.rename(filename, newfilePath) - except Exception as e: - logger.error("Unable to rename file due to: %s" % (str(e)), "EXCEPTION") + except Exception as error: + logger.error("Unable to rename file due to: {error}".format(error=error), "EXCEPTION") def replace_filename(filename, dirname, name): head, fileExtension = os.path.splitext(os.path.basename(filename)) if media_pattern.search(os.path.basename(dirname).replace(' ', '.')) is not None: newname = os.path.basename(dirname).replace(' ', '.') - logger.debug("Replacing file name %s with directory name %s" % (head, newname), "EXCEPTION") + logger.debug("Replacing file name {old} with directory name {new}".format(old=head, new=newname), "EXCEPTION") elif media_pattern.search(name.replace(' ', '.').lower()) is not None: newname = name.replace(' ', '.') - logger.debug("Replacing file name %s with download name %s" % (head, newname), "EXCEPTION") + logger.debug("Replacing file name {old} with download name {new}".format + (old=head, new=newname), "EXCEPTION") else: - logger.warning("No name replacement determined for %s" % (head), "EXCEPTION") + logger.warning("No name replacement determined for {name}".format(name=head), "EXCEPTION") newname = name newfile = newname + fileExtension newfilePath = os.path.join(dirname, newfile) @@ -103,7 +105,8 @@ def reverse_filename(filename, dirname, name): else: newname = head[::-1].title() newname = newname.replace(' ', '.') - logger.debug("Reversing filename %s to %s" % (head, newname), "EXCEPTION") + logger.debug("Reversing filename {old} to {new}".format + (old=head, new=newname), "EXCEPTION") newfile = newname + fileExtension newfilePath = os.path.join(dirname, newfile) return newfilePath @@ -129,11 +132,12 @@ def rename_script(dirname): dest = os.path.join(dirname, cmd[1].split('\\')[-1].split('/')[-1]) if os.path.isfile(dest): continue - logger.debug("Renaming file %s to %s" % (orig, dest), "EXCEPTION") + logger.debug("Renaming file {source} to {destination}".format + (source=orig, destination=dest), "EXCEPTION") try: os.rename(orig, dest) - except Exception as e: - logger.error("Unable to rename file due to: %s" % (str(e)), "EXCEPTION") + except Exception as error: + logger.error("Unable to rename file due to: {error}".format(error=error), "EXCEPTION") # dict for custom groups # we can add more to this list diff --git a/core/nzbToMediaUserScript.py b/core/nzbToMediaUserScript.py index fe6a453e..d05273be 100644 --- a/core/nzbToMediaUserScript.py +++ b/core/nzbToMediaUserScript.py @@ -48,7 +48,7 @@ def external_script(outputDestination, torrentName, torrentLabel, settings): if transcoder.isVideoGood(video, 0): import_subs(video) else: - logger.info("Corrupt video file found %s. Deleting." % (video), "USERSCRIPT") + logger.info("Corrupt video file found {0}. Deleting.".format(video), "USERSCRIPT") os.unlink(video) for dirpath, dirnames, filenames in os.walk(outputDestination): @@ -64,22 +64,22 @@ def external_script(outputDestination, torrentName, torrentLabel, settings): command = [core.USER_SCRIPT] for param in core.USER_SCRIPT_PARAM: if param == "FN": - command.append('%s' % file) + command.append('{0}'.format(file)) continue elif param == "FP": - command.append('%s' % filePath) + command.append('{0}'.format(filePath)) continue elif param == "TN": - command.append('%s' % torrentName) + command.append('{0}'.format(torrentName)) continue elif param == "TL": - command.append('%s' % torrentLabel) + command.append('{0}'.format(torrentLabel)) continue elif param == "DN": if core.USER_SCRIPT_RUNONCE == 1: - command.append('%s' % outputDestination) + command.append('{0}'.format(outputDestination)) else: - command.append('%s' % dirpath) + command.append('{0}'.format(dirpath)) continue else: command.append(param) @@ -87,21 +87,21 @@ def external_script(outputDestination, torrentName, torrentLabel, settings): cmd = "" for item in command: cmd = cmd + " " + item - logger.info("Running script %s on file %s." % (cmd, filePath), "USERSCRIPT") + logger.info("Running script {0} on file {1}.".format(cmd, filePath), "USERSCRIPT") try: p = Popen(command) res = p.wait() if str(res) in core.USER_SCRIPT_SUCCESSCODES: # Linux returns 0 for successful. - logger.info("UserScript %s was successfull" % (command[0])) + logger.info("UserScript {0} was successfull".format(command[0])) result = 0 else: - logger.error("UserScript %s has failed with return code: %s" % (command[0], res), "USERSCRIPT") + logger.error("UserScript {0} has failed with return code: {1}".format(command[0], res), "USERSCRIPT") logger.info( - "If the UserScript completed successfully you should add %s to the user_script_successCodes" % ( + "If the UserScript completed successfully you should add {0} to the user_script_successCodes".format( res), "USERSCRIPT") result = int(1) except: - logger.error("UserScript %s has failed" % (command[0]), "USERSCRIPT") + logger.error("UserScript {0} has failed".format(command[0]), "USERSCRIPT") result = int(1) final_result += result @@ -114,9 +114,9 @@ def external_script(outputDestination, torrentName, torrentLabel, settings): num_files_new += 1 if core.USER_SCRIPT_CLEAN == int(1) and num_files_new == 0 and final_result == 0: - logger.info("All files have been processed. Cleaning outputDirectory %s" % (outputDestination)) + logger.info("All files have been processed. Cleaning outputDirectory {0}".format(outputDestination)) rmDir(outputDestination) elif core.USER_SCRIPT_CLEAN == int(1) and num_files_new != 0: - logger.info("%s files were processed, but %s still remain. outputDirectory will not be cleaned." % ( + logger.info("{0} files were processed, but {1} still remain. outputDirectory will not be cleaned.".format( num_files, num_files_new)) return [final_result, ''] diff --git a/core/nzbToMediaUtil.py b/core/nzbToMediaUtil.py index bbb58346..75c3571a 100644 --- a/core/nzbToMediaUtil.py +++ b/core/nzbToMediaUtil.py @@ -40,7 +40,7 @@ def reportNzb(failure_link, clientAgent): try: requests.post(failure_link, headers=headers, timeout=(30, 300)) except Exception as e: - logger.error("Unable to open URL %s due to %s" % (failure_link, e)) + logger.error("Unable to open URL {0} due to {1}".format(failure_link, e)) return @@ -115,13 +115,13 @@ def category_search(inputDirectory, inputName, inputCategory, root, categories): pathlist = os.path.normpath(inputDirectory).split(os.sep) if inputCategory and inputCategory in pathlist: - logger.debug("SEARCH: Found the Category: %s in directory structure" % (inputCategory)) + logger.debug("SEARCH: Found the Category: {0} in directory structure".format(inputCategory)) elif inputCategory: - logger.debug("SEARCH: Could not find the category: %s in the directory structure" % (inputCategory)) + logger.debug("SEARCH: Could not find the category: {0} in the directory structure".format(inputCategory)) else: try: inputCategory = list(set(pathlist) & set(categories))[-1] # assume last match is most relevant category. - logger.debug("SEARCH: Found Category: %s in directory structure" % (inputCategory)) + logger.debug("SEARCH: Found Category: {0} in directory structure".format(inputCategory)) except IndexError: inputCategory = "" logger.debug("SEARCH: Could not find a category in the directory structure") @@ -132,30 +132,30 @@ def category_search(inputDirectory, inputName, inputCategory, root, categories): if inputCategory and os.path.isdir(os.path.join(inputDirectory, inputCategory)): logger.info( - "SEARCH: Found category directory %s in input directory directory %s" % (inputCategory, inputDirectory)) + "SEARCH: Found category directory {0} in input directory directory {1}".format(inputCategory, inputDirectory)) inputDirectory = os.path.join(inputDirectory, inputCategory) - logger.info("SEARCH: Setting inputDirectory to %s" % (inputDirectory)) + logger.info("SEARCH: Setting inputDirectory to {0}".format(inputDirectory)) if inputName and os.path.isdir(os.path.join(inputDirectory, inputName)): - logger.info("SEARCH: Found torrent directory %s in input directory directory %s" % (inputName, inputDirectory)) + logger.info("SEARCH: Found torrent directory {0} in input directory directory {1}".format(inputName, inputDirectory)) inputDirectory = os.path.join(inputDirectory, inputName) - logger.info("SEARCH: Setting inputDirectory to %s" % (inputDirectory)) + logger.info("SEARCH: Setting inputDirectory to {0}".format(inputDirectory)) tordir = True elif inputName and os.path.isdir(os.path.join(inputDirectory, sanitizeName(inputName))): - logger.info("SEARCH: Found torrent directory %s in input directory directory %s" % ( + logger.info("SEARCH: Found torrent directory {0} in input directory directory {1}".format( sanitizeName(inputName), inputDirectory)) inputDirectory = os.path.join(inputDirectory, sanitizeName(inputName)) - logger.info("SEARCH: Setting inputDirectory to %s" % (inputDirectory)) + logger.info("SEARCH: Setting inputDirectory to {0}".format(inputDirectory)) tordir = True elif inputName and os.path.isfile(os.path.join(inputDirectory, inputName)): - logger.info("SEARCH: Found torrent file %s in input directory directory %s" % (inputName, inputDirectory)) + logger.info("SEARCH: Found torrent file {0} in input directory directory {1}".format(inputName, inputDirectory)) inputDirectory = os.path.join(inputDirectory, inputName) - logger.info("SEARCH: Setting inputDirectory to %s" % (inputDirectory)) + logger.info("SEARCH: Setting inputDirectory to {0}".format(inputDirectory)) tordir = True elif inputName and os.path.isfile(os.path.join(inputDirectory, sanitizeName(inputName))): - logger.info("SEARCH: Found torrent file %s in input directory directory %s" % ( + logger.info("SEARCH: Found torrent file {0} in input directory directory {1}".format( sanitizeName(inputName), inputDirectory)) inputDirectory = os.path.join(inputDirectory, sanitizeName(inputName)) - logger.info("SEARCH: Setting inputDirectory to %s" % (inputDirectory)) + logger.info("SEARCH: Setting inputDirectory to {0}".format(inputDirectory)) tordir = True imdbid = [item for item in pathlist if '.cp(tt' in item] # This looks for the .cp(tt imdb id in the path. @@ -168,7 +168,8 @@ def category_search(inputDirectory, inputName, inputCategory, root, categories): index = pathlist.index(inputCategory) if index + 1 < len(pathlist): tordir = True - logger.info("SEARCH: Found a unique directory %s in the category directory" % (pathlist[index + 1])) + logger.info("SEARCH: Found a unique directory {0} in the category directory".format + (pathlist[index + 1])) if not inputName: inputName = pathlist[index + 1] except ValueError: @@ -176,7 +177,7 @@ def category_search(inputDirectory, inputName, inputCategory, root, categories): if inputName and not tordir: if inputName in pathlist or sanitizeName(inputName) in pathlist: - logger.info("SEARCH: Found torrent directory %s in the directory structure" % (inputName)) + logger.info("SEARCH: Found torrent directory {0} in the directory structure".format(inputName)) tordir = True else: root = 1 @@ -206,7 +207,7 @@ def is_minSize(inputName, minSize): try: inputSize = getDirSize(os.path.dirname(inputName)) except: - logger.error("Failed to get file size for %s" % (inputName), 'MINSIZE') + logger.error("Failed to get file size for {0}".format(inputName), 'MINSIZE') return True # Ignore files under a certain size @@ -221,9 +222,9 @@ def is_sample(inputName): def copy_link(src, targetLink, useLink): - logger.info("MEDIAFILE: [%s]" % (os.path.basename(targetLink)), 'COPYLINK') - logger.info("SOURCE FOLDER: [%s]" % (os.path.dirname(src)), 'COPYLINK') - logger.info("TARGET FOLDER: [%s]" % (os.path.dirname(targetLink)), 'COPYLINK') + logger.info("MEDIAFILE: [{0}]".format(os.path.basename(targetLink)), 'COPYLINK') + logger.info("SOURCE FOLDER: [{0}]".format(os.path.dirname(src)), 'COPYLINK') + logger.info("TARGET FOLDER: [{0}]".format(os.path.dirname(targetLink)), 'COPYLINK') if src != targetLink and os.path.exists(targetLink): logger.info("MEDIAFILE already exists in the TARGET folder, skipping ...", 'COPYLINK') @@ -263,7 +264,7 @@ def copy_link(src, targetLink, useLink): shutil.move(src, targetLink) return True except Exception as e: - logger.warning("Error: %s, copying instead ... " % (e), 'COPYLINK') + logger.warning("Error: {0}, copying instead ... ".format(e), 'COPYLINK') logger.info("Copying SOURCE MEDIAFILE -> TARGET FOLDER", 'COPYLINK') shutil.copy(src, targetLink) @@ -277,26 +278,26 @@ def replace_links(link): if os.name == 'nt': import jaraco if not jaraco.windows.filesystem.islink(link): - logger.debug('%s is not a link' % (link)) + logger.debug('{0} is not a link'.format(link)) return while jaraco.windows.filesystem.islink(target): target = jaraco.windows.filesystem.readlink(target) n = n + 1 else: if not os.path.islink(link): - logger.debug('%s is not a link' % (link)) + logger.debug('{0} is not a link'.format(link)) return while os.path.islink(target): target = os.readlink(target) n = n + 1 if n > 1: - logger.info("Changing sym-link: %s to point directly to file: %s" % (link, target), 'COPYLINK') + logger.info("Changing sym-link: {0} to point directly to file: {1}".format(link, target), 'COPYLINK') os.unlink(link) linktastic.symlink(target, link) def flatten(outputDestination): - logger.info("FLATTEN: Flattening directory: %s" % (outputDestination)) + logger.info("FLATTEN: Flattening directory: {0}".format(outputDestination)) for outputFile in listMediaFiles(outputDestination): dirPath = os.path.dirname(outputFile) fileName = os.path.basename(outputFile) @@ -309,7 +310,7 @@ def flatten(outputDestination): try: shutil.move(outputFile, target) except: - logger.error("Could not flatten %s" % (outputFile), 'FLATTEN') + logger.error("Could not flatten {0}".format(outputFile), 'FLATTEN') removeEmptyFolders(outputDestination) # Cleanup empty directories @@ -320,7 +321,7 @@ def removeEmptyFolders(path, removeRoot=True): return # remove empty subfolders - logger.debug("Checking for empty folders in:%s" % (path)) + logger.debug("Checking for empty folders in:{0}".format(path)) files = os.listdir(path) if len(files): for f in files: @@ -331,7 +332,7 @@ def removeEmptyFolders(path, removeRoot=True): # if folder empty, delete it files = os.listdir(path) if len(files) == 0 and removeRoot: - logger.debug("Removing empty folder:%s" % (path)) + logger.debug("Removing empty folder:{}".format(path)) os.rmdir(path) @@ -386,16 +387,16 @@ def WakeUp(): i = 1 while TestCon(host, port) == "Down" and i < 4: - logger.info(("Sending WakeOnLan Magic Packet for mac: %s" % (mac))) + logger.info(("Sending WakeOnLan Magic Packet for mac: {0}".format(mac))) WakeOnLan(mac) time.sleep(20) i = i + 1 if TestCon(host, port) == "Down": # final check. - logger.warning("System with mac: %s has not woken after 3 attempts. Continuing with the rest of the script." % ( - mac)) + logger.warning("System with mac: {0} has not woken after 3 attempts. " + "Continuing with the rest of the script.".format(mac)) else: - logger.info("System with mac: %s has been woken. Continuing with the rest of the script." % (mac)) + logger.info("System with mac: {0} has been woken. Continuing with the rest of the script.".format(mac)) def CharReplace(Name): @@ -454,23 +455,23 @@ def convert_to_ascii(inputName, dirName): encoded, base2 = CharReplace(base) if encoded: dirName = os.path.join(dir, base2) - logger.info("Renaming directory to: %s." % (base2), 'ENCODER') + logger.info("Renaming directory to: {0}.".format(base2), 'ENCODER') os.rename(os.path.join(dir, base), dirName) if 'NZBOP_SCRIPTDIR' in os.environ: - print("[NZB] DIRECTORY=%s" % (dirName)) + print("[NZB] DIRECTORY={0}".format(dirName)) for dirname, dirnames, filenames in os.walk(dirName, topdown=False): for subdirname in dirnames: encoded, subdirname2 = CharReplace(subdirname) if encoded: - logger.info("Renaming directory to: %s." % (subdirname2), 'ENCODER') + logger.info("Renaming directory to: {0}.".format(subdirname2), 'ENCODER') os.rename(os.path.join(dirname, subdirname), os.path.join(dirname, subdirname2)) for dirname, dirnames, filenames in os.walk(dirName): for filename in filenames: encoded, filename2 = CharReplace(filename) if encoded: - logger.info("Renaming file to: %s." % (filename2), 'ENCODER') + logger.info("Renaming file to: {0}.".format(filename2), 'ENCODER') os.rename(os.path.join(dirname, filename), os.path.join(dirname, filename2)) return inputName, dirName @@ -604,7 +605,7 @@ def getDirs(section, subsection, link='hard'): def processDir(path): folders = [] - logger.info("Searching %s for mediafiles to post-process ..." % (path)) + logger.info("Searching {0} for mediafiles to post-process ...".format(path)) sync = [o for o in os.listdir(path) if os.path.splitext(o)[1] in ['.!sync', '.bts']] # search for single files and move them into their own folder for post-processing for mediafile in [os.path.join(path, o) for o in os.listdir(path) if @@ -614,7 +615,7 @@ def getDirs(section, subsection, link='hard'): if os.path.split(mediafile)[1] in ['Thumbs.db', 'thumbs.db']: continue try: - logger.debug("Found file %s in root directory %s." % (os.path.split(mediafile)[1], path)) + logger.debug("Found file {0} in root directory {1}.".format(os.path.split(mediafile)[1], path)) newPath = None fileExt = os.path.splitext(mediafile)[1] try: @@ -626,7 +627,7 @@ def getDirs(section, subsection, link='hard'): album = f.album # create new path - newPath = os.path.join(path, "%s - %s" % (sanitizeName(artist), sanitizeName(album))) + newPath = os.path.join(path, "{0} - {1}".format(sanitizeName(artist), sanitizeName(album))) elif fileExt in core.MEDIACONTAINER: f = guessit.guess_video_info(mediafile) @@ -638,7 +639,7 @@ def getDirs(section, subsection, link='hard'): newPath = os.path.join(path, sanitizeName(title)) except Exception as e: - logger.error("Exception parsing name for media file: %s: %s" % (os.path.split(mediafile)[1], e)) + logger.error("Exception parsing name for media file: {0}: {1}".format(os.path.split(mediafile)[1], e)) if not newPath: title = os.path.splitext(os.path.basename(mediafile))[0] @@ -667,7 +668,7 @@ def getDirs(section, subsection, link='hard'): # link file to its new path copy_link(mediafile, newfile, link) except Exception as e: - logger.error("Failed to move %s to its own directory: %s" % (os.path.split(mediafile)[1], e)) + logger.error("Failed to move {0} to its own directory: {1}".format(os.path.split(mediafile)[1], e)) # removeEmptyFolders(path, removeRoot=False) @@ -687,8 +688,8 @@ def getDirs(section, subsection, link='hard'): elif os.path.exists(core.CFG[section][subsection]["watch_dir"]): to_return.extend(processDir(core.CFG[section][subsection]["watch_dir"])) except Exception as e: - logger.error("Failed to add directories from %s for post-processing: %s" % ( - core.CFG[section][subsection]["watch_dir"], e)) + logger.error("Failed to add directories from {0} for post-processing: {1}".format + (core.CFG[section][subsection]["watch_dir"], e)) if core.USELINK == 'move': try: @@ -696,10 +697,10 @@ def getDirs(section, subsection, link='hard'): if os.path.exists(outputDirectory): to_return.extend(processDir(outputDirectory)) except Exception as e: - logger.error("Failed to add directories from %s for post-processing: %s" % (core.OUTPUTDIRECTORY, e)) + logger.error("Failed to add directories from {0} for post-processing: {1}".format(core.OUTPUTDIRECTORY, e)) if not to_return: - logger.debug("No directories identified in %s:%s for post-processing" % (section, subsection)) + logger.debug("No directories identified in {0}:{1} for post-processing".format(section, subsection)) return list(set(to_return)) @@ -724,19 +725,19 @@ def onerror(func, path, exc_info): def rmDir(dirName): - logger.info("Deleting %s" % (dirName)) + logger.info("Deleting {0}".format(dirName)) try: shutil.rmtree(dirName, onerror=onerror) except: - logger.error("Unable to delete folder %s" % (dirName)) + logger.error("Unable to delete folder {0}".format(dirName)) def cleanDir(path, section, subsection): if not os.path.exists(path): - logger.info('Directory %s has been processed and removed ...' % (path), 'CLEANDIR') + logger.info('Directory {0} has been processed and removed ...'.format(path), 'CLEANDIR') return if core.FORCE_CLEAN and not core.FAILED: - logger.info('Doing Forceful Clean of %s' % (path), 'CLEANDIR') + logger.info('Doing Forceful Clean of {0}'.format(path), 'CLEANDIR') rmDir(path) return try: @@ -753,15 +754,15 @@ def cleanDir(path, section, subsection): num_files = 'unknown' if num_files > 0: logger.info( - "Directory %s still contains %s unprocessed file(s), skipping ..." % (path, num_files), + "Directory {0} still contains {1} unprocessed file(s), skipping ...".format(path, num_files), 'CLEANDIRS') return - logger.info("Directory %s has been processed, removing ..." % (path), 'CLEANDIRS') + logger.info("Directory {0} has been processed, removing ...".format(path), 'CLEANDIRS') try: shutil.rmtree(path, onerror=onerror) except: - logger.error("Unable to delete directory %s" % (path)) + logger.error("Unable to delete directory {0}".format(path)) def create_torrent_class(clientAgent): @@ -770,14 +771,14 @@ def create_torrent_class(clientAgent): if clientAgent == 'utorrent': try: - logger.debug("Connecting to %s: %s" % (clientAgent, core.UTORRENTWEBUI)) + logger.debug("Connecting to {0}: {1}".format(clientAgent, core.UTORRENTWEBUI)) tc = UTorrentClient(core.UTORRENTWEBUI, core.UTORRENTUSR, core.UTORRENTPWD) except: logger.error("Failed to connect to uTorrent") if clientAgent == 'transmission': try: - logger.debug("Connecting to %s: http://%s:%s" % ( + logger.debug("Connecting to {0}: http://{1}:{2}".format( clientAgent, core.TRANSMISSIONHOST, core.TRANSMISSIONPORT)) tc = TransmissionClient(core.TRANSMISSIONHOST, core.TRANSMISSIONPORT, core.TRANSMISSIONUSR, @@ -787,7 +788,7 @@ def create_torrent_class(clientAgent): if clientAgent == 'deluge': try: - logger.debug("Connecting to %s: http://%s:%s" % (clientAgent, core.DELUGEHOST, core.DELUGEPORT)) + logger.debug("Connecting to {0}: http://{1}:{2}".format(clientAgent, core.DELUGEHOST, core.DELUGEPORT)) tc = DelugeClient() tc.connect(host=core.DELUGEHOST, port=core.DELUGEPORT, username=core.DELUGEUSR, password=core.DELUGEPWD) @@ -798,7 +799,7 @@ def create_torrent_class(clientAgent): def pause_torrent(clientAgent, inputHash, inputID, inputName): - logger.debug("Stopping torrent %s in %s while processing" % (inputName, clientAgent)) + logger.debug("Stopping torrent {0} in {1} while processing".format(inputName, clientAgent)) try: if clientAgent == 'utorrent' and core.TORRENT_CLASS != "": core.TORRENT_CLASS.stop(inputHash) @@ -808,13 +809,13 @@ def pause_torrent(clientAgent, inputHash, inputID, inputName): core.TORRENT_CLASS.core.pause_torrent([inputID]) time.sleep(5) except: - logger.warning("Failed to stop torrent %s in %s" % (inputName, clientAgent)) + logger.warning("Failed to stop torrent {0} in {1}".format(inputName, clientAgent)) def resume_torrent(clientAgent, inputHash, inputID, inputName): if not core.TORRENT_RESUME == 1: return - logger.debug("Starting torrent %s in %s" % (inputName, clientAgent)) + logger.debug("Starting torrent {0} in {1}".format(inputName, clientAgent)) try: if clientAgent == 'utorrent' and core.TORRENT_CLASS != "": core.TORRENT_CLASS.start(inputHash) @@ -824,12 +825,12 @@ def resume_torrent(clientAgent, inputHash, inputID, inputName): core.TORRENT_CLASS.core.resume_torrent([inputID]) time.sleep(5) except: - logger.warning("Failed to start torrent %s in %s" % (inputName, clientAgent)) + logger.warning("Failed to start torrent {0} in {1}".format(inputName, clientAgent)) def remove_torrent(clientAgent, inputHash, inputID, inputName): if core.DELETE_ORIGINAL == 1 or core.USELINK == 'move': - logger.debug("Deleting torrent %s from %s" % (inputName, clientAgent)) + logger.debug("Deleting torrent {0} from {1}".format(inputName, clientAgent)) try: if clientAgent == 'utorrent' and core.TORRENT_CLASS != "": core.TORRENT_CLASS.removedata(inputHash) @@ -840,13 +841,13 @@ def remove_torrent(clientAgent, inputHash, inputID, inputName): core.TORRENT_CLASS.core.remove_torrent(inputID, True) time.sleep(5) except: - logger.warning("Failed to delete torrent %s in %s" % (inputName, clientAgent)) + logger.warning("Failed to delete torrent {0} in {1}".format(inputName, clientAgent)) else: resume_torrent(clientAgent, inputHash, inputID, inputName) def find_download(clientAgent, download_id): - logger.debug("Searching for Download on %s ..." % (clientAgent)) + logger.debug("Searching for Download on {0} ...".format(clientAgent)) if clientAgent == 'utorrent': torrents = core.TORRENT_CLASS.list()[1]['torrents'] for torrent in torrents: @@ -862,9 +863,9 @@ def find_download(clientAgent, download_id): return False if clientAgent == 'sabnzbd': if "http" in core.SABNZBDHOST: - baseURL = "%s:%s/api" % (core.SABNZBDHOST, core.SABNZBDPORT) + baseURL = "{0}:{1}/api".format(core.SABNZBDHOST, core.SABNZBDPORT) else: - baseURL = "http://%s:%s/api" % (core.SABNZBDHOST, core.SABNZBDPORT) + baseURL = "http://{0}:{1}/api".format(core.SABNZBDHOST, core.SABNZBDPORT) url = baseURL params = { 'apikey': core.SABNZBDAPIKEY, @@ -889,9 +890,9 @@ def get_nzoid(inputName): slots = [] logger.debug("Searching for nzoid from SAbnzbd ...") if "http" in core.SABNZBDHOST: - baseURL = "%s:%s/api" % (core.SABNZBDHOST, core.SABNZBDPORT) + baseURL = "{0}:{1}/api".format(core.SABNZBDHOST, core.SABNZBDPORT) else: - baseURL = "http://%s:%s/api" % (core.SABNZBDHOST, core.SABNZBDPORT) + baseURL = "http://{0}:{1}/api".format(core.SABNZBDHOST, core.SABNZBDPORT) url = baseURL params = { 'apikey': core.SABNZBDAPIKEY, @@ -925,7 +926,7 @@ def get_nzoid(inputName): for nzo_id, name in slots: if name in [inputName, cleanName]: nzoid = nzo_id - logger.debug("Found nzoid: %s" % nzoid) + logger.debug("Found nzoid: {0}".format(nzoid)) break except: logger.warning("Data from SABnzbd could not be parsed") @@ -988,7 +989,8 @@ def listMediaFiles(path, minSize=0, delete_ignored=0, media=True, audio=True, me if delete_ignored == 1: try: os.unlink(path) - logger.debug('Ignored file %s has been removed ...' % (curFile)) + logger.debug('Ignored file {0} has been removed ...'.format + (curFile)) except: pass else: @@ -1009,7 +1011,8 @@ def listMediaFiles(path, minSize=0, delete_ignored=0, media=True, audio=True, me if delete_ignored == 1: try: os.unlink(fullCurFile) - logger.debug('Ignored file %s has been removed ...' % (curFile)) + logger.debug('Ignored file {0} has been removed ...'.format + (curFile)) except: pass continue @@ -1022,21 +1025,21 @@ def listMediaFiles(path, minSize=0, delete_ignored=0, media=True, audio=True, me def find_imdbid(dirName, inputName): imdbid = None - logger.info('Attemping imdbID lookup for %s' % (inputName)) + logger.info('Attemping imdbID lookup for {0}'.format(inputName)) # find imdbid in dirName logger.info('Searching folder and file names for imdbID ...') m = re.search('(tt\d{7})', dirName + inputName) if m: imdbid = m.group(1) - logger.info("Found imdbID [%s]" % imdbid) + logger.info("Found imdbID [{0}]".format(imdbid)) return imdbid if os.path.isdir(dirName): for file in os.listdir(dirName): m = re.search('(tt\d{7})', file) if m: imdbid = m.group(1) - logger.info("Found imdbID [%s] via file name" % imdbid) + logger.info("Found imdbID [{0}] via file name".format(imdbid)) return imdbid if 'NZBPR__DNZB_MOREINFO' in os.environ: dnzb_more_info = os.environ.get('NZBPR__DNZB_MOREINFO', '') @@ -1045,7 +1048,7 @@ def find_imdbid(dirName, inputName): m = regex.match(dnzb_more_info) if m: imdbid = m.group(1) - logger.info("Found imdbID [%s] from DNZB-MoreInfo" % imdbid) + logger.info("Found imdbID [{0}] from DNZB-MoreInfo".format(imdbid)) return imdbid logger.info('Searching IMDB for imdbID ...') guess = guessit.guess_movie_info(inputName) @@ -1062,12 +1065,12 @@ def find_imdbid(dirName, inputName): url = "http://www.omdbapi.com" - logger.debug("Opening URL: %s" % url) + logger.debug("Opening URL: {0}".format(url)) try: r = requests.get(url, params={'y': year, 't': title}, verify=False, timeout=(60, 300)) except requests.ConnectionError: - logger.error("Unable to open URL %s" % url) + logger.error("Unable to open URL {0}".format(url)) return results = r.json() @@ -1078,10 +1081,10 @@ def find_imdbid(dirName, inputName): pass if imdbid: - logger.info("Found imdbID [%s]" % imdbid) + logger.info("Found imdbID [{0}]".format(imdbid)) return imdbid - logger.warning('Unable to find a imdbID for %s' % (inputName)) + logger.warning('Unable to find a imdbID for {0}'.format(inputName)) return imdbid @@ -1103,7 +1106,7 @@ def extractFiles(src, dst=None, keep_archive=None): extracted_folder.append(dst or dirPath) extracted_archive.append(archiveName) except Exception: - logger.error("Extraction failed for: %s" % (fullFileName)) + logger.error("Extraction failed for: {0}".format(fullFileName)) for folder in extracted_folder: for inputFile in listMediaFiles(folder, media=False, audio=False, meta=False, archives=True): @@ -1112,14 +1115,14 @@ def extractFiles(src, dst=None, keep_archive=None): archiveName = re.sub(r"part[0-9]+", "", archiveName) if archiveName not in extracted_archive or keep_archive is True: continue # don't remove if we haven't extracted this archive, or if we want to preserve them. - logger.info("Removing extracted archive %s from folder %s ..." % (fullFileName, folder)) + logger.info("Removing extracted archive {0} from folder {1} ...".format(fullFileName, folder)) try: if not os.access(inputFile, os.W_OK): os.chmod(inputFile, stat.S_IWUSR) os.remove(inputFile) time.sleep(1) except Exception as e: - logger.error("Unable to remove file %s due to: %s" % (inputFile, e)) + logger.error("Unable to remove file {0} due to: {1}".format(inputFile, e)) def import_subs(filename): @@ -1139,13 +1142,13 @@ def import_subs(filename): if not languages: return - logger.debug("Attempting to download subtitles for %s" % (filename), 'SUBTITLES') + logger.debug("Attempting to download subtitles for {0}".format(filename), 'SUBTITLES') try: video = subliminal.scan_video(filename, subtitles=True, embedded_subtitles=True) subtitles = subliminal.download_best_subtitles({video}, languages, hearing_impaired=False) subliminal.save_subtitles(subtitles) except Exception as e: - logger.error("Failed to download subtitles for %s due to: %s" % (filename, e), 'SUBTITLES') + logger.error("Failed to download subtitles for {0} due to: {1}".format(filename, e), 'SUBTITLES') def server_responding(baseURL): @@ -1167,7 +1170,7 @@ def plex_update(category): section = None if not core.PLEXSEC: return - logger.debug("Attempting to update Plex Library for category %s." % (category), 'PLEX') + logger.debug("Attempting to update Plex Library for category {0}.".format(category), 'PLEX') for item in core.PLEXSEC: if item[0] == category: section = item[1] @@ -1210,7 +1213,7 @@ def backupVersionedFile(old_file, version): def update_downloadInfoStatus(inputName, status): - logger.db("Updating status of our download %s in the DB to %s" % (inputName, status)) + logger.db("Updating status of our download {0} in the DB to {1}".format(inputName, status)) myDB = nzbToMediaDB.DBConnection() myDB.action("UPDATE downloads SET status=?, last_update=? WHERE input_name=?", @@ -1218,7 +1221,7 @@ def update_downloadInfoStatus(inputName, status): def get_downloadInfo(inputName, status): - logger.db("Getting download info for %s from the DB" % (inputName)) + logger.db("Getting download info for {0} from the DB".format(inputName)) myDB = nzbToMediaDB.DBConnection() sqlResults = myDB.select("SELECT * FROM downloads WHERE input_name=? AND status=?", diff --git a/core/synchronousdeluge/rencode.py b/core/synchronousdeluge/rencode.py index f27c3304..8ab01375 100644 --- a/core/synchronousdeluge/rencode.py +++ b/core/synchronousdeluge/rencode.py @@ -435,7 +435,7 @@ def dumps(x, float_bits=DEFAULT_FLOAT_BITS): elif float_bits == 64: encode_func[FloatType] = encode_float64 else: - raise ValueError('Float bits (%d) is not 32 or 64' % float_bits) + raise ValueError('Float bits ({0:d}) is not 32 or 64'.format(float_bits)) r = [] encode_func[type(x)](x, r) finally: diff --git a/core/transcoder/transcoder.py b/core/transcoder/transcoder.py index 9731f689..a557c808 100644 --- a/core/transcoder/transcoder.py +++ b/core/transcoder/transcoder.py @@ -37,24 +37,25 @@ def isVideoGood(videofile, status): else: return True - logger.info('Checking [%s] for corruption, please stand by ...' % (fileNameExt), 'TRANSCODER') + logger.info('Checking [{0}] for corruption, please stand by ...'.format(fileNameExt), 'TRANSCODER') video_details, result = getVideoDetails(videofile) if result != 0: - logger.error("FAILED: [%s] is corrupted!" % (fileNameExt), 'TRANSCODER') + logger.error("FAILED: [{0}] is corrupted!".format(fileNameExt), 'TRANSCODER') return False if video_details.get("error"): - logger.info("FAILED: [%s] returned error [%s]." % (fileNameExt, str(video_details.get("error"))), 'TRANSCODER') + logger.info("FAILED: [{0}] returned error [{1}].".format(fileNameExt, video_details.get("error")), 'TRANSCODER') return False if video_details.get("streams"): videoStreams = [item for item in video_details["streams"] if item["codec_type"] == "video"] audioStreams = [item for item in video_details["streams"] if item["codec_type"] == "audio"] if len(videoStreams) > 0 and len(audioStreams) > 0: - logger.info("SUCCESS: [%s] has no corruption." % (fileNameExt), 'TRANSCODER') + logger.info("SUCCESS: [{0}] has no corruption.".format(fileNameExt), 'TRANSCODER') return True else: - logger.info("FAILED: [%s] has %s video streams and %s audio streams. Assume corruption." % ( - fileNameExt, str(len(videoStreams)), str(len(audioStreams))), 'TRANSCODER') + logger.info("FAILED: [{0}] has {1} video streams and {2} audio streams. " + "Assume corruption.".format + (fileNameExt, len(videoStreams), len(audioStreams)), 'TRANSCODER') return False @@ -64,7 +65,7 @@ def zip_out(file, img, bitbucket): try: procin = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=bitbucket) except: - logger.error("Extracting [%s] has failed" % (file), 'TRANSCODER') + logger.error("Extracting [{0}] has failed".format(file), 'TRANSCODER') return procin @@ -108,7 +109,7 @@ def getVideoDetails(videofile, img=None, bitbucket=None): result = proc.returncode video_details = json.loads(out) except: - logger.error("Checking [%s] has failed" % (file), 'TRANSCODER') + logger.error("Checking [{0}] has failed".format(file), 'TRANSCODER') return video_details, result @@ -124,7 +125,7 @@ def buildCommands(file, newDir, movieName, bitbucket): if check and core.CONCAT: name = movieName elif check: - name = ('%s.cd%s' % (movieName, check.groups()[0])) + name = ('{0}.cd{1}'.format(movieName, check.groups()[0])) elif core.CONCAT and re.match("(.+)[cC][dD][0-9]", name): name = re.sub("([\ \.\-\_\=\:]+[cC][dD][0-9])", "", name) if ext == core.VEXTENSION and newDir == dir: # we need to change the name to prevent overwriting itself. @@ -545,20 +546,20 @@ def extract_subs(file, newfilePath, bitbucket): lan = "unk" if num == 1: - outputFile = os.path.join(subdir, "%s.srt" % (name)) + outputFile = os.path.join(subdir, "{0}.srt".format(name)) if os.path.isfile(outputFile): - outputFile = os.path.join(subdir, "%s.%s.srt" % (name, n)) + outputFile = os.path.join(subdir, "{0}.{1}.srt".format(name, n)) else: - outputFile = os.path.join(subdir, "%s.%s.srt" % (name, lan)) + outputFile = os.path.join(subdir, "{0}.{1}.srt".format(name, lan)) if os.path.isfile(outputFile): - outputFile = os.path.join(subdir, "%s.%s.%s.srt" % (name, lan, n)) + outputFile = os.path.join(subdir, "{0}.{1}.{2}.srt".format(name, lan, n)) command = [core.FFMPEG, '-loglevel', 'warning', '-i', file, '-vn', '-an', '-codec:' + str(idx), 'srt', outputFile] if platform.system() != 'Windows': command = core.NICENESS + command - logger.info("Extracting %s subtitle from: %s" % (lan, file)) + logger.info("Extracting {0} subtitle from: {1}".format(lan, file)) print_cmd(command) result = 1 # set result to failed in case call fails. try: @@ -573,7 +574,7 @@ def extract_subs(file, newfilePath, bitbucket): shutil.copymode(file, outputFile) except: pass - logger.info("Extracting %s subtitle from %s has succeeded" % (lan, file)) + logger.info("Extracting {0} subtitle from {1} has succeeded".format(lan, file)) else: logger.error("Extracting subtitles has failed") @@ -587,11 +588,11 @@ def processList(List, newDir, bitbucket): for item in List: ext = os.path.splitext(item)[1].lower() if ext in ['.iso', '.bin', '.img'] and ext not in core.IGNOREEXTENSIONS: - logger.debug("Attempting to rip disk image: %s" % (item), "TRANSCODER") + logger.debug("Attempting to rip disk image: {0}".format(item), "TRANSCODER") newList.extend(ripISO(item, newDir, bitbucket)) remList.append(item) elif re.match(".+VTS_[0-9][0-9]_[0-9].[Vv][Oo][Bb]", item) and '.vob' not in core.IGNOREEXTENSIONS: - logger.debug("Found VIDEO_TS image file: %s" % (item), "TRANSCODER") + logger.debug("Found VIDEO_TS image file: {0}".format(item), "TRANSCODER") if not vtsPath: try: vtsPath = re.match("(.+VIDEO_TS)", item).groups()[0] @@ -617,7 +618,7 @@ def processList(List, newDir, bitbucket): List.extend(newList) for item in remList: List.remove(item) - logger.debug("Successfully extracted .vob file %s from disk image" % (newList[0]), "TRANSCODER") + logger.debug("Successfully extracted .vob file {0} from disk image".format(newList[0]), "TRANSCODER") elif newList and not success: newList = [] remList = [] @@ -630,12 +631,12 @@ def ripISO(item, newDir, bitbucket): failure_dir = 'failure' # Mount the ISO in your OS and call combineVTS. if not core.SEVENZIP: - logger.error("No 7zip installed. Can't extract image file %s" % (item), "TRANSCODER") + logger.error("No 7zip installed. Can't extract image file {0}".format(item), "TRANSCODER") newFiles = [failure_dir] return newFiles cmd = [core.SEVENZIP, 'l', item] try: - logger.debug("Attempting to extract .vob from image file %s" % (item), "TRANSCODER") + logger.debug("Attempting to extract .vob from image file {0}".format(item), "TRANSCODER") print_cmd(cmd) proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=bitbucket) out, err = proc.communicate() @@ -646,7 +647,7 @@ def ripISO(item, newDir, bitbucket): concat = [] m = 1 while True: - vtsName = 'VIDEO_TS%sVTS_%02d_%d.VOB' % (os.sep, n + 1, m) + vtsName = 'VIDEO_TS{0}VTS_{1:02d}_{2:d}.VOB'.format(os.sep, n + 1, m) if vtsName in fileList: concat.append(vtsName) m += 1 @@ -657,16 +658,16 @@ def ripISO(item, newDir, bitbucket): if core.CONCAT: combined.extend(concat) continue - name = '%s.cd%s' % (os.path.splitext(os.path.split(item)[1])[0], str(n + 1)) + name = '{0}.cd{1}'.format(os.path.splitext(os.path.split(item)[1])[0], str(n + 1)) newFiles.append({item: {'name': name, 'files': concat}}) if core.CONCAT: name = os.path.splitext(os.path.split(item)[1])[0] newFiles.append({item: {'name': name, 'files': combined}}) if not newFiles: - logger.error("No VIDEO_TS folder found in image file %s" % (item), "TRANSCODER") + logger.error("No VIDEO_TS folder found in image file {0}".format(item), "TRANSCODER") newFiles = [failure_dir] except: - logger.error("Failed to extract from image file %s" % (item), "TRANSCODER") + logger.error("Failed to extract from image file {0}".format(item), "TRANSCODER") newFiles = [failure_dir] return newFiles @@ -678,7 +679,7 @@ def combineVTS(vtsPath): concat = '' m = 1 while True: - vtsName = 'VTS_%02d_%d.VOB' % (n + 1, m) + vtsName = 'VTS_{0:02d}_{1:d}.VOB'.format(n + 1, m) if os.path.isfile(os.path.join(vtsPath, vtsName)): concat = concat + os.path.join(vtsPath, vtsName) + '|' m += 1 @@ -689,9 +690,9 @@ def combineVTS(vtsPath): if core.CONCAT: combined = combined + concat + '|' continue - newFiles.append('concat:%s' % concat[:-1]) + newFiles.append('concat:{0}'.format(concat[:-1])) if core.CONCAT: - newFiles.append('concat:%s' % combined[:-1]) + newFiles.append('concat:{0}'.format(combined[:-1])) return newFiles @@ -707,7 +708,7 @@ def combineCD(combine): else: break if concat: - newFiles.append('concat:%s' % concat[:-1]) + newFiles.append('concat:{0}'.format(concat[:-1])) return newFiles @@ -715,7 +716,7 @@ def print_cmd(command): cmd = "" for item in command: cmd = cmd + " " + str(item) - logger.debug("calling command:%s" % (cmd)) + logger.debug("calling command:{0}".format(cmd)) def Transcode_directory(dirName): @@ -756,11 +757,11 @@ def Transcode_directory(dirName): os.remove(newfilePath) except OSError as e: if e.errno != errno.ENOENT: # Ignore the error if it's just telling us that the file doesn't exist - logger.debug("Error when removing transcoding target: %s" % (e)) + logger.debug("Error when removing transcoding target: {0}".format(e)) except Exception as e: - logger.debug("Error when removing transcoding target: %s" % (e)) + logger.debug("Error when removing transcoding target: {0}".format(e)) - logger.info("Transcoding video: %s" % (newfilePath)) + logger.info("Transcoding video: {0}".format(newfilePath)) print_cmd(command) result = 1 # set result to failed in case call fails. try: @@ -777,7 +778,7 @@ def Transcode_directory(dirName): proc.communicate() result = proc.returncode except: - logger.error("Transcoding of video %s has failed" % (newfilePath)) + logger.error("Transcoding of video {0} has failed".format(newfilePath)) if core.SUBSDIR and result == 0 and isinstance(file, str): for sub in get_subs(file): @@ -793,14 +794,14 @@ def Transcode_directory(dirName): shutil.copymode(file, newfilePath) except: pass - logger.info("Transcoding of video to %s succeeded" % (newfilePath)) + logger.info("Transcoding of video to {0} succeeded".format(newfilePath)) if os.path.isfile(newfilePath) and (file in newList or not core.DUPLICATE): try: os.unlink(file) except: pass else: - logger.error("Transcoding of video to %s failed with result %s" % (newfilePath, str(result))) + logger.error("Transcoding of video to {0} failed with result {1}".format(newfilePath, result)) # this will be 0 (successful) it all are successful, else will return a positive integer for failure. final_result = final_result + result if final_result == 0 and not core.DUPLICATE: diff --git a/core/transmissionrpc/client.py b/core/transmissionrpc/client.py index 6379e595..04c85ac0 100644 --- a/core/transmissionrpc/client.py +++ b/core/transmissionrpc/client.py @@ -100,7 +100,7 @@ def parse_torrent_ids(args): except ValueError: pass if not addition: - raise ValueError('Invalid torrent id, \"%s\"' % item) + raise ValueError('Invalid torrent id, {item!r}'.format(item=item)) ids.extend(addition) elif isinstance(args, (list, tuple)): for item in args: @@ -251,20 +251,20 @@ class Client(object): start = time.time() http_data = self._http_query(query, timeout) elapsed = time.time() - start - LOGGER.info('http request took %.3f s' % (elapsed)) + LOGGER.info('http request took {time:.3f} s'.format(time=elapsed)) try: data = json.loads(http_data) except ValueError as error: LOGGER.error('Error: ' + str(error)) - LOGGER.error('Request: \"%s\"' % (query)) - LOGGER.error('HTTP data: \"%s\"' % (http_data)) + LOGGER.error('Request: {request!r}'.format(request=query)) + LOGGER.error('HTTP data: {data!r}'.format(data=http_data)) raise LOGGER.debug(json.dumps(data, indent=2)) if 'result' in data: if data['result'] != 'success': - raise TransmissionError('Query failed with result \"%s\".' % (data['result'])) + raise TransmissionError('Query failed with result {result!r}.'.format(result=data['result'])) else: raise TransmissionError('Query failed without result.') @@ -348,8 +348,9 @@ class Client(object): Add a warning to the log if the Transmission RPC version is lower then the provided version. """ if self.rpc_version < version: - LOGGER.warning('Using feature not supported by server. RPC version for server %d, feature introduced in %d.' - % (self.rpc_version, version)) + LOGGER.warning('Using feature not supported by server. ' + 'RPC version for server {x}, feature introduced in {y}.'.format + (x=self.rpc_version, y=version)) def add_torrent(self, torrent, timeout=None, **kwargs): """ diff --git a/core/transmissionrpc/error.py b/core/transmissionrpc/error.py index 6b44bf32..ecd6bf11 100644 --- a/core/transmissionrpc/error.py +++ b/core/transmissionrpc/error.py @@ -19,7 +19,7 @@ class TransmissionError(Exception): def __str__(self): if self.original: original_name = type(self.original).__name__ - return '%s Original exception: %s, "%s"' % (self.message, original_name, str(self.original)) + return '{0} Original exception: {1}, "{2}"'.format(self.message, original_name, str(self.original)) else: return self.message @@ -49,10 +49,10 @@ class HTTPHandlerError(Exception): self.data = httpdata def __repr__(self): - return '' % (self.code, self.message) + return ''.format(self.code, self.message) def __str__(self): - return 'HTTPHandlerError %d: %s' % (self.code, self.message) + return 'HTTPHandlerError {0:d}: {1}'.format(self.code, self.message) def __unicode__(self): - return 'HTTPHandlerError %d: %s' % (self.code, self.message) + return 'HTTPHandlerError {0:d}: {1}'.format(self.code, self.message) diff --git a/core/transmissionrpc/httphandler.py b/core/transmissionrpc/httphandler.py index 2968762e..02d65fa7 100644 --- a/core/transmissionrpc/httphandler.py +++ b/core/transmissionrpc/httphandler.py @@ -75,7 +75,7 @@ class DefaultHTTPHandler(HTTPHandler): if hasattr(error.reason, 'args') and isinstance(error.reason.args, tuple) and len(error.reason.args) == 2: raise HTTPHandlerError(httpcode=error.reason.args[0], httpmsg=error.reason.args[1]) else: - raise HTTPHandlerError(httpmsg='urllib2.URLError: %s' % (error.reason)) + raise HTTPHandlerError(httpmsg='urllib2.URLError: {error.reason}'.format(error=error)) except BadStatusLine as error: - raise HTTPHandlerError(httpmsg='httplib.BadStatusLine: %s' % (error.line)) + raise HTTPHandlerError(httpmsg='httplib.BadStatusLine: {error.line}'.format(error=error)) return response.read().decode('utf-8') diff --git a/core/transmissionrpc/session.py b/core/transmissionrpc/session.py index 6b620373..bb2c1560 100644 --- a/core/transmissionrpc/session.py +++ b/core/transmissionrpc/session.py @@ -27,12 +27,12 @@ class Session(object): try: return self._fields[name].value except KeyError: - raise AttributeError('No attribute %s' % name) + raise AttributeError('No attribute {0}'.format(name)) def __str__(self): text = '' for key in sorted(self._fields.keys()): - text += "% 32s: %s\n" % (key[-32:], self._fields[key].value) + text += "{0:32}: {1}\n".format(key[-32:], self._fields[key].value) return text def _update_fields(self, other): diff --git a/core/transmissionrpc/torrent.py b/core/transmissionrpc/torrent.py index 54ee2a2d..21d4f367 100644 --- a/core/transmissionrpc/torrent.py +++ b/core/transmissionrpc/torrent.py @@ -73,14 +73,14 @@ class Torrent(object): tid = self._fields['id'].value name = self._get_name_string() if isinstance(name, str): - return '' % (tid, name) + return ''.format(tid, name) else: - return '' % (tid) + return ''.format(tid) def __str__(self): name = self._get_name_string() if isinstance(name, str): - return 'Torrent \"%s\"' % (name) + return 'Torrent \"{0}\"'.format(name) else: return 'Torrent' @@ -91,7 +91,7 @@ class Torrent(object): try: return self._fields[name].value except KeyError: - raise AttributeError('No attribute %s' % name) + raise AttributeError('No attribute {0}'.format(name)) def _rpc_version(self): """Get the Transmission RPC API version.""" diff --git a/core/transmissionrpc/utils.py b/core/transmissionrpc/utils.py index 0ac2a32a..9381edac 100644 --- a/core/transmissionrpc/utils.py +++ b/core/transmissionrpc/utils.py @@ -40,7 +40,7 @@ def format_timedelta(delta): """ minutes, seconds = divmod(delta.seconds, 60) hours, minutes = divmod(minutes, 60) - return '%d %02d:%02d:%02d' % (delta.days, hours, minutes, seconds) + return '{0:d} {1:02d}:{2:02d}:{3:02d}'.format(delta.days, hours, minutes, seconds) def format_timestamp(timestamp, utc=False): @@ -80,17 +80,17 @@ def inet_address(address, default_port, default_address='localhost'): try: port = int(addr[1]) except ValueError: - raise INetAddressError('Invalid address "%s".' % address) + raise INetAddressError('Invalid address "{0}".'.format(address)) if len(addr[0]) == 0: addr = default_address else: addr = addr[0] else: - raise INetAddressError('Invalid address "%s".' % address) + raise INetAddressError('Invalid address "{0}".'.format(address)) try: socket.getaddrinfo(addr, port, socket.AF_INET, socket.SOCK_STREAM) except socket.gaierror: - raise INetAddressError('Cannot look up address "%s".' % address) + raise INetAddressError('Cannot look up address "{0}".'.format(address)) return addr, port @@ -139,7 +139,7 @@ def argument_value_convert(method, argument, value, rpc_version): elif method in ('session-get', 'session-set'): args = constants.SESSION_ARGS[method[-3:]] else: - return ValueError('Method "%s" not supported' % (method)) + return ValueError('Method "{0}" not supported'.format(method)) if argument in args: info = args[argument] invalid_version = True @@ -155,14 +155,12 @@ def argument_value_convert(method, argument, value, rpc_version): if invalid_version: if replacement: LOGGER.warning( - 'Replacing requested argument "%s" with "%s".' - % (argument, replacement)) + 'Replacing requested argument "{0}" with "{1}".'.format(argument, replacement)) argument = replacement info = args[argument] else: raise ValueError( - 'Method "%s" Argument "%s" does not exist in version %d.' - % (method, argument, rpc_version)) + 'Method "{0}" Argument "{1}" does not exist in version {2:d}.'.format(method, argument, rpc_version)) return argument, TR_TYPE_MAP[info[0]](value) else: raise ValueError('Argument "%s" does not exists for method "%s".', @@ -178,7 +176,7 @@ def get_arguments(method, rpc_version): elif method in ('session-get', 'session-set'): args = constants.SESSION_ARGS[method[-3:]] else: - return ValueError('Method "%s" not supported' % (method)) + return ValueError('Method "{0}" not supported'.format(method)) accessible = [] for argument, info in iteritems(args): valid_version = True diff --git a/core/utorrent/upload.py b/core/utorrent/upload.py index ddf228cc..f8db659c 100644 --- a/core/utorrent/upload.py +++ b/core/utorrent/upload.py @@ -16,7 +16,7 @@ class MultiPartForm(object): return def get_content_type(self): - return 'multipart/form-data; boundary=%s' % self.boundary + return 'multipart/form-data; boundary={0}'.format(self.boundary) def add_field(self, name, value): """Add a simple field to the form data.""" @@ -43,7 +43,7 @@ class MultiPartForm(object): # Add the form fields parts.extend( [part_boundary, - 'Content-Disposition: form-data; name="%s"' % name, + 'Content-Disposition: form-data; name="{0}"'.format(name), '', value, ] @@ -53,8 +53,8 @@ class MultiPartForm(object): # Add the files to upload parts.extend( [part_boundary, - 'Content-Disposition: file; name="%s"; filename="%s"' % (field_name, filename), - 'Content-Type: %s' % content_type, + 'Content-Disposition: file; name="{0}"; filename="{1}"'.format(field_name, filename), + 'Content-Type: {0}'.format(content_type), '', body, ] diff --git a/nzbToMedia.py b/nzbToMedia.py index 7c11c35a..c599e217 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -514,7 +514,7 @@ from core import logger, nzbToMediaDB def process(inputDirectory, inputName=None, status=0, clientAgent='manual', download_id=None, inputCategory=None, failureLink=None): if core.SAFE_MODE and inputDirectory == core.NZB_DEFAULTDIR: logger.error( - 'The input directory:[%s] is the Default Download Directory. Please configure category directories to prevent processing of other media.' % ( + 'The input directory:[{0}] is the Default Download Directory. Please configure category directories to prevent processing of other media.'.format( inputDirectory)) return [-1, ""] @@ -522,7 +522,7 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down download_id = get_nzoid(inputName) if clientAgent != 'manual' and not core.DOWNLOADINFO: - logger.debug('Adding NZB download info for directory %s to database' % (inputDirectory)) + logger.debug('Adding NZB download info for directory {0} to database'.format(inputDirectory)) myDB = nzbToMediaDB.DBConnection() @@ -555,7 +555,7 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down section = core.CFG.findsection("ALL").isenabled() if section is None: logger.error( - 'Category:[%s] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.' % ( + 'Category:[{0}] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.'.format( inputCategory)) return [-1, ""] else: @@ -563,15 +563,15 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down if len(section) > 1: logger.error( - 'Category:[%s] is not unique, %s are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.' % ( + 'Category:[{0}] is not unique, {1} are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.'.format( inputCategory, section.keys())) return [-1, ""] if section: sectionName = section.keys()[0] - logger.info('Auto-detected SECTION:%s' % (sectionName)) + logger.info('Auto-detected SECTION:{0}'.format(sectionName)) else: - logger.error("Unable to locate a section with subsection:%s enabled in your autoProcessMedia.cfg, exiting!" % ( + logger.error("Unable to locate a section with subsection:{0} enabled in your autoProcessMedia.cfg, exiting!".format( inputCategory)) return [-1, ""] @@ -582,20 +582,20 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down try: if int(section[usercat]['remote_path']) and not core.REMOTEPATHS: - logger.error('Remote Path is enabled for %s:%s but no Network mount points are defined. Please check your autoProcessMedia.cfg, exiting!' % ( + logger.error('Remote Path is enabled for {0}:{1} but no Network mount points are defined. Please check your autoProcessMedia.cfg, exiting!'.format( sectionName, inputCategory)) return [-1, ""] except: - logger.error('Remote Path %s is not valid for %s:%s Please set this to either 0 to disable or 1 to enable!' % ( + logger.error('Remote Path {0} is not valid for {1}:{2} Please set this to either 0 to disable or 1 to enable!'.format( section[usercat]['remote_path'], sectionName, inputCategory)) inputName, inputDirectory = convert_to_ascii(inputName, inputDirectory) if extract == 1: - logger.debug('Checking for archives to extract in directory: %s' % (inputDirectory)) + logger.debug('Checking for archives to extract in directory: {0}'.format(inputDirectory)) extractFiles(inputDirectory) - logger.info("Calling %s:%s to post-process:%s" % (sectionName, inputCategory, inputName)) + logger.info("Calling {0}:{1} to post-process:{2}".format(sectionName, inputCategory, inputName)) if sectionName == "CouchPotato": result = autoProcessMovie().process(sectionName, inputDirectory, inputName, status, clientAgent, download_id, @@ -636,11 +636,11 @@ def main(args, section=None): clientAgent = core.NZB_CLIENTAGENT logger.info("#########################################################") - logger.info("## ..::[%s]::.. ##" % os.path.basename(__file__)) + logger.info("## ..::[{0}]::.. ##".format(os.path.basename(__file__))) logger.info("#########################################################") # debug command line options - logger.debug("Options passed into nzbToMedia: %s" % args) + logger.debug("Options passed into nzbToMedia: {0}".format(args)) # Post-Processing Result result = [0, ""] @@ -650,15 +650,15 @@ def main(args, section=None): if os.environ.has_key('NZBOP_SCRIPTDIR'): # Check if the script is called from nzbget 11.0 or later if os.environ['NZBOP_VERSION'][0:5] < '11.0': - logger.error("NZBGet Version %s is not supported. Please update NZBGet." %(str(os.environ['NZBOP_VERSION']))) + logger.error("NZBGet Version {0} is not supported. Please update NZBGet.".format(os.environ['NZBOP_VERSION'])) sys.exit(core.NZBGET_POSTPROCESS_ERROR) - logger.info("Script triggered from NZBGet Version %s." %(str(os.environ['NZBOP_VERSION']))) + logger.info("Script triggered from NZBGet Version {0}.".format(os.environ['NZBOP_VERSION'])) # Check if the script is called from nzbget 13.0 or later if os.environ.has_key('NZBPP_TOTALSTATUS'): if not os.environ['NZBPP_TOTALSTATUS'] == 'SUCCESS': - logger.info("Download failed with status %s." %(os.environ['NZBPP_STATUS'])) + logger.info("Download failed with status {0}.".format(os.environ['NZBPP_STATUS'])) status = 1 else: @@ -745,16 +745,16 @@ def main(args, section=None): if not core.CFG[section][subsection].isenabled(): continue for dirName in getDirs(section, subsection, link = 'move'): - logger.info("Starting manual run for %s:%s - Folder:%s" % (section, subsection, dirName)) + logger.info("Starting manual run for {0}:{1} - Folder:{2}".format(section, subsection, dirName)) - logger.info("Checking database for download info for %s ..." % (os.path.basename(dirName))) + logger.info("Checking database for download info for {0} ...".format(os.path.basename(dirName))) core.DOWNLOADINFO = get_downloadInfo(os.path.basename(dirName), 0) if core.DOWNLOADINFO: logger.info( - "Found download info for %s, setting variables now ..." % (os.path.basename(dirName))) + "Found download info for {0}, setting variables now ...".format(os.path.basename(dirName))) else: logger.info( - 'Unable to locate download info for %s, continuing to try and process this release ...' % ( + 'Unable to locate download info for {0}, continuing to try and process this release ...'.format( os.path.basename(dirName)) ) @@ -781,19 +781,19 @@ def main(args, section=None): results = process(dirName, inputName, 0, clientAgent=clientAgent, download_id=download_id, inputCategory=subsection) if results[0] != 0: - logger.error("A problem was reported when trying to perform a manual run for %s:%s." % ( + logger.error("A problem was reported when trying to perform a manual run for {0}:{1}.".format( section, subsection)) result = results if result[0] == 0: - logger.info("The %s script completed successfully." % args[0]) + logger.info("The {0} script completed successfully.".format(args[0])) if result[1]: print result[1] + "!" # For SABnzbd Status display. if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 del core.MYAPP return (core.NZBGET_POSTPROCESS_SUCCESS) else: - logger.error("A problem was reported in the %s script." % args[0]) + logger.error("A problem was reported in the {0} script.".format(args[0])) if result[1]: print result[1] + "!" # For SABnzbd Status display. if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11