def add(self, nzo, save=True, quiet=False): if not nzo.nzo_id: nzo.nzo_id = sabnzbd.get_new_id("nzo", nzo.workpath, self.__nzo_table) # If no files are to be downloaded anymore, send to postproc if not nzo.files and not nzo.futuretype: self.end_job(nzo) return nzo.nzo_id # Reset try_lists nzo.reset_try_list() if nzo.nzo_id: nzo.deleted = False priority = nzo.priority if sabnzbd.scheduler.analyse(False, priority): nzo.status = Status.PAUSED self.__nzo_table[nzo.nzo_id] = nzo if priority > HIGH_PRIORITY: # Top and repair priority items are added to the top of the queue self.__nzo_list.insert(0, nzo) elif priority == LOW_PRIORITY: self.__nzo_list.append(nzo) else: # for high priority we need to add the item at the bottom # of any other high priority items above the normal priority # for normal priority we need to add the item at the bottom # of the normal priority items above the low priority if self.__nzo_list: pos = 0 added = False for position in self.__nzo_list: if position.priority < priority: self.__nzo_list.insert(pos, nzo) added = True break pos += 1 if not added: # if there are no other items classed as a lower priority # then it will be added to the bottom of the queue self.__nzo_list.append(nzo) else: # if the queue is empty then simple append the item to the bottom self.__nzo_list.append(nzo) if save: self.save(nzo) if not (quiet or nzo.status == Status.FETCHING): notifier.send_notification(T("NZB added to queue"), nzo.filename, "download", nzo.cat) if not quiet and cfg.auto_sort(): try: field, direction = cfg.auto_sort().split() self.sort_queue(field, direction) except ValueError: pass return nzo.nzo_id
def add(self, nzo, save=True, quiet=False): if 0: assert isinstance(nzo, NzbObject) # Assert only for debug purposes if not nzo.nzo_id: nzo.nzo_id = sabnzbd.get_new_id('nzo', nzo.workpath, self.__nzo_table) # If no files are to be downloaded anymore, send to postproc if not nzo.files and not nzo.futuretype: self.end_job(nzo) return '' # Reset try_lists nzo.reset_try_list() self.reset_try_list() if nzo.nzo_id: nzo.deleted = False priority = nzo.priority if sabnzbd.scheduler.analyse(False, priority): nzo.status = Status.PAUSED self.__nzo_table[nzo.nzo_id] = nzo if priority > HIGH_PRIORITY: # Top and repair priority items are added to the top of the queue self.__nzo_list.insert(0, nzo) elif priority == LOW_PRIORITY: self.__nzo_list.append(nzo) else: # for high priority we need to add the item at the bottom # of any other high priority items above the normal priority # for normal priority we need to add the item at the bottom # of the normal priority items above the low priority if self.__nzo_list: pos = 0 added = False for position in self.__nzo_list: if position.priority < priority: self.__nzo_list.insert(pos, nzo) added = True break pos += 1 if not added: # if there are no other items classed as a lower priority # then it will be added to the bottom of the queue self.__nzo_list.append(nzo) else: # if the queue is empty then simple append the item to the bottom self.__nzo_list.append(nzo) if save: self.save(nzo) if not (quiet or nzo.status in ('Fetching', )): notifier.send_notification(T('NZB added to queue'), nzo.filename, 'download') if cfg.auto_sort(): self.sort_by_avg_age() return nzo.nzo_id
def add(self, nzo, save=True, quiet=False): if 0: assert isinstance(nzo, NzbObject) # Assert only for debug purposes if not nzo.nzo_id: nzo.nzo_id = sabnzbd.get_new_id('nzo', nzo.workpath, self.__nzo_table) # If no files are to be downloaded anymore, send to postproc if not nzo.files and not nzo.futuretype: self.end_job(nzo) return '' # Reset try_lists nzo.reset_try_list() self.reset_try_list() if nzo.nzo_id: nzo.deleted = False priority = nzo.priority if sabnzbd.scheduler.analyse(False, priority): nzo.status = Status.PAUSED self.__nzo_table[nzo.nzo_id] = nzo if priority > HIGH_PRIORITY: # Top and repair priority items are added to the top of the queue self.__nzo_list.insert(0, nzo) elif priority == LOW_PRIORITY: self.__nzo_list.append(nzo) else: # for high priority we need to add the item at the bottom # of any other high priority items above the normal priority # for normal priority we need to add the item at the bottom # of the normal priority items above the low priority if self.__nzo_list: pos = 0 added = False for position in self.__nzo_list: if position.priority < priority: self.__nzo_list.insert(pos, nzo) added = True break pos += 1 if not added: # if there are no other items classed as a lower priority # then it will be added to the bottom of the queue self.__nzo_list.append(nzo) else: # if the queue is empty then simple append the item to the bottom self.__nzo_list.append(nzo) if save: self.save(nzo) if not (quiet or nzo.status in ('Fetching',)): notifier.send_notification(T('NZB added to queue'), nzo.filename, 'download') if cfg.auto_sort(): self.sort_by_avg_age() return nzo.nzo_id
def add(self, nzo, save=True, quiet=False): assert isinstance(nzo, NzbObject) if not nzo.nzo_id: nzo.nzo_id = sabnzbd.get_new_id("nzo", nzo.workpath, self.__nzo_table) # If no files are to be downloaded anymore, send to postproc if not nzo.files and not nzo.futuretype: sabnzbd.remove_data(nzo.nzo_id, nzo.workpath) sabnzbd.proxy_postproc(nzo) return "" # Reset try_lists nzo.reset_try_list() self.reset_try_list() if nzo.nzo_id: nzo.deleted = False priority = nzo.priority self.__nzo_table[nzo.nzo_id] = nzo if priority > HIGH_PRIORITY: # Top and repair priority items are added to the top of the queue self.__nzo_list.insert(0, nzo) elif priority == LOW_PRIORITY: self.__nzo_list.append(nzo) else: # for high priority we need to add the item at the bottom # of any other high priority items above the normal priority # for normal priority we need to add the item at the bottom # of the normal priority items above the low priority if self.__nzo_list: pos = 0 added = False for position in self.__nzo_list: if position.priority < priority: self.__nzo_list.insert(pos, nzo) added = True break pos += 1 if not added: # if there are no other items classed as a lower priority # then it will be added to the bottom of the queue self.__nzo_list.append(nzo) else: # if the queue is empty then simple append the item to the bottom self.__nzo_list.append(nzo) if save: self.save(nzo) if not (quiet or nzo.status in ("Fetching",)): growler.send_notification(T("NZB added to queue"), nzo.filename, "download") if cfg.auto_sort(): self.sort_by_avg_age() return nzo.nzo_id
def add(self, nzo, save=True, quiet=False): assert isinstance(nzo, NzbObject) if not nzo.nzo_id: nzo.nzo_id = sabnzbd.get_new_id('nzo', nzo.workpath, self.__nzo_table) # If no files are to be downloaded anymore, send to postproc if not nzo.files and not nzo.futuretype: sabnzbd.remove_data(nzo.nzo_id, nzo.workpath) sabnzbd.proxy_postproc(nzo) return # Reset try_lists nzo.reset_try_list() self.reset_try_list() if nzo.nzo_id: nzo.deleted = False priority = nzo.priority self.__nzo_table[nzo.nzo_id] = nzo if priority > HIGH_PRIORITY: #Top and repair priority items are added to the top of the queue self.__nzo_list.insert(0, nzo) elif priority == LOW_PRIORITY: self.__nzo_list.append(nzo) else: #for high priority we need to add the item at the bottom #of any other high priority items above the normal priority #for normal priority we need to add the item at the bottom #of the normal priority items above the low priority if self.__nzo_list: pos = 0 added = False for position in self.__nzo_list: if position.priority < priority: self.__nzo_list.insert(pos, nzo) added = True break pos += 1 if not added: #if there are no other items classed as a lower priority #then it will be added to the bottom of the queue self.__nzo_list.append(nzo) else: #if the queue is empty then simple append the item to the bottom self.__nzo_list.append(nzo) if save: self.save(nzo) if not (quiet or nzo.status in ('Fetching',)): osx.sendGrowlMsg(T('NZB added to queue'), nzo.filename, osx.NOTIFICATION['download']) if cfg.auto_sort(): self.sort_by_avg_age()
def insert_future(self, future, filename, msgid, data, pp=None, script=None, cat=None, priority=NORMAL_PRIORITY, nzbname=None, nzo_info=None): """ Refresh a placeholder nzo with an actual nzo """ assert isinstance(future, NzbObject) if nzo_info is None: nzo_info = {} nzo_id = future.nzo_id if nzo_id in self.__nzo_table: try: sabnzbd.remove_data(nzo_id, future.workpath) logging.info("Regenerating item: %s", nzo_id) r, u, d = future.repair_opts if not r is None: pp = sabnzbd.opts_to_pp(r, u, d) scr = future.script if scr is None: scr = script categ = future.cat if categ is None: categ = cat categ, pp, script, priority = cat_to_opts(categ, pp, script, priority) # Remember old priority old_prio = future.priority try: future.__init__(filename, msgid, pp, scr, nzb=data, futuretype=False, cat=categ, priority=priority, nzbname=nzbname, nzo_info=nzo_info) future.nzo_id = nzo_id self.save(future) except ValueError: self.remove(nzo_id, False) except TypeError: self.remove(nzo_id, False) # Make sure the priority is changed now that we know the category if old_prio != priority: future.priority = None self.set_priority(future.nzo_id, priority) if cfg.auto_sort(): self.sort_by_avg_age() self.reset_try_list() except: logging.error(Ta('Error while adding %s, removing'), nzo_id) logging.info("Traceback: ", exc_info = True) self.remove(nzo_id, False) else: logging.info("Item %s no longer in queue, omitting", nzo_id)
def initialize(pause_downloader=False, clean_up=False, evalSched=False, repair=0): global __INITIALIZED__, __SHUTTING_DOWN__, LOGFILE, WEBLOGFILE, LOGHANDLER, GUIHANDLER, AMBI_LOCALHOST, WAITEXIT, DAEMON, MY_NAME, MY_FULLNAME, NEW_VERSION, DIR_HOME, DIR_APPDATA, DIR_LCLDATA, DIR_PROG, DIR_INTERFACES, DARWIN, RESTART_REQ if __INITIALIZED__: return False __SHUTTING_DOWN__ = False # Set global database connection for Web-UI threads cherrypy.engine.subscribe("start_thread", get_db_connection) # Paused? pause_downloader = pause_downloader or cfg.start_paused() # Clean-up, if requested if clean_up: # New admin folder filesystem.remove_all(cfg.admin_dir.get_path(), "*.sab") # Optionally wait for "incomplete" to become online if cfg.wait_for_dfolder(): wait_for_download_folder() else: cfg.download_dir.set(cfg.download_dir(), create=True) cfg.download_dir.set_create(True) # Set access rights for "incomplete" base folder filesystem.set_permissions(cfg.download_dir.get_path(), recursive=False) # If dirscan_dir cannot be created, set a proper value anyway. # Maybe it's a network path that's temporarily missing. path = cfg.dirscan_dir.get_path() if not os.path.exists(path): filesystem.create_real_path(cfg.dirscan_dir.ident(), "", path, False) # Set call backs for Config items cfg.cache_limit.callback(new_limit) cfg.cherryhost.callback(guard_restart) cfg.cherryport.callback(guard_restart) cfg.web_dir.callback(guard_restart) cfg.web_color.callback(guard_restart) cfg.username.callback(guard_restart) cfg.password.callback(guard_restart) cfg.log_dir.callback(guard_restart) cfg.https_port.callback(guard_restart) cfg.https_cert.callback(guard_restart) cfg.https_key.callback(guard_restart) cfg.enable_https.callback(guard_restart) cfg.top_only.callback(guard_top_only) cfg.pause_on_post_processing.callback(guard_pause_on_pp) cfg.quota_size.callback(guard_quota_size) cfg.quota_day.callback(guard_quota_dp) cfg.quota_period.callback(guard_quota_dp) cfg.language.callback(guard_language) cfg.enable_https_verification.callback(guard_https_ver) guard_https_ver() # Set cache limit if not cfg.cache_limit() or (cfg.cache_limit() in ("200M", "450M") and (sabnzbd.WIN32 or sabnzbd.DARWIN)): cfg.cache_limit.set(misc.get_cache_limit()) ArticleCache.do.new_limit(cfg.cache_limit.get_int()) check_incomplete_vs_complete() # Set language files lang.set_locale_info("SABnzbd", DIR_LANGUAGE) lang.set_language(cfg.language()) sabnzbd.api.clear_trans_cache() sabnzbd.change_queue_complete_action(cfg.queue_complete(), new=False) # One time conversion "speedlimit" in schedules. if not cfg.sched_converted(): schedules = cfg.schedules() newsched = [] for sched in schedules: if "speedlimit" in sched: newsched.append(re.sub(r"(speedlimit \d+)$", r"\1K", sched)) else: newsched.append(sched) cfg.schedules.set(newsched) cfg.sched_converted.set(1) # Second time schedule conversion if cfg.sched_converted() != 2: cfg.schedules.set(["%s %s" % (1, schedule) for schedule in cfg.schedules()]) cfg.sched_converted.set(2) config.save_config() # Convert auto-sort if cfg.auto_sort() == "0": cfg.auto_sort.set("") elif cfg.auto_sort() == "1": cfg.auto_sort.set("avg_age asc") # Add hostname to the whitelist if not cfg.host_whitelist(): cfg.host_whitelist.set(socket.gethostname()) # Do repair if requested if check_repair_request(): repair = 2 pause_downloader = True # Initialize threads rss.init() paused = BPSMeter.do.read() NzbQueue() Downloader(pause_downloader or paused) Decoder() Assembler() PostProcessor() NzbQueue.do.read_queue(repair) DirScanner() Rating() URLGrabber() scheduler.init() if evalSched: scheduler.analyse(pause_downloader) logging.info("All processes started") RESTART_REQ = False __INITIALIZED__ = True return True
def initialize(pause_downloader=False, clean_up=False, repair=0): if sabnzbd.__INITIALIZED__: return False sabnzbd.__SHUTTING_DOWN__ = False # Set global database connection for Web-UI threads cherrypy.engine.subscribe("start_thread", get_db_connection) # Paused? pause_downloader = pause_downloader or cfg.start_paused() # Clean-up, if requested if clean_up: # New admin folder filesystem.remove_all(cfg.admin_dir.get_path(), "*.sab") # Optionally wait for "incomplete" to become online if cfg.wait_for_dfolder(): wait_for_download_folder() else: cfg.download_dir.set(cfg.download_dir(), create=True) cfg.download_dir.set_create(True) # Set access rights for "incomplete" base folder filesystem.set_permissions(cfg.download_dir.get_path(), recursive=False) # If dirscan_dir cannot be created, set a proper value anyway. # Maybe it's a network path that's temporarily missing. path = cfg.dirscan_dir.get_path() if not os.path.exists(path): filesystem.create_real_path(cfg.dirscan_dir.ident(), "", path, False) # Set call backs for Config items cfg.cache_limit.callback(new_limit) cfg.cherryhost.callback(guard_restart) cfg.cherryport.callback(guard_restart) cfg.web_dir.callback(guard_restart) cfg.web_color.callback(guard_restart) cfg.username.callback(guard_restart) cfg.password.callback(guard_restart) cfg.log_dir.callback(guard_restart) cfg.https_port.callback(guard_restart) cfg.https_cert.callback(guard_restart) cfg.https_key.callback(guard_restart) cfg.enable_https.callback(guard_restart) cfg.top_only.callback(guard_top_only) cfg.pause_on_post_processing.callback(guard_pause_on_pp) cfg.quota_size.callback(guard_quota_size) cfg.quota_day.callback(guard_quota_dp) cfg.quota_period.callback(guard_quota_dp) cfg.language.callback(guard_language) cfg.enable_https_verification.callback(guard_https_ver) guard_https_ver() check_incomplete_vs_complete() # Set language files lang.set_locale_info("SABnzbd", DIR_LANGUAGE) lang.set_language(cfg.language()) sabnzbd.api.clear_trans_cache() # Set end-of-queue action sabnzbd.change_queue_complete_action(cfg.queue_complete(), new=False) # Convert auto-sort if cfg.auto_sort() == "0": cfg.auto_sort.set("") elif cfg.auto_sort() == "1": cfg.auto_sort.set("avg_age asc") # Add hostname to the whitelist if not cfg.host_whitelist(): cfg.host_whitelist.set(socket.gethostname()) # Do repair if requested if check_repair_request(): repair = 2 pause_downloader = True # Initialize threads sabnzbd.ArticleCache = sabnzbd.articlecache.ArticleCache() sabnzbd.BPSMeter = sabnzbd.bpsmeter.BPSMeter() sabnzbd.NzbQueue = sabnzbd.nzbqueue.NzbQueue() sabnzbd.Downloader = sabnzbd.downloader.Downloader(sabnzbd.BPSMeter.read() or pause_downloader) sabnzbd.Decoder = sabnzbd.decoder.Decoder() sabnzbd.Assembler = sabnzbd.assembler.Assembler() sabnzbd.PostProcessor = sabnzbd.postproc.PostProcessor() sabnzbd.DirScanner = sabnzbd.dirscanner.DirScanner() sabnzbd.Rating = sabnzbd.rating.Rating() sabnzbd.URLGrabber = sabnzbd.urlgrabber.URLGrabber() sabnzbd.RSSReader = sabnzbd.rss.RSSReader() sabnzbd.Scheduler = sabnzbd.scheduler.Scheduler() # Run startup tasks sabnzbd.NzbQueue.read_queue(repair) sabnzbd.Scheduler.analyse(pause_downloader) # Set cache limit for new users if not cfg.cache_limit(): cfg.cache_limit.set(misc.get_cache_limit()) sabnzbd.ArticleCache.new_limit(cfg.cache_limit.get_int()) logging.info("All processes started") sabnzbd.RESTART_REQ = False sabnzbd.__INITIALIZED__ = True