def load_admin(_id, remove=False, silent=False): """ Read data in admin folder in specified format """ path = os.path.join(cfg.admin_dir.get_path(), _id) logging.debug("[%s] Loading data for %s from %s", misc.caller_name(), _id, path) if not os.path.exists(path): logging.info("[%s] %s missing", misc.caller_name(), path) return None try: with open(path, 'rb') as data_file: if cfg.use_pickle(): data = pickle.load(data_file) else: data = cPickle.load(data_file) if remove: misc.remove_file(path) except: if not silent: excepterror = str(sys.exc_info()[0]) logging.error(T('Loading %s failed with error %s'), path, excepterror) logging.info("Traceback: ", exc_info=True) return None return data
def load_data(_id, path, remove=True, do_pickle=True, silent=False): """ Read data from disk file """ path = os.path.join(path, _id) if not os.path.exists(path): logging.info("[%s] %s missing", misc.caller_name(), path) return None if not silent: logging.debug("[%s] Loading data for %s from %s", misc.caller_name(), _id, path) try: with open(path, 'rb') as data_file: if do_pickle: if cfg.use_pickle(): data = pickle.load(data_file) else: data = cPickle.load(data_file) else: data = data_file.read() if remove: misc.remove_file(path) except: logging.error(T('Loading %s failed'), path) logging.info("Traceback: ", exc_info=True) return None return data
def load_data(data_id, path, remove=True, do_pickle=True, silent=False): """ Read data from disk file """ path = os.path.join(path, data_id) if not os.path.exists(path): logging.info("[%s] %s missing", misc.caller_name(), path) return None if not silent: logging.debug("[%s] Loading data for %s from %s", misc.caller_name(), data_id, path) try: with open(path, "rb") as data_file: if do_pickle: try: data = pickle.load(data_file, encoding=sabnzbd.encoding.CODEPAGE) except UnicodeDecodeError: # Could be Python 2 data that we can load using old encoding data = pickle.load(data_file, encoding="latin1") else: data = data_file.read() if remove: filesystem.remove_file(path) except: logging.error(T("Loading %s failed"), path) logging.info("Traceback: ", exc_info=True) return None return data
def save_data(data, _id, path, do_pickle=True, silent=False): """ Save data to a diskfile """ if not silent: logging.debug("[%s] Saving data for %s in %s", misc.caller_name(), _id, path) path = os.path.join(path, _id) # We try 3 times, to avoid any dict or access problems for t in range(3): try: with open(path, "wb") as data_file: if do_pickle: pickle.dump(data, data_file, protocol=pickle.HIGHEST_PROTOCOL) else: data_file.write(data) break except: if silent: # This can happen, probably a removed folder pass elif t == 2: logging.error(T("Saving %s failed"), path) logging.info("Traceback: ", exc_info=True) else: # Wait a tiny bit before trying again time.sleep(0.1)
def remove(self, nzo_id, add_to_history=True, save=True, cleanup=True, keep_basic=False, del_files=False): if nzo_id in self.__nzo_table: nzo = self.__nzo_table.pop(nzo_id) nzo.deleted = True if cleanup and not nzo.is_gone(): nzo.status = Status.DELETED self.__nzo_list.remove(nzo) if add_to_history: # Create the history DB instance history_db = database.HistoryDB() # Add the nzo to the database. Only the path, script and time taken is passed # Other information is obtained from the nzo history_db.add_history_db(nzo, '', '', 0, '', '') history_db.close() sabnzbd.history_updated() elif cleanup: self.cleanup_nzo(nzo, keep_basic, del_files) sabnzbd.remove_data(nzo_id, nzo.workpath) logging.info('[%s] Removed job %s', caller_name(), nzo.final_name) if save: self.save(nzo) else: nzo_id = None return nzo_id
def load_admin(data_id, remove=False, silent=False): """ Read data in admin folder in specified format """ logging.debug("[%s] Loading data for %s", misc.caller_name(), data_id) return load_data(data_id, cfg.admin_dir.get_path(), remove=remove, silent=silent)
def shutdown_program(): """ Stop program after halting and saving """ if not sabnzbd.SABSTOP: logging.info("[%s] Performing SABnzbd shutdown", misc.caller_name()) sabnzbd.halt() cherrypy.engine.exit() sabnzbd.SABSTOP = True
def save_data(data, _id, path, do_pickle=True, silent=False): """ Save data to a diskfile """ if not silent: logging.debug('[%s] Saving data for %s in %s', misc.caller_name(), _id, path) path = os.path.join(path, _id) # We try 3 times, to avoid any dict or access problems for t in xrange(3): try: with open(path, 'wb') as data_file: if do_pickle: if cfg.use_pickle(): pickle.dump(data, data_file) else: cPickle.dump(data, data_file) else: data_file.write(data) break except: if silent: # This can happen, probably a removed folder pass elif t == 2: logging.error(T('Saving %s failed'), path) logging.info("Traceback: ", exc_info=True) else: # Wait a tiny bit before trying again time.sleep(0.1)
def remove(self, nzo_id, add_to_history=True, cleanup=True, delete_all_data=True): """ Remove NZO from queue. It can be added to history directly. Or, we do some clean-up, sometimes leaving some data. """ if nzo_id in self.__nzo_table: nzo = self.__nzo_table.pop(nzo_id) logging.info("[%s] Removing job %s", caller_name(), nzo.final_name) # Set statuses nzo.deleted = True if cleanup and not nzo.is_gone(): nzo.status = Status.DELETED self.__nzo_list.remove(nzo) if add_to_history: # Create the history DB instance history_db = database.HistoryDB() # Add the nzo to the database. Only the path, script and time taken is passed # Other information is obtained from the nzo history_db.add_history_db(nzo) history_db.close() sabnzbd.history_updated() elif cleanup: nzo.purge_data(delete_all_data=delete_all_data) self.save(False) return nzo_id return None
def remove_history(self, jobs=None): """ Remove all jobs in the list `jobs`, empty list will remove all completed jobs """ if jobs is None: self.remove_completed() else: if not isinstance(jobs, list): jobs = [jobs] for job in jobs: self.execute("""DELETE FROM history WHERE nzo_id=?""", (job,), save=True) logging.info('[%s] Removing job %s from history', caller_name(), job)
def end_job(self, nzo): """ Send NZO to the post-processing queue """ # Notify assembler to call postprocessor if not nzo.deleted: logging.info("[%s] Ending job %s", caller_name(), nzo.final_name) nzo.deleted = True if nzo.precheck: nzo.save_to_disk() # Check result enough, _ = nzo.check_availability_ratio() if enough: # Enough data present, do real download self.send_back(nzo) return else: # Not enough data, let postprocessor show it as failed pass Assembler.do.process((nzo, None, None))
def end_job(self, nzo): """ Send NZO to the post-processing queue """ logging.info('[%s] Ending job %s', caller_name(), nzo.final_name) # Notify assembler to call postprocessor if not nzo.deleted: nzo.deleted = True if nzo.precheck: nzo.save_to_disk() # Check result enough, _ratio = nzo.check_quality() if enough: # Enough data present, do real download self.cleanup_nzo(nzo, keep_basic=True) self.send_back(nzo) return else: # Not enough data, let postprocessor show it as failed pass Assembler.do.process((nzo, None))
def end_job(self, nzo): """ Send NZO to the post-processing queue """ logging.info('[%s] Ending job %s', caller_name(), nzo.final_name) # Notify assembler to call postprocessor if not nzo.deleted: nzo.deleted = True if nzo.precheck: nzo.save_to_disk() # Check result enough, _ratio = nzo.check_availability_ratio() if enough: # Enough data present, do real download self.cleanup_nzo(nzo, keep_basic=True) self.send_back(nzo) return else: # Not enough data, let postprocessor show it as failed pass Assembler.do.process((nzo, None))
def remove(self, nzo_id: str, cleanup=True, delete_all_data=True): """Remove NZO from queue. It can be added to history directly. Or, we do some clean-up, sometimes leaving some data. """ if nzo_id in self.__nzo_table: nzo = self.__nzo_table.pop(nzo_id) logging.info("[%s] Removing job %s", caller_name(), nzo.final_name) # Set statuses nzo.deleted = True if cleanup and not nzo.is_gone(): nzo.status = Status.DELETED self.__nzo_list.remove(nzo) if cleanup: nzo.purge_data(delete_all_data=delete_all_data) self.save(False) return nzo_id return None
def save_admin(data, _id): """ Save data in admin folder in specified format """ path = os.path.join(cfg.admin_dir.get_path(), _id) logging.debug("[%s] Saving data for %s in %s", misc.caller_name(), _id, path) # We try 3 times, to avoid any dict or access problems for t in xrange(3): try: with open(path, 'wb') as data_file: if cfg.use_pickle(): pickle.dump(data, data_file) else: cPickle.dump(data, data_file) break except: if t == 2: logging.error(T('Saving %s failed'), path) logging.info("Traceback: ", exc_info=True) else: # Wait a tiny bit before trying again time.sleep(0.1)
def save_admin(data, _id): """ Save data in admin folder in specified format """ path = os.path.join(cfg.admin_dir.get_path(), _id) logging.debug("[%s] Saving data for %s in %s", misc.caller_name(), _id, path) # We try 3 times, to avoid any dict or access problems for t in xrange(3): try: with open(path, 'wb') as data_file: if cfg.use_pickle(): data = pickle.dump(data, data_file) else: data = cPickle.dump(data, data_file) break except: if t == 2: logging.error(T('Saving %s failed'), path) logging.info("Traceback: ", exc_info=True) else: # Wait a tiny bit before trying again time.sleep(0.1)
def test_wrapper_2(skip): return misc.caller_name(skip=skip)
def save_admin(data, data_id): """ Save data in admin folder in specified format """ logging.debug("[%s] Saving data for %s", misc.caller_name(), data_id) save_data(data, data_id, cfg.admin_dir.get_path())
def shutdown_program(): """ Stop program after halting and saving """ logging.info("[%s] Performing SABnzbd shutdown", misc.caller_name()) sabnzbd.halt() cherrypy.engine.exit() sabnzbd.SABSTOP = True