From 7d8a0eef528103fbae20f378a595f7811784264c Mon Sep 17 00:00:00 2001 From: JackDandy Date: Wed, 2 Dec 2020 15:57:09 +0000 Subject: [PATCH] Change remove unused code and fix a couple of pyc flagged items. Change Tidy helpers --- lib/sg_helpers.py | 31 ++++++++++++------- sickbeard/_legacy.py | 44 --------------------------- sickbeard/helpers.py | 11 ++++--- sickbeard/webserve.py | 82 ++------------------------------------------------- 4 files changed, 27 insertions(+), 141 deletions(-) diff --git a/lib/sg_helpers.py b/lib/sg_helpers.py index d367956..98968e4 100644 --- a/lib/sg_helpers.py +++ b/lib/sg_helpers.py @@ -36,18 +36,28 @@ from _23 import decode_bytes, filter_list, html_unescape, list_range, \ from six import integer_types, iteritems, iterkeys, itervalues, PY2, string_types, text_type import zipfile -try: - import py7zr -except ImportError: - py7zr = None +# py7z hardwired removed, see comment below +py7zr = None # noinspection PyUnreachableCode if False: + from _23 import DirEntry + from lxml_etree import etree + try: + # py7z hardwired removed because Python 3.9 interpretor crashes with a process kill signal 9 when memory is + # low/exhausted during a native 7z compress action on Linux. Therefore, the native functions cannot be trusted. + # `import` moved to this non-runtime scope to preserve code resolution in case reinstated at a later PY release + # noinspection PyUnresolvedReferences,PyPackageRequirements + import py7zr + except ImportError: + py7zr = None + # sickbeard is strictly used here for resolution, this is only possible because + # this section is not used at runtime which would create circular reference issues + # noinspection PyPep8Naming + from sickbeard import db, notifiers as NOTIFIERS # noinspection PyUnresolvedReferences from typing import Any, AnyStr, Dict, Generator, NoReturn, integer_types, Iterable, Iterator, List, Optional, \ Tuple, Union - from lxml_etree import etree - from _23 import DirEntry # global tmdb_info cache _TMDB_INFO_CACHE = {'date': datetime.datetime(2000, 1, 1), 'data': None} @@ -101,10 +111,12 @@ USER_AGENT = '' CACHE_DIR = None DATA_DIR = None PROXY_SETTING = None -NOTIFIERS = None TRASH_REMOVE_SHOW = False +# noinspection PyRedeclaration db = None +# noinspection PyRedeclaration +NOTIFIERS = None class ConnectionFailTypes(object): @@ -1124,7 +1136,7 @@ def fix_set_group_id(child_path): logger.debug(u'Respecting the set-group-ID bit on the parent directory for %s' % child_path) except OSError: logger.error(u'Failed to respect the set-group-id bit on the parent directory for %s (setting group id %i)' - % (child_path, parent_gid)) + % (child_path, parent_gid)) def copy_file(src_file, dest_file): @@ -1376,9 +1388,6 @@ def compress_file(target, filename, prefer_7z=True, remove_source=True): :return: success of compression """ try: - # py7z is hardwired removed because Python 3.9 interpretor crashes with a process kill signal 9 when memory is - # low/exhausted during a native 7z compress action on Linux. Therefore, the native functions cannot be trusted - prefer_7z = False and prefer_7z if prefer_7z and None is not py7zr: z_name = '%s.7z' % target.rpartition('.')[0] with py7zr.SevenZipFile(z_name, 'w') as z_file: diff --git a/sickbeard/_legacy.py b/sickbeard/_legacy.py index e672a2d..0eaebf8 100644 --- a/sickbeard/_legacy.py +++ b/sickbeard/_legacy.py @@ -407,14 +407,6 @@ class LegacyBaseHandler(LegacyBase): # abstract method pass - def sanitizeFileName(self, *args): - # todo: find where this is called in JS or tmpl, the old name must still be used as refactor didnt find it - return self.sanitize_file_name(*args) - - def sanitize_file_name(self, *args): - # abstract method - pass - def searchIndexersForShowName(self, *args, **kwargs): return self.search_tvinfo_for_showname(*args, **kwargs) @@ -508,15 +500,6 @@ class LegacyBaseHandler(LegacyBase): # abstract method pass - def saveNewznabProvider(self, *args, **kwargs): - # todo: find where this is called in JS or tmpl, the old name must still be used as refactor didnt find it - return self.save_newznab_provider(*args, **kwargs) - - @staticmethod - def save_newznab_provider(*args, **kwargs): - # abstract method - pass - def getNewznabCategories(self, *args): return self.get_newznab_categories(*args) @@ -525,15 +508,6 @@ class LegacyBaseHandler(LegacyBase): # abstract method pass - def deleteNewznabProvider(self, *args): - # todo: find where this is called in JS or tmpl, the old name must still be used as refactor didnt find it - return self.delete_newznab_provider(*args) - - @staticmethod - def delete_newznab_provider(*args): - # abstract method - pass - def canAddTorrentRssProvider(self, *args): return self.can_add_torrent_rss_provider(*args) @@ -542,24 +516,6 @@ class LegacyBaseHandler(LegacyBase): # abstract method pass - def saveTorrentRssProvider(self, *args): - # todo: find where this is called in JS or tmpl, the old name must still be used as refactor didnt find it - return self.save_torrent_rss_provider(*args) - - @staticmethod - def save_torrent_rss_provider(*args): - # abstract method - pass - - def deleteTorrentRssProvider(self, **kwargs): - # todo: find where this is called in JS or tmpl, the old name must still be used as refactor didnt find it - return self.delete_torrent_rss_provider(kwargs.get('id')) - - @staticmethod - def delete_torrent_rss_provider(*args): - # abstract method - pass - def checkProvidersPing(self): return self.check_providers_ping() diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index 8a5936c..beb62dc 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -52,8 +52,8 @@ import requests.exceptions import subliminal from lxml_etree import etree, is_lxml -from _23 import b64decodebytes, b64encodebytes, decode_bytes, decode_str, filter_iter, Popen, scandir -from six import iteritems, PY2, string_types, text_type +from _23 import b64decodebytes, b64encodebytes, decode_bytes, decode_str, filter_iter, scandir +from six import iteritems, string_types, text_type # noinspection PyUnresolvedReferences from six.moves import zip @@ -269,7 +269,7 @@ def make_dir(path): if not ek.ek(os.path.isdir, path): try: ek.ek(os.makedirs, path) - # do the library update for synoindex + # do a Synology library update notifiers.NotifierFactory().get('SYNOINDEX').addFolder(path) except OSError: return False @@ -542,7 +542,7 @@ def delete_empty_folders(check_empty_dir, keep_dir=None): logger.log(u"Deleting empty folder: " + check_empty_dir) # need shutil.rmtree when ignore_items is really implemented ek.ek(os.rmdir, check_empty_dir) - # do the library update for synoindex + # do a Synology library update notifiers.NotifierFactory().get('SYNOINDEX').deleteFolder(check_empty_dir) except OSError as e: logger.log(u"Unable to delete " + check_empty_dir + ": " + repr(e) + " / " + ex(e), logger.WARNING) @@ -1309,8 +1309,7 @@ def check_port(host, port, timeout=1.0): s = None try: s = socket.socket(af, socktype, proto) - # See http://groups.google.com/group/cherrypy-users/ - # browse_frm/thread/bbfe5eb39c904fe0 + # See http://groups.google.com/group/cherrypy-users/browse_frm/thread/bbfe5eb39c904fe0 s.settimeout(timeout) s.connect((host, port)) s.close() diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index f0d7bf3..33ad65f 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -3391,10 +3391,6 @@ class AddShows(Home): return json.dumps({'results': result}) @staticmethod - def sanitize_file_name(name): - return helpers.sanitize_filename(name) - - @staticmethod def generate_show_dir_name(show_name): return helpers.generate_show_dir_name(None, show_name) @@ -5468,7 +5464,7 @@ class Manage(MainHandler): my_db = db.DBConnection() # noinspection SqlResolve sql_result = my_db.select( - 'SELECT tv_episodes.subtitles subtitles, show_name,' + 'SELECT tv_episodes.subtitles as subtitles, show_name,' ' tv_shows.indexer AS tv_id, tv_shows.indexer_id AS prod_id' ' FROM tv_episodes, tv_shows' ' WHERE tv_shows.subtitles = 1' @@ -7554,29 +7550,6 @@ class ConfigProviders(Config): return json.dumps({'success': temp_provider.get_id()}) @staticmethod - def save_newznab_provider(name, url, key=''): - if not name or not url: - return '0' - - providerDict = dict(zip([x.name for x in sickbeard.newznabProviderList], sickbeard.newznabProviderList)) - - if name in providerDict: - if not providerDict[name].default: - providerDict[name].name = name - providerDict[name].url = config.clean_url(url) - - providerDict[name].key = key - # a 0 in the key spot indicates that no key is needed - providerDict[name].needs_auth = '0' != key - - return providerDict[name].get_id() + '|' + providerDict[name].config_str() - - else: - newProvider = newznab.NewznabProvider(name, url, key=key) - sickbeard.newznabProviderList.append(newProvider) - return newProvider.get_id() + '|' + newProvider.config_str() - - @staticmethod def get_newznab_categories(name, url, key): """ Retrieves a list of possible categories with category id's @@ -7604,21 +7577,6 @@ class ConfigProviders(Config): return json.dumps({'success': True, 'tv_categories': tv_categories, 'state': state, 'error': ''}) @staticmethod - def delete_newznab_provider(nnid): - providerDict = dict(zip([x.get_id() for x in sickbeard.newznabProviderList], sickbeard.newznabProviderList)) - - if nnid not in providerDict or providerDict[nnid].default: - return '0' - - # delete it from the list - sickbeard.newznabProviderList.remove(providerDict[nnid]) - - if nnid in sickbeard.PROVIDER_ORDER: - sickbeard.PROVIDER_ORDER.remove(nnid) - - return '1' - - @staticmethod def can_add_torrent_rss_provider(name, url, cookies): if not name: return json.dumps({'error': 'Invalid name specified'}) @@ -7638,42 +7596,6 @@ class ConfigProviders(Config): return json.dumps({'error': errMsg}) @staticmethod - def save_torrent_rss_provider(name, url, cookies): - if not name or not url: - return '0' - - providerDict = dict(zip([x.name for x in sickbeard.torrentRssProviderList], sickbeard.torrentRssProviderList)) - - if name in providerDict: - providerDict[name].name = name - providerDict[name].url = config.clean_url(url) - providerDict[name].cookies = cookies - - return providerDict[name].get_id() + '|' + providerDict[name].config_str() - - else: - newProvider = rsstorrent.TorrentRssProvider(name, url, cookies) - sickbeard.torrentRssProviderList.append(newProvider) - return newProvider.get_id() + '|' + newProvider.config_str() - - @staticmethod - def delete_torrent_rss_provider(provider_id): - - providerDict = dict( - zip([x.get_id() for x in sickbeard.torrentRssProviderList], sickbeard.torrentRssProviderList)) - - if provider_id not in providerDict: - return '0' - - # delete it from the list - sickbeard.torrentRssProviderList.remove(providerDict[provider_id]) - - if provider_id in sickbeard.PROVIDER_ORDER: - sickbeard.PROVIDER_ORDER.remove(provider_id) - - return '1' - - @staticmethod def check_providers_ping(): for p in sickbeard.providers.sortedProviderList(): if getattr(p, 'ping_iv', None): @@ -7879,7 +7801,7 @@ class ConfigProviders(Config): attr = 'filter' if hasattr(torrent_src, attr) and torrent_src.may_filter: setattr(torrent_src, attr, - [k for k in torrent_src.may_filter + [k for k in getattr(torrent_src, 'may_filter', 'nop') if config.checkbox_to_value(kwargs.get('%sfilter_%s' % (src_id_prefix, k)))]) for attr in filter_iter(lambda a: hasattr(torrent_src, a), [