From 6d0d2d3f7e9e4ccbf7f2681d83ac2bea95cc31ac Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Mon, 31 Dec 2018 12:21:16 -0500 Subject: [PATCH] Use dict literal or comprehension for dict creation --- core/__init__.py | 22 ++++++++++++---------- core/auto_process/movies.py | 9 +++++---- core/forks.py | 12 ++++++++++-- core/main_db.py | 16 ++++++++-------- 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/core/__init__.py b/core/__init__.py index b55ea684..6487e716 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -63,7 +63,6 @@ SABNZB_NO_OF_ARGUMENTS = 8 SABNZB_0717_NO_OF_ARGUMENTS = 9 # sickbeard fork/branch constants -FORKS = {} FORK_DEFAULT = 'default' FORK_FAILED = 'failed' FORK_FAILED_TORRENT = 'failed-torrent' @@ -73,15 +72,18 @@ FORK_SICKBEARD_API = 'SickBeard-api' FORK_MEDUSA = 'Medusa' FORK_SICKGEAR = 'SickGear' FORK_STHENO = 'Stheno' -FORKS[FORK_DEFAULT] = {'dir': None} -FORKS[FORK_FAILED] = {'dirName': None, 'failed': None} -FORKS[FORK_FAILED_TORRENT] = {'dir': None, 'failed': None, 'process_method': None} -FORKS[FORK_SICKRAGE] = {'proc_dir': None, 'failed': None, 'process_method': None, 'force': None, 'delete_on': None} -FORKS[FORK_SICKCHILL] = {'proc_dir': None, 'failed': None, 'process_method': None, 'force': None, 'delete_on': None, 'force_next': None} -FORKS[FORK_SICKBEARD_API] = {'path': None, 'failed': None, 'process_method': None, 'force_replace': None, 'return_data': None, 'type': None, 'delete': None, 'force_next': None} -FORKS[FORK_MEDUSA] = {'proc_dir': None, 'failed': None, 'process_method': None, 'force': None, 'delete_on': None, 'ignore_subs': None} -FORKS[FORK_SICKGEAR] = {'dir': None, 'failed': None, 'process_method': None, 'force': None} -FORKS[FORK_STHENO] = {"proc_dir": None, "failed": None, "process_method": None, "force": None, "delete_on": None, "ignore_subs": None} + +FORKS = { + FORK_DEFAULT: {'dir': None}, + FORK_FAILED: {'dirName': None, 'failed': None}, + FORK_FAILED_TORRENT: {'dir': None, 'failed': None, 'process_method': None}, + FORK_SICKRAGE: {'proc_dir': None, 'failed': None, 'process_method': None, 'force': None, 'delete_on': None}, + FORK_SICKCHILL: {'proc_dir': None, 'failed': None, 'process_method': None, 'force': None, 'delete_on': None, 'force_next': None}, + FORK_SICKBEARD_API: {'path': None, 'failed': None, 'process_method': None, 'force_replace': None, 'return_data': None, 'type': None, 'delete': None, 'force_next': None}, + FORK_MEDUSA: {'proc_dir': None, 'failed': None, 'process_method': None, 'force': None, 'delete_on': None, 'ignore_subs': None}, + FORK_SICKGEAR: {'dir': None, 'failed': None, 'process_method': None, 'force': None}, + FORK_STHENO: {"proc_dir": None, "failed": None, "process_method": None, "force": None, "delete_on": None, "ignore_subs": None} +} ALL_FORKS = {k: None for k in set(list(itertools.chain.from_iterable([FORKS[x].keys() for x in FORKS.keys()])))} # NZBGet Exit Codes diff --git a/core/auto_process/movies.py b/core/auto_process/movies.py index f3097b6f..7c7b8f02 100644 --- a/core/auto_process/movies.py +++ b/core/auto_process/movies.py @@ -163,17 +163,18 @@ def process(section, dir_name, input_name=None, status=0, client_agent='manual', status_code=0, ) - params = {} + params = { + 'media_folder': remote_dir(dir_name) if remote_path else dir_name, + } + if download_id and release_id: params['downloader'] = downloader or client_agent params['download_id'] = download_id - params['media_folder'] = remote_dir(dir_name) if remote_path else dir_name - if section == 'CouchPotato': if method == 'manage': command = 'manage.update' - params = {} + params.clear() else: command = 'renamer.scan' diff --git a/core/forks.py b/core/forks.py index 8ff389fe..65610ad0 100644 --- a/core/forks.py +++ b/core/forks.py @@ -20,8 +20,16 @@ def auto_fork(section, input_category): apikey = cfg.get('apikey') ssl = int(cfg.get('ssl', 0)) web_root = cfg.get('web_root', '') - replace = {'sickrage': 'SickRage', 'sickchill': 'SickChill', 'sickgear': 'SickGear', 'medusa': 'Medusa', 'sickbeard-api': 'SickBeard-api', 'stheno': 'Stheno'} - f1 = replace[cfg.get('fork', 'auto')] if cfg.get('fork', 'auto') in replace else cfg.get('fork', 'auto') + replace = { + 'medusa': 'Medusa', + 'sickbeard-api': 'SickBeard-api', + 'sickgear': 'SickGear', + 'sickchill': 'SickChill', + 'sickrage': 'SickRage', + 'stheno': 'Stheno', + } + _val = cfg.get('fork', 'auto') + f1 = replace.get(_val, _val) try: fork = f1, core.FORKS[f1] except KeyError: diff --git a/core/main_db.py b/core/main_db.py index 6d2b6b95..12c21c7e 100644 --- a/core/main_db.py +++ b/core/main_db.py @@ -202,17 +202,17 @@ class DBConnection(object): def table_info(self, table_name): # FIXME ? binding is not supported here, but I cannot find a way to escape a string manually cursor = self.connection.execute('PRAGMA table_info({0})'.format(table_name)) - columns = {} - for column in cursor: - columns[column['name']] = {'type': column['type']} - return columns + return { + column['name']: {'type': column['type']} + for column in cursor + } # http://stackoverflow.com/questions/3300464/how-can-i-get-dict-from-sqlite-query def _dict_factory(self, cursor, row): - d = {} - for idx, col in enumerate(cursor.description): - d[col[0]] = row[idx] - return d + return { + col[0]: row[idx] + for idx, col in enumerate(cursor.description) + } def sanity_check_database(connection, sanity_check):