def scan_jobs(self, all=False, action=True): """ Scan "incomplete" for mssing folders, 'all' is True: Include active folders 'action' is True, do the recovery action returns list of orphaned folders """ result = [] # Folders from the download queue if all: registered = [] else: registered = [nzo.work_name for nzo in self.__nzo_list] # Retryable folders from History items = sabnzbd.proxy_build_history()[0] # Anything waiting or active or retryable is a known item registered.extend([platform_encode(os.path.basename(item['path'])) \ for item in items if item['retry'] or item['loaded'] or item['status'] == 'Queued']) # Repair unregistered folders for folder in globber(cfg.download_dir.get_path()): if os.path.isdir(folder) and os.path.basename(folder) not in registered: if action: logging.info('Repairing job %s', folder) self.repair_job(folder) result.append(os.path.basename(folder)) else: if action: logging.info('Skipping repair for job %s', folder) return result
def retry_all_jobs(self, history_db): """ Retry all retryable jobs in History """ result = [] # Retryable folders from History items = sabnzbd.api.build_history()[0] registered = [(platform_encode(os.path.basename(item['path'])), item['nzo_id']) for item in items if item['retry']] for job in registered: logging.info('Repairing job %s', job[0]) result.append(self.repair_job(job[0])) history_db.remove_history(job[1]) return bool(result)
def run_dir(folder, catdir): try: files = os.listdir(folder) except: if not self.error_reported and not catdir: logging.error(T('Cannot read Watched Folder %s'), misc.clip_path(folder)) self.error_reported = True files = [] for filename in files: path = os.path.join(folder, platform_encode(filename)) if os.path.isdir( path) or path in self.ignored or filename[0] == '.': continue ext = os.path.splitext(path)[1].lower() candidate = ext in VALID_NZB_FILES + VALID_ARCHIVES if candidate: try: stat_tuple = os.stat(path) except: continue else: self.ignored[path] = 1 if path in self.suspected: if CompareStat(self.suspected[path], stat_tuple): # Suspected file still has the same attributes continue else: del self.suspected[path] if candidate and stat_tuple.st_size > 0: logging.info('Trying to import %s', path) # Wait until the attributes are stable for 1 second # but give up after 3 sec stable = False for n in xrange(3): time.sleep(1.0) try: stat_tuple_tmp = os.stat(path) except: continue if CompareStat(stat_tuple, stat_tuple_tmp): stable = True break else: stat_tuple = stat_tuple_tmp if not stable: continue # Handle archive files, but only when containing just NZB files if ext in VALID_ARCHIVES: res, nzo_ids = ProcessArchiveFile(filename, path, catdir=catdir, url=path) if res == -1: self.suspected[path] = stat_tuple elif res == 0: self.error_reported = False else: self.ignored[path] = 1 # Handle .nzb, .nzb.gz or gzip-disguised-as-nzb or .bz2 elif ext == '.nzb' or filename.lower().endswith( '.nzb.gz') or filename.lower().endswith( '.nzb.bz2'): res, nzo_id = ProcessSingleFile(filename, path, catdir=catdir, url=path) if res < 0: self.suspected[path] = stat_tuple elif res == 0: self.error_reported = False else: self.ignored[path] = 1 else: self.ignored[path] = 1 CleanList(self.ignored, folder, files) CleanList(self.suspected, folder, files)
def run_dir(folder, catdir): try: files = os.listdir(folder) except: if not self.error_reported and not catdir: logging.error(T('Cannot read Watched Folder %s'), misc.clip_path(folder)) self.error_reported = True files = [] for filename in files: path = os.path.join(folder, platform_encode(filename)) if os.path.isdir(path) or path in self.ignored or filename[0] == '.': continue ext = os.path.splitext(path)[1].lower() candidate = ext in VALID_NZB_FILES + VALID_ARCHIVES if candidate: try: stat_tuple = os.stat(path) except: continue else: self.ignored[path] = 1 if path in self.suspected: if CompareStat(self.suspected[path], stat_tuple): # Suspected file still has the same attributes continue else: del self.suspected[path] if candidate and stat_tuple.st_size > 0: logging.info('Trying to import %s', path) # Wait until the attributes are stable for 1 second # but give up after 3 sec stable = False for n in xrange(3): time.sleep(1.0) try: stat_tuple_tmp = os.stat(path) except: continue if CompareStat(stat_tuple, stat_tuple_tmp): stable = True break else: stat_tuple = stat_tuple_tmp if not stable: continue # Handle archive files, but only when containing just NZB files if ext in VALID_ARCHIVES: res, nzo_ids = ProcessArchiveFile(filename, path, catdir=catdir, url=path) if res == -1: self.suspected[path] = stat_tuple elif res == 0: self.error_reported = False else: self.ignored[path] = 1 # Handle .nzb, .nzb.gz or gzip-disguised-as-nzb or .bz2 elif ext == '.nzb' or filename.lower().endswith('.nzb.gz') or filename.lower().endswith('.nzb.bz2'): res, nzo_id = ProcessSingleFile(filename, path, catdir=catdir, url=path) if res < 0: self.suspected[path] = stat_tuple elif res == 0: self.error_reported = False else: self.ignored[path] = 1 else: self.ignored[path] = 1 CleanList(self.ignored, folder, files) CleanList(self.suspected, folder, files)