diff --git a/TorrentToMedia.py b/TorrentToMedia.py index 0e521575..79f6de76 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -31,7 +31,7 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp try: encoded, input_directory1 = char_replace(input_directory) encoded, input_name1 = char_replace(input_name) - except: + except Exception: pass control_value_dict = {"input_directory": text_type(input_directory1)} @@ -196,7 +196,7 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp try: core.copy_link(inputFile, target_file, core.USELINK) core.remove_read_only(target_file) - except: + except Exception: logger.error("Failed to link: {0} to {1}".format(inputFile, target_file)) input_name, output_destination = convert_to_ascii(input_name, output_destination) @@ -306,7 +306,7 @@ def main(args): try: input_directory, input_name, input_category, input_hash, input_id = core.parse_args(client_agent, args) - except: + except Exception: logger.error("There was a problem loading variables") return -1 diff --git a/core/__init__.py b/core/__init__.py index 0e73b883..b20f3d0b 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -281,7 +281,7 @@ def initialize(section=None): # pylint: disable=E1101 # On non-unicode builds this will raise an AttributeError, if encoding type is not valid it throws a LookupError sys.setdefaultencoding(SYS_ENCODING) - except: + except Exception: print('Sorry, you MUST add the nzbToMedia folder to the PYTHONPATH environment variable' '\nor find another way to force Python to use {codec} for string encoding.'.format (codec=SYS_ENCODING)) @@ -345,7 +345,7 @@ def initialize(section=None): # restart nzbToMedia try: del MYAPP - except: + except Exception: pass restart() else: @@ -426,22 +426,22 @@ def initialize(section=None): try: subprocess.Popen(["nice"], stdout=devnull, stderr=devnull).communicate() NICENESS.extend(['nice', '-n{0}'.format(int(CFG["Posix"]["niceness"]))]) - except: + except Exception: pass try: subprocess.Popen(["ionice"], stdout=devnull, stderr=devnull).communicate() try: NICENESS.extend(['ionice', '-c{0}'.format(int(CFG["Posix"]["ionice_class"]))]) - except: + except Exception: pass try: if 'ionice' in NICENESS: NICENESS.extend(['-n{0}'.format(int(CFG["Posix"]["ionice_classdata"]))]) else: NICENESS.extend(['ionice', '-n{0}'.format(int(CFG["Posix"]["ionice_classdata"]))]) - except: + except Exception: pass - except: + except Exception: pass devnull.close() @@ -480,7 +480,7 @@ def initialize(section=None): GENERALOPTS.append('+genpts') try: OUTPUTQUALITYPERCENT = int(CFG["Transcoder"]["outputQualityPercent"]) - except: + except Exception: pass OUTPUTVIDEOPATH = CFG["Transcoder"]["outputVideoPath"] PROCESSOUTPUT = int(CFG["Transcoder"]["processOutput"]) @@ -505,19 +505,19 @@ def initialize(section=None): VPRESET = CFG["Transcoder"]["outputVideoPreset"].strip() try: VFRAMERATE = float(CFG["Transcoder"]["outputVideoFramerate"].strip()) - except: + except Exception: pass try: VCRF = int(CFG["Transcoder"]["outputVideoCRF"].strip()) - except: + except Exception: pass try: VLEVEL = CFG["Transcoder"]["outputVideoLevel"].strip() - except: + except Exception: pass try: VBITRATE = int((CFG["Transcoder"]["outputVideoBitrate"].strip()).replace('k', '000')) - except: + except Exception: pass VRESOLUTION = CFG["Transcoder"]["outputVideoResolution"] ACODEC = CFG["Transcoder"]["outputAudioCodec"].strip() @@ -528,11 +528,11 @@ def initialize(section=None): ACODEC_ALLOW = [] try: ACHANNELS = int(CFG["Transcoder"]["outputAudioChannels"].strip()) - except: + except Exception: pass try: ABITRATE = int((CFG["Transcoder"]["outputAudioBitrate"].strip()).replace('k', '000')) - except: + except Exception: pass ACODEC2 = CFG["Transcoder"]["outputAudioTrack2Codec"].strip() ACODEC2_ALLOW = CFG["Transcoder"]["AudioCodec2Allow"].strip() @@ -542,11 +542,11 @@ def initialize(section=None): ACODEC2_ALLOW = [] try: ACHANNELS2 = int(CFG["Transcoder"]["outputAudioTrack2Channels"].strip()) - except: + except Exception: pass try: ABITRATE2 = int((CFG["Transcoder"]["outputAudioTrack2Bitrate"].strip()).replace('k', '000')) - except: + except Exception: pass ACODEC3 = CFG["Transcoder"]["outputAudioOtherCodec"].strip() ACODEC3_ALLOW = CFG["Transcoder"]["AudioOtherCodecAllow"].strip() @@ -556,11 +556,11 @@ def initialize(section=None): ACODEC3_ALLOW = [] try: ACHANNELS3 = int(CFG["Transcoder"]["outputAudioOtherChannels"].strip()) - except: + except Exception: pass try: ABITRATE3 = int((CFG["Transcoder"]["outputAudioOtherBitrate"].strip()).replace('k', '000')) - except: + except Exception: pass SCODEC = CFG["Transcoder"]["outputSubtitleCodec"].strip() BURN = int(CFG["Transcoder"]["burnInSubtitle"].strip()) @@ -765,17 +765,17 @@ def initialize(section=None): else: try: SEVENZIP = subprocess.Popen(['which', '7z'], stdout=subprocess.PIPE).communicate()[0].strip() - except: + except Exception: pass if not SEVENZIP: try: SEVENZIP = subprocess.Popen(['which', '7zr'], stdout=subprocess.PIPE).communicate()[0].strip() - except: + except Exception: pass if not SEVENZIP: try: SEVENZIP = subprocess.Popen(['which', '7za'], stdout=subprocess.PIPE).communicate()[0].strip() - except: + except Exception: pass if not SEVENZIP: SEVENZIP = None @@ -783,7 +783,7 @@ def initialize(section=None): "Failed to locate 7zip. Transcoding of disk images and extraction of .7z files will not be possible!") try: PAR2CMD = subprocess.Popen(['which', 'par2'], stdout=subprocess.PIPE).communicate()[0].strip() - except: + except Exception: pass if not PAR2CMD: PAR2CMD = None @@ -798,12 +798,12 @@ def initialize(section=None): else: try: FFMPEG = subprocess.Popen(['which', 'ffmpeg'], stdout=subprocess.PIPE).communicate()[0].strip() - except: + except Exception: pass if not FFMPEG: try: FFMPEG = subprocess.Popen(['which', 'avconv'], stdout=subprocess.PIPE).communicate()[0].strip() - except: + except Exception: pass if not FFMPEG: FFMPEG = None @@ -819,12 +819,12 @@ def initialize(section=None): else: try: FFPROBE = subprocess.Popen(['which', 'ffprobe'], stdout=subprocess.PIPE).communicate()[0].strip() - except: + except Exception: pass if not FFPROBE: try: FFPROBE = subprocess.Popen(['which', 'avprobe'], stdout=subprocess.PIPE).communicate()[0].strip() - except: + except Exception: pass if not FFPROBE: FFPROBE = None diff --git a/core/auto_process/games.py b/core/auto_process/games.py index 19ecc63a..28183095 100644 --- a/core/auto_process/games.py +++ b/core/auto_process/games.py @@ -60,7 +60,7 @@ class Game(object): logger.postprocess("moving files to library: {0}".format(library), section) try: shutil.move(dir_name, os.path.join(library, input_name)) - except: + except Exception: logger.error("Unable to move {0} to {1}".format(dir_name, os.path.join(library, input_name)), section) return [1, "{0}: Failed to post-process - Unable to move files".format(section)] else: diff --git a/core/auto_process/movies.py b/core/auto_process/movies.py index 9717c01d..00f15e84 100644 --- a/core/auto_process/movies.py +++ b/core/auto_process/movies.py @@ -75,7 +75,7 @@ class Movie(object): download_id = release[release_id]['download_info']['id'] downloader = release[release_id]['download_info']['downloader'] release_status_old = release[release_id]['status'] - except: + except Exception: pass if not os.path.isdir(dir_name) and os.path.isfile(dir_name): # If the input directory is a file, assume single file download and split dir/name. @@ -300,7 +300,7 @@ class Movie(object): logger.postprocess("SUCCESS: Release for {0} has now been marked with a status of [{1}]".format( title, str(release_status_new).upper()), section) return [0, "{0}: Successfully post-processed {1}".format(section, input_name)] - except: + except Exception: pass elif scan_id: url = "{0}/{1}".format(base_url, scan_id) @@ -416,7 +416,7 @@ class Movie(object): id = result[section]['_id'] results[id] = result[section] return results - except: + except Exception: pass # Gather release info and proceed with trying to narrow results to one release choice @@ -441,7 +441,7 @@ class Movie(object): id = release['_id'] results[id] = release results[id]['title'] = movie['title'] - except: + except Exception: continue # Narrow results by removing old releases by comparing their last_edit field @@ -451,7 +451,7 @@ class Movie(object): try: if x2["last_edit"] > x1["last_edit"]: results.pop(id1) - except: + except Exception: continue # Search downloads on clients for a match to try and narrow our results down to 1 @@ -460,7 +460,7 @@ class Movie(object): try: if not find_download(str(x['download_info']['downloader']).lower(), x['download_info']['id']): results.pop(id) - except: + except Exception: continue return results diff --git a/core/configuration.py b/core/configuration.py index 64a04c6d..d469ad67 100644 --- a/core/configuration.py +++ b/core/configuration.py @@ -18,7 +18,7 @@ class Section(configobj.Section, object): if not section.sections: try: value = list(ConfigObj.find_key(section, 'enabled'))[0] - except: + except Exception: value = 0 if int(value) == 1: return section @@ -28,7 +28,7 @@ class Section(configobj.Section, object): for subsection in subsections: try: value = list(ConfigObj.find_key(subsections, 'enabled'))[0] - except: + except Exception: value = 0 if int(value) != 1: @@ -45,7 +45,7 @@ class Section(configobj.Section, object): for subsection in to_return: try: value = list(ConfigObj.find_key(to_return[subsection], key))[0] - except: + except Exception: value = None if not value: @@ -198,7 +198,7 @@ class ConfigObj(configobj.ConfigObj, Section): if not list(ConfigObj.find_key(CFG_NEW, option)): try: values.pop(option) - except: + except Exception: pass return values diff --git a/core/extractor/__init__.py b/core/extractor/__init__.py index a1ed8457..03005662 100644 --- a/core/extractor/__init__.py +++ b/core/extractor/__init__.py @@ -147,7 +147,7 @@ def extract(file_path, output_destination): break else: continue - except: + except Exception: core.logger.error("EXTRACTOR: Extraction failed for {file}. " "Could not call command {cmd}".format (file=file_path, cmd=cmd)) @@ -165,13 +165,13 @@ def extract(file_path, output_destination): if not os.path.join(dir, subdir) in orig_files: try: os.chmod(os.path.join(dir, subdir), perms) - except: + except Exception: pass for file in files: if not os.path.join(dir, file) in orig_files: try: shutil.copymode(file_path, os.path.join(dir, file)) - except: + except Exception: pass return True else: diff --git a/core/forks.py b/core/forks.py index c15879c2..5cf4e5f1 100644 --- a/core/forks.py +++ b/core/forks.py @@ -82,7 +82,7 @@ def auto_fork(section, input_category): optional_parameters = [] try: optional_parameters = r.json()['data']['optionalParameters'].keys() - except: + except Exception: optional_parameters = r.json()['data']['data']['optionalParameters'].keys() for param in params: if param not in optional_parameters: diff --git a/core/scene_exceptions.py b/core/scene_exceptions.py index dafc2b6a..aa85326e 100644 --- a/core/scene_exceptions.py +++ b/core/scene_exceptions.py @@ -177,7 +177,7 @@ def par2(dirname): proc = subprocess.Popen(command, stdout=bitbucket, stderr=bitbucket) proc.communicate() result = proc.returncode - except: + except Exception: logger.error("par2 file processing for {0} has failed".format(parfile), "PAR2") if result == 0: logger.info("par2 file processing succeeded", "PAR2") diff --git a/core/transcoder.py b/core/transcoder.py index b3727ee1..fc4bb4e0 100644 --- a/core/transcoder.py +++ b/core/transcoder.py @@ -69,7 +69,7 @@ def zip_out(file, img, bitbucket): cmd = [core.SEVENZIP, '-so', 'e', img, file] try: procin = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=bitbucket) - except: + except Exception: logger.error("Extracting [{0}] has failed".format(file), 'TRANSCODER') return procin @@ -99,7 +99,7 @@ def get_video_details(videofile, img=None, bitbucket=None): out, err = proc.communicate() result = proc.returncode video_details = json.loads(out) - except: + except Exception: pass if not video_details: try: @@ -113,7 +113,7 @@ def get_video_details(videofile, img=None, bitbucket=None): out, err = proc.communicate() result = proc.returncode video_details = json.loads(out) - except: + except Exception: logger.error("Checking [{0}] has failed".format(file), 'TRANSCODER') return video_details, result @@ -265,23 +265,23 @@ def build_commands(file, new_dir, movie_name, bitbucket): if "Commentary" in val.get("tags").get("title"): # Split out commentry tracks. commentary.append(val) del audio_streams[i] - except: + except Exception: continue try: audio1 = [item for item in audio_streams if item["tags"]["language"] == core.ALANGUAGE] - except: # no language tags. Assume only 1 language. + except Exception: # no language tags. Assume only 1 language. audio1 = audio_streams try: audio2 = [item for item in audio1 if item["codec_name"] in core.ACODEC_ALLOW] - except: + except Exception: audio2 = [] try: audio3 = [item for item in audio_streams if item["tags"]["language"] != core.ALANGUAGE] - except: + except Exception: audio3 = [] try: audio4 = [item for item in audio3 if item["codec_name"] in core.ACODEC_ALLOW] - except: + except Exception: audio4 = [] if audio2: # right (or only) language and codec... @@ -328,11 +328,11 @@ def build_commands(file, new_dir, movie_name, bitbucket): used_audio += 1 try: audio5 = [item for item in audio1 if item["codec_name"] in core.ACODEC2_ALLOW] - except: + except Exception: audio5 = [] try: audio6 = [item for item in audio3 if item["codec_name"] in core.ACODEC2_ALLOW] - except: + except Exception: audio6 = [] if audio5: # right language and codec. map_cmd.extend(['-map', '0:{index}'.format(index=audio5[0]["index"])]) @@ -425,7 +425,7 @@ def build_commands(file, new_dir, movie_name, bitbucket): for lan in core.SLANGUAGES: try: subs1 = [item for item in sub_streams if item["tags"]["language"] == lan] - except: + except Exception: subs1 = [] if core.BURN and not subs1 and not burnt and os.path.isfile(file): for subfile in get_subs(file): @@ -489,7 +489,7 @@ def build_commands(file, new_dir, movie_name, bitbucket): metlan = Language(lan) if len(lan) == 2: metlan = Language.fromalpha2(lan) - except: + except Exception: pass if metlan: meta_cmd.extend(['-metadata:s:s:{x}'.format(x=len(s_mapped) + n), @@ -544,7 +544,7 @@ def extract_subs(file, newfile_path, bitbucket): sub_streams = [item for item in video_details["streams"] if item["codec_type"] == "subtitle" and item["tags"]["language"] in core.SLANGUAGES and item[ "codec_name"] != "hdmv_pgs_subtitle" and item["codec_name"] != "pgssub"] - except: + except Exception: sub_streams = [item for item in video_details["streams"] if item["codec_type"] == "subtitle" and item["codec_name"] != "hdmv_pgs_subtitle" and item[ "codec_name"] != "pgssub"] @@ -575,13 +575,13 @@ def extract_subs(file, newfile_path, bitbucket): proc = subprocess.Popen(command, stdout=bitbucket, stderr=bitbucket) proc.communicate() result = proc.returncode - except: + except Exception: logger.error("Extracting subtitle has failed") if result == 0: try: shutil.copymode(file, output_file) - except: + except Exception: pass logger.info("Extracting {0} subtitle from {1} has succeeded".format(lan, file)) else: @@ -605,7 +605,7 @@ def process_list(it, new_dir, bitbucket): if not vts_path: try: vts_path = re.match("(.+VIDEO_TS)", item).groups()[0] - except: + except Exception: vts_path = os.path.split(item)[0] rem_list.append(item) elif re.match(".+VIDEO_TS.", item) or re.match(".+VTS_[0-9][0-9]_[0-9].", item): @@ -677,7 +677,7 @@ def rip_iso(item, new_dir, bitbucket): if not new_files: logger.error("No VIDEO_TS folder found in image file {0}".format(item), "TRANSCODER") new_files = [failure_dir] - except: + except Exception: logger.error("Failed to extract from image file {0}".format(item), "TRANSCODER") new_files = [failure_dir] return new_files @@ -788,7 +788,7 @@ def transcode_directory(dir_name): procin.stdout.close() proc.communicate() result = proc.returncode - except: + except Exception: logger.error("Transcoding of video {0} has failed".format(newfile_path)) if core.SUBSDIR and result == 0 and isinstance(file, string_types): @@ -803,13 +803,13 @@ def transcode_directory(dir_name): if result == 0: try: shutil.copymode(file, newfile_path) - except: + except Exception: pass logger.info("Transcoding of video to {0} succeeded".format(newfile_path)) if os.path.isfile(newfile_path) and (file in new_list or not core.DUPLICATE): try: os.unlink(file) - except: + except Exception: pass else: logger.error("Transcoding of video to {0} failed with result {1}".format(newfile_path, result)) @@ -819,7 +819,7 @@ def transcode_directory(dir_name): for file in rem_list: try: os.unlink(file) - except: + except Exception: pass if not os.listdir(text_type(new_dir)): # this is an empty directory and we didn't transcode into it. os.rmdir(new_dir) diff --git a/core/user_scripts.py b/core/user_scripts.py index 6eae29f5..1fc97dc5 100644 --- a/core/user_scripts.py +++ b/core/user_scripts.py @@ -15,7 +15,7 @@ def external_script(output_destination, torrent_name, torrent_label, settings): core.USER_SCRIPT_MEDIAEXTENSIONS = settings["user_script_mediaExtensions"].lower() if isinstance(core.USER_SCRIPT_MEDIAEXTENSIONS, str): core.USER_SCRIPT_MEDIAEXTENSIONS = core.USER_SCRIPT_MEDIAEXTENSIONS.split(',') - except: + except Exception: core.USER_SCRIPT_MEDIAEXTENSIONS = [] core.USER_SCRIPT = settings.get("user_script_path") @@ -26,13 +26,13 @@ def external_script(output_destination, torrent_name, torrent_label, settings): core.USER_SCRIPT_PARAM = settings["user_script_param"] if isinstance(core.USER_SCRIPT_PARAM, str): core.USER_SCRIPT_PARAM = core.USER_SCRIPT_PARAM.split(',') - except: + except Exception: core.USER_SCRIPT_PARAM = [] try: core.USER_SCRIPT_SUCCESSCODES = settings["user_script_successCodes"] if isinstance(core.USER_SCRIPT_SUCCESSCODES, str): core.USER_SCRIPT_SUCCESSCODES = core.USER_SCRIPT_SUCCESSCODES.split(',') - except: + except Exception: core.USER_SCRIPT_SUCCESSCODES = 0 core.USER_SCRIPT_CLEAN = int(settings.get("user_script_clean", 1)) @@ -95,7 +95,7 @@ def external_script(output_destination, torrent_name, torrent_label, settings): "If the UserScript completed successfully you should add {0} to the user_script_successCodes".format( res), "USERSCRIPT") result = int(1) - except: + except Exception: logger.error("UserScript {0} has failed".format(command[0]), "USERSCRIPT") result = int(1) final_result += result diff --git a/core/utils.py b/core/utils.py index 7189cce6..9784f5f7 100644 --- a/core/utils.py +++ b/core/utils.py @@ -90,7 +90,7 @@ def sanitize_name(name): name = name.strip(' .') try: name = name.encode(core.SYS_ENCODING) - except: + except Exception: pass return name @@ -128,11 +128,11 @@ def category_search(input_directory, input_name, input_category, root, categorie try: input_name = input_name.encode(core.SYS_ENCODING) - except: + except Exception: pass try: input_directory = input_directory.encode(core.SYS_ENCODING) - except: + except Exception: pass if input_directory is None: # =Nothing to process here. @@ -233,7 +233,7 @@ def is_min_size(input_name, min_size): if file_ext in core.AUDIOCONTAINER: try: input_size = get_dir_size(os.path.dirname(input_name)) - except: + except Exception: logger.error("Failed to get file size for {0}".format(input_name), 'MINSIZE') return True @@ -335,7 +335,7 @@ def flatten(output_destination): try: shutil.move(outputFile, target) - except: + except Exception: logger.error("Could not flatten {0}".format(outputFile), 'FLATTEN') remove_empty_folders(output_destination) # Cleanup empty directories @@ -372,7 +372,7 @@ def remove_read_only(filename): (name=filename)) try: os.chmod(filename, stat.S_IWRITE) - except: + except Exception: logger.warning('Cannot change permissions of {file}'.format(file=filename), logger.WARNING) @@ -403,7 +403,7 @@ def test_connection(host, port): try: socket.create_connection((host, port)) return "Up" - except: + except Exception: return "Down" @@ -515,19 +515,19 @@ def parse_rtorrent(args): input_directory = os.path.normpath(args[1]) try: input_name = args[2] - except: + except Exception: input_name = '' try: input_category = args[3] - except: + except Exception: input_category = '' try: input_hash = args[4] - except: + except Exception: input_hash = '' try: input_id = args[4] - except: + except Exception: input_id = '' return input_directory, input_name, input_category, input_hash, input_id @@ -539,15 +539,15 @@ def parse_utorrent(args): input_name = args[2] try: input_category = args[3] - except: + except Exception: input_category = '' try: input_hash = args[4] - except: + except Exception: input_hash = '' try: input_id = args[4] - except: + except Exception: input_id = '' return input_directory, input_name, input_category, input_hash, input_id @@ -561,7 +561,7 @@ def parse_deluge(args): input_id = args[1] try: input_category = core.TORRENT_CLASS.core.get_torrent_status(input_id, ['label']).get()['label'] - except: + except Exception: input_category = '' return input_directory, input_name, input_category, input_hash, input_id @@ -580,32 +580,32 @@ def parse_vuze(args): # vuze usage: C:\full\path\to\nzbToMedia\TorrentToMedia.py "%D%N%L%I%K%F" try: input = args[1].split(',') - except: + except Exception: input = [] try: input_directory = os.path.normpath(input[0]) - except: + except Exception: input_directory = '' try: input_name = input[1] - except: + except Exception: input_name = '' try: input_category = input[2] - except: + except Exception: input_category = '' try: input_hash = input[3] - except: + except Exception: input_hash = '' try: input_id = input[3] - except: + except Exception: input_id = '' try: if input[4] == 'single': input_name = input[5] - except: + except Exception: pass return input_directory, input_name, input_category, input_hash, input_id @@ -615,27 +615,27 @@ def parse_qbittorrent(args): # qbittorrent usage: C:\full\path\to\nzbToMedia\TorrentToMedia.py "%D|%N|%L|%I" try: input = args[1].split('|') - except: + except Exception: input = [] try: input_directory = os.path.normpath(input[0].replace('"', '')) - except: + except Exception: input_directory = '' try: input_name = input[1].replace('"', '') - except: + except Exception: input_name = '' try: input_category = input[2].replace('"', '') - except: + except Exception: input_category = '' try: input_hash = input[3].replace('"', '') - except: + except Exception: input_hash = '' try: input_id = input[3].replace('"', '') - except: + except Exception: input_id = '' return input_directory, input_name, input_category, input_hash, input_id @@ -654,7 +654,7 @@ def parse_args(client_agent, args): try: return clients[client_agent](args) - except: + except Exception: return None, None, None, None, None @@ -706,7 +706,7 @@ def get_dirs(section, subsection, link='hard'): try: new_path = new_path.encode(core.SYS_ENCODING) - except: + except Exception: pass # Just fail-safe incase we already have afile with this clean-name (was actually a bug from earlier code, but let's be safe). @@ -721,7 +721,7 @@ def get_dirs(section, subsection, link='hard'): newfile = os.path.join(new_path, sanitize_name(os.path.split(mediafile)[1])) try: newfile = newfile.encode(core.SYS_ENCODING) - except: + except Exception: pass # link file to its new path @@ -787,7 +787,7 @@ def remove_dir(dir_name): logger.info("Deleting {0}".format(dir_name)) try: shutil.rmtree(text_type(dir_name), onerror=onerror) - except: + except Exception: logger.error("Unable to delete folder {0}".format(dir_name)) @@ -804,7 +804,7 @@ def clean_dir(path, section, subsection): delete_ignored = int(cfg.get('delete_ignored', 0)) try: num_files = len(list_media_files(path, min_size=min_size, delete_ignored=delete_ignored)) - except: + except Exception: num_files = 'unknown' if num_files > 0: logger.info( @@ -815,7 +815,7 @@ def clean_dir(path, section, subsection): logger.info("Directory {0} has been processed, removing ...".format(path), 'CLEANDIRS') try: shutil.rmtree(path, onerror=onerror) - except: + except Exception: logger.error("Unable to delete directory {0}".format(path)) @@ -827,7 +827,7 @@ def create_torrent_class(client_agent): try: logger.debug("Connecting to {0}: {1}".format(client_agent, core.UTORRENTWEBUI)) tc = UTorrentClient(core.UTORRENTWEBUI, core.UTORRENTUSR, core.UTORRENTPWD) - except: + except Exception: logger.error("Failed to connect to uTorrent") if client_agent == 'transmission': @@ -837,7 +837,7 @@ def create_torrent_class(client_agent): tc = TransmissionClient(core.TRANSMISSIONHOST, core.TRANSMISSIONPORT, core.TRANSMISSIONUSR, core.TRANSMISSIONPWD) - except: + except Exception: logger.error("Failed to connect to Transmission") if client_agent == 'deluge': @@ -846,7 +846,7 @@ def create_torrent_class(client_agent): tc = DelugeClient() tc.connect(host=core.DELUGEHOST, port=core.DELUGEPORT, username=core.DELUGEUSR, password=core.DELUGEPWD) - except: + except Exception: logger.error("Failed to connect to Deluge") if client_agent == 'qbittorrent': @@ -854,7 +854,7 @@ def create_torrent_class(client_agent): logger.debug("Connecting to {0}: http://{1}:{2}".format(client_agent, core.QBITTORRENTHOST, core.QBITTORRENTPORT)) tc = qBittorrentClient("http://{0}:{1}/".format(core.QBITTORRENTHOST, core.QBITTORRENTPORT)) tc.login(core.QBITTORRENTUSR, core.QBITTORRENTPWD) - except: + except Exception: logger.error("Failed to connect to qBittorrent") return tc @@ -872,7 +872,7 @@ def pause_torrent(client_agent, input_hash, input_id, input_name): if client_agent == 'qbittorrent' and core.TORRENT_CLASS != "": core.TORRENT_CLASS.pause(input_hash) time.sleep(5) - except: + except Exception: logger.warning("Failed to stop torrent {0} in {1}".format(input_name, client_agent)) @@ -890,7 +890,7 @@ def resume_torrent(client_agent, input_hash, input_id, input_name): if client_agent == 'qbittorrent' and core.TORRENT_CLASS != "": core.TORRENT_CLASS.resume(input_hash) time.sleep(5) - except: + except Exception: logger.warning("Failed to start torrent {0} in {1}".format(input_name, client_agent)) @@ -908,7 +908,7 @@ def remove_torrent(client_agent, input_hash, input_id, input_name): if client_agent == 'qbittorrent' and core.TORRENT_CLASS != "": core.TORRENT_CLASS.delete_permanently(input_hash) time.sleep(5) - except: + except Exception: logger.warning("Failed to delete torrent {0} in {1}".format(input_name, client_agent)) else: resume_torrent(client_agent, input_hash, input_id, input_name) @@ -981,7 +981,7 @@ def get_nzoid(input_name): result = r.json() clean_name = os.path.splitext(os.path.split(input_name)[1])[0] slots.extend([(slot['nzo_id'], slot['filename']) for slot in result['queue']['slots']]) - except: + except Exception: logger.warning("Data from SABnzbd queue could not be parsed") params['mode'] = "history" try: @@ -993,7 +993,7 @@ def get_nzoid(input_name): result = r.json() clean_name = os.path.splitext(os.path.split(input_name)[1])[0] slots.extend([(slot['nzo_id'], slot['name']) for slot in result['history']['slots']]) - except: + except Exception: logger.warning("Data from SABnzbd history could not be parsed") try: for nzo_id, name in slots: @@ -1001,7 +1001,7 @@ def get_nzoid(input_name): nzoid = nzo_id logger.debug("Found nzoid: {0}".format(nzoid)) break - except: + except Exception: logger.warning("Data from SABnzbd could not be parsed") return nzoid @@ -1039,7 +1039,7 @@ def is_media_file(mediafile, media=True, audio=True, meta=True, archives=True, o # ignore MAC OS's "resource fork" files if file_name.startswith('._'): return False - except: + except Exception: pass if (media and file_ext.lower() in core.MEDIACONTAINER) \ or (audio and file_ext.lower() in core.AUDIOCONTAINER) \ @@ -1064,7 +1064,7 @@ def list_media_files(path, min_size=0, delete_ignored=0, media=True, audio=True, os.unlink(path) logger.debug('Ignored file {0} has been removed ...'.format (cur_file)) - except: + except Exception: pass else: files.append(path) @@ -1086,7 +1086,7 @@ def list_media_files(path, min_size=0, delete_ignored=0, media=True, audio=True, os.unlink(full_cur_file) logger.debug('Ignored file {0} has been removed ...'.format (cur_file)) - except: + except Exception: pass continue @@ -1126,7 +1126,7 @@ def find_imdbid(dir_name, input_name, omdb_api_key): logger.info('Searching IMDB for imdbID ...') try: guess = guessit.guessit(input_name) - except: + except Exception: guess = None if guess: # Movie Title @@ -1156,12 +1156,12 @@ def find_imdbid(dir_name, input_name, omdb_api_key): try: results = r.json() - except: + except Exception: logger.error("No json data returned from omdbapi.com") try: imdbid = results['imdbID'] - except: + except Exception: logger.error("No imdbID returned from omdbapi.com") if imdbid: @@ -1214,14 +1214,14 @@ def import_subs(filename): return try: subliminal.region.configure('dogpile.cache.dbm', arguments={'filename': 'cachefile.dbm'}) - except: + except Exception: pass languages = set() for item in core.SLANGUAGES: try: languages.add(Language(item)) - except: + except Exception: pass if not languages: return @@ -1361,7 +1361,7 @@ class PosixProcess(object): # Make sure it is not a "stale" pidFile try: pid = int(open(self.pidpath, 'r').read().strip()) - except: + except Exception: pid = None # Check list of running pids, if not running it is stale so overwrite if isinstance(pid, int): @@ -1381,7 +1381,7 @@ class PosixProcess(object): fp = open(self.pidpath, 'w') fp.write(str(os.getpid())) fp.close() - except: + except Exception: pass return self.lasterror diff --git a/core/version_check.py b/core/version_check.py index e8bad6ca..4c46d03e 100644 --- a/core/version_check.py +++ b/core/version_check.py @@ -285,7 +285,7 @@ class GitUpdateManager(UpdateManager): self._num_commits_behind = int(output.count("<")) self._num_commits_ahead = int(output.count(">")) - except: + except Exception: logger.log(u"git didn't return numbers for behind and ahead, not using it", logger.DEBUG) return diff --git a/nzbToMedia.py b/nzbToMedia.py index 862231e1..8f48f7db 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -664,7 +664,7 @@ def process(input_directory, input_name=None, status=0, client_agent='manual', d try: encoded, input_directory1 = char_replace(input_directory) encoded, input_name1 = char_replace(input_name) - except: + except Exception: pass control_value_dict = {"input_directory": text_type(input_directory1)} @@ -716,7 +716,7 @@ def process(input_directory, input_name=None, status=0, client_agent='manual', d logger.error('Remote Path is enabled for {0}:{1} but no Network mount points are defined. Please check your autoProcessMedia.cfg, exiting!'.format( section_name, input_category)) return [-1, ""] - except: + except Exception: logger.error('Remote Path {0} is not valid for {1}:{2} Please set this to either 0 to disable or 1 to enable!'.format( core.get("remote_path"), section_name, input_category))