From 5a2d3fbb854336a79d67c6c0ea0e5ca47aa69b5a Mon Sep 17 00:00:00 2001 From: JackDandy Date: Wed, 24 Aug 2016 03:03:06 +0100 Subject: [PATCH] Change unpack files once only in auto post processing copy mode. --- CHANGES.md | 3 +- gui/slick/js/config.js | 1 + sickbeard/processTV.py | 66 +++++++++++++++++++++++++++++++++--------- sickbeard/webserve.py | 2 +- 4 files changed, 57 insertions(+), 15 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3342551e..886e5992 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ ### 0.12.0 (2016-xx-xx xx:xx:xx UTC) -* Add strict Python version check (equal or higher than 2.7.9 and less than 3.0), ** exit ** if incorrect version +* Add strict Python version check (equal to, or higher than 2.7.9 and less than 3.0), **exit** if incorrect version * Update unidecode library 0.04.11 to 0.04.18 (fd57cbf) * Update xmltodict library 0.9.2 (579a005) to 0.9.2 (eac0031) * Update Tornado Web Server 4.3.dev1 (1b6157d) to 4.4.dev1 (c2b4d05) @@ -127,6 +127,7 @@ * Fix Nyaa and TT torrent providers * Change PrivateHD torrent provider * Fix Add from Trakt +* Change unpack files once only in auto post processing copy mode ### 0.11.14 (2016-07-25 03:10:00 UTC) diff --git a/gui/slick/js/config.js b/gui/slick/js/config.js index 5b01a099..ac7eec89 100644 --- a/gui/slick/js/config.js +++ b/gui/slick/js/config.js @@ -302,6 +302,7 @@ function fetch_branches() { $.each(branches, function (i, text) { add_option_to_branches(text); }); + $('#branchVersion').find('option[value=' + data['current'] + ']').attr('selected','selected'); $('#branchCheckout').removeAttr('disabled'); } else { add_option_to_branches('No branches available'); diff --git a/sickbeard/processTV.py b/sickbeard/processTV.py index ed9b92d6..959cc897 100644 --- a/sickbeard/processTV.py +++ b/sickbeard/processTV.py @@ -19,11 +19,13 @@ from __future__ import with_statement from functools import partial +import datetime import os import re import shutil import stat import sys +import time import sickbeard from sickbeard import postProcessor @@ -39,6 +41,11 @@ from sickbeard import failedProcessor import lib.rarfile.rarfile as rarfile +try: + import json +except ImportError: + from lib import simplejson as json + try: from lib.send2trash import send2trash except ImportError: @@ -190,13 +197,13 @@ class ProcessTVShow(object): path, dirs, files = self._get_path_dir_files(dir_name, nzb_name, pp_type) - sync_files = filter(helpers.isSyncFile, files) - - # Don't post process if files are still being synced and option is activated - if sync_files and sickbeard.POSTPONE_IF_SYNC_FILES: + if sickbeard.POSTPONE_IF_SYNC_FILES and any(filter(helpers.isSyncFile, files)): self._log_helper(u'Found temporary sync files, skipping post process', logger.ERROR) return self.result + if not process_method: + process_method = sickbeard.PROCESS_METHOD + self._log_helper(u'Processing folder... %s' % path) work_files = [] @@ -204,7 +211,8 @@ class ProcessTVShow(object): if joined: work_files += [joined] - rar_files = filter(helpers.is_first_rar_volume, files) + rar_files, rarfile_history = self.unused_archives( + path, filter(helpers.is_first_rar_volume, files), pp_type, process_method) rar_content = self._unrar(path, rar_files, force) if self.fail_detected: self._process_failed(dir_name, nzb_name) @@ -228,9 +236,6 @@ class ProcessTVShow(object): if 2 <= len(video_files): nzb_name = None - if not process_method: - process_method = sickbeard.PROCESS_METHOD - # self._set_process_success() # Don't Link media when the media is extracted from a rar in the same path @@ -266,14 +271,12 @@ class ProcessTVShow(object): for walk_path, walk_dir, files in ek.ek(os.walk, ek.ek(os.path.join, path, directory), topdown=False): - sync_files = filter(helpers.isSyncFile, files) - - # Don't post process if files are still being synced and option is activated - if sync_files and sickbeard.POSTPONE_IF_SYNC_FILES: + if sickbeard.POSTPONE_IF_SYNC_FILES and any(filter(helpers.isSyncFile, files)): self._log_helper(u'Found temporary sync files, skipping post process', logger.ERROR) return self.result - rar_files = filter(helpers.is_first_rar_volume, files) + rar_files, rarfile_history = self.unused_archives( + walk_path, filter(helpers.is_first_rar_volume, files), pp_type, process_method, rarfile_history) rar_content = self._unrar(walk_path, rar_files, force) work_files += [ek.ek(os.path.join, walk_path, item) for item in rar_content] if self.fail_detected: @@ -346,6 +349,43 @@ class ProcessTVShow(object): return self.result + @staticmethod + def unused_archives(path, archives, pp_type, process_method, archive_history=None): + + archive_history = (archive_history, {})[not archive_history] + if ('auto' == pp_type and sickbeard.PROCESS_AUTOMATICALLY + and 'copy' == process_method and sickbeard.UNPACK): + + archive_history_file = ek.ek(os.path.join, sickbeard.DATA_DIR, 'archive_history.txt') + + if not archive_history: + try: + with open(archive_history_file, 'r') as fh: + archive_history = json.loads(fh.read(10 * 1024 * 1024)) + except (IOError, ValueError, Exception): + pass + + init_history_cnt = len(archive_history) + + for archive in archive_history.keys(): + if not ek.ek(os.path.isfile, archive): + del archive_history[archive] + + unused_files = list(set([ek.ek(os.path.join, path, x) for x in archives]) - set(archive_history.keys())) + archives = [ek.ek(os.path.basename, x) for x in unused_files] + if unused_files: + for f in unused_files: + archive_history.setdefault(f, time.mktime(datetime.datetime.utcnow().timetuple())) + + if init_history_cnt != len(archive_history): + try: + with open(archive_history_file, 'w') as fh: + fh.write(json.dumps(archive_history)) + except (IOError, Exception): + pass + + return archives, archive_history + def _validate_dir(self, path, dir_name, nzb_name_original, failed): self._log_helper(u'Processing sub dir: ' + dir_name) diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 97839753..aeaba48d 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -4330,7 +4330,7 @@ class ConfigGeneral(Config): def fetch_branches(): try: branches = sickbeard.versionCheckScheduler.action.list_remote_branches() - return json.dumps({'result': 'success', 'branches': branches}) + return json.dumps({'result': 'success', 'branches': branches, 'current': sickbeard.BRANCH or 'master'}) except Exception as e: logger.log(u'exception msg: ' + str(e), logger.DEBUG) return json.dumps({'result': 'fail'})