def request_items__lirs(items_to_request): """Request items/books again when in queue to long.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START, requesting %d items" % len(items_to_request), wdb.SHOW_START) for item in items_to_request: request_book__lirs(d.SERVER, d.CHANNEL, item)
def is_nick_on_channel(this_nick): """Checks if a nick is online.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START : %s" % this_nick, wdb.SHOW_START) return channel_has_nick(d.SERVER, d.CHANNEL, this_nick)
def move_book_from_sending_2_completed__lbirs(book_): """Book received and completed; checks if can remove book from INQUEUE.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START: %s" % book_, wdb.SHOW_START) found = False bl_found, b_book = remove_from_booklist__lbirs(book_) if bl_found: wp.print_to_completed_list(b_book) found = True rq_found, r_book = remove_from_request_queue__lirs(book_) if rq_found: wp.print_to_completed_list(r_book) found = True iq_found, q_book, _ = remove_from_queue__lirs(book_) if iq_found: wp.print_to_completed_list(q_book) found = True sq_found, s_book, _ = remove_from_sending__lirs(book_) if sq_found: wp.print_to_completed_list(s_book) found = True if found: d.RUNNING = check_if_books_done() if not d.RUNNING: d.QUEUE_RUNNING = d.RUNNING d.BOOK_LIST_CHANGED = True else: if book_.startswith("!SearchOok") and book_.endswith(".txt.zip"): return wp.print_bad_book_name__lis(book_, "SENDING to COMPLETED") f.write_files()
def adding_books__lbcinrs(argf): """Take args(argn) and determining if a filename or a book listing. Putting the books into the BKLIST using helper functions. """ # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START: %s" % argf, wdb.SHOW_START) added_books = 0 wp.wprint("ADD\t Adding an item or file:%s" % argf) if argf.startswith('!'): # this is a single book item and uses the rest of the line # bookitem = argn[1:] # and sends the line to S to pull off any extra info # and checks if the book was added if book_add__lbinrs(argf) == 1: wp.wprint("BOOK\t ADDED: %s" % argf) d.BOOK_LIST_CHANGED = True tnick = re.findall(r"(?<=!)\S*", argf) nick = tnick[0].strip() n.add_nick_to_send_list(nick) added_books = 1 d.NOTIFY_LIST_CHANGED = n.put_nicklist_in_notify() wp.update_bar__lirs() # no book was added, print out error statement else: wp.error_print("UNABLE TO ADD BOOK: %s" % argf) # this is a file and sends the file name to read_file__lbn else: # adding a file added_books = f.read_file__lbinrs(argf) wp.wprint("%d books added" % added_books)
def is_nicklist_empty(): """Check if NICKLIST is empty, all done.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START", wdb.SHOW_START) return not d.NICKLIST # empty
def is_nick_online(this_nick): """Return whether or not the NICKLIST thinks the nick is online.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START : %s" % this_nick, wdb.SHOW_START) if this_nick in d.NICKLIST: return d.NICKLIST[this_nick][d.ONLINE] return False
def clear_queue__lbinrs(this_nick): """Clear the items for a nick out of the queue back to the books list. Used when nick quits or stopping queue. """ # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START: %s" % this_nick, wdb.SHOW_START) move_items_inqueue_to_bklist__lbinrs(this_nick) wp.update_bar__lirs()
def check_if_books_done(): """Check if all books are done, empty lists,queuek.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START", wdb.SHOW_START) done = False if not d.BKLIST and not d.INQUEUE and not d.SENDING and not d.REQUEST_QUEUE: done = True return not done
def move_items_send_2_bklist(items_to_move): """Move items to bklist when in sending to long.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START, moving %d items" % len(items_to_move), wdb.SHOW_START) for item in items_to_move: keys_it = item.keys() for i_key in keys_it: wp.wprint(function_name + "\t Moving item from SENDING to queue: i_key=%s, nick=%s" % (str(i_key), item[i_key])) move_book_from_sending_to_queue_bklist__lbcinrs(str(i_key), item[i_key])
def get_item_from_list(book, nick): """Return first book from BkLIST, does not remove.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START: %s" % nick, wdb.SHOW_START) for bkitem, nkitem in book.items(): if nkitem == nick: return bkitem, nkitem return None, None
def request_book__lirs(fserver, fchannel, fbook): """Request the download of the book from the server. fbook is the book out of bklist. """ # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START: %s" % fbook, wdb.SHOW_START) thisbuffer = w.buffer_search("", "%s.%s" % (fserver, fchannel)) wp.wprint("REQUEST book\t%s" % fbook) wp.update_bar__lirs() w.command(thisbuffer, fbook)
def check_if_book_anywhere__lbirs(bkitem_): """Check if book was in sending to long and moved elsewhere. :param bkitem_: str :return: None """ # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START", wdb.SHOW_START) remove_from_booklist__lbirs(bkitem_) remove_from_request_queue__lirs(bkitem_) remove_from_queue__lirs(bkitem_)
def channel_has_nick(fserver, fchannel, fnick): """Check if channel has nick in it.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START : %s" % fnick, wdb.SHOW_START) thisbuffer = w.buffer_search("", "%s.%s" % (fserver, fchannel)) # check for nick in the buffer is_online = bool(w.nicklist_search_nick(thisbuffer, "", fnick)) if (fnick == "FlipMoran" and not (is_online)): is_online = bool(w.nicklist_search_nick(thisbuffer, "", "FlipMoran2")) return is_online
def check_if_nick_done(this_nick): """Check if all books for a nick has been downloaded.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START : %s" % this_nick, wdb.SHOW_START) if this_nick in d.NICKLIST and d.NICKLIST[this_nick][d.NUM_IN_QUEUE] == 0 and \ d.NICKLIST[this_nick][d.NUM_BOOKS] == 0 and \ d.NICKLIST[this_nick][d.DOWNLOAD] == 0: d.NOTIFY_LIST_CHANGED = True return True return False
def stop_queue__linrs(): """Stop the download queue of books.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START", wdb.SHOW_START) d.QUEUE_RUNNING = False for nick in d.NICKLIST: move_items_inqueue_to_bklist__lbinrs(nick) n.pull_nick_from_down_accept(nick) # print_queue_status("QUEUE STOPPED") wp.update_bar__lirs() return False
def pull_nick_from_down_accept(th_nick): """Remove nick from the send list.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START : %s" % th_nick, wdb.SHOW_START) original_xfer_list = w.config_string( w.config_get("xfer.file.auto_accept_nicks")) listold = original_xfer_list.split(',') if th_nick in listold and check_if_nick_done(th_nick): listold.remove(th_nick) newlist = ','.join(listold) return set_xfer_down_accept(newlist)
def find_in_dictionary(this_queue, book_): """Find an item in a dictionary queue for SENDING, INQUEUE, or REQUEST_QUEUE. The lock must be made for the appropriate queue before calling this function.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START : %s" % book_, wdb.SHOW_START) book_standard = standardize_string(book_) for item in this_queue: item_ = standardize_string(item) if item_ == book_standard: # or item_ == book_b_standard: return True, item, this_queue[item][d.NICK] # sending_found, to_remove return False, None, None
def move_book_from_inqueue_to_sending__linrs(book_): """Book received and completed; checks if can remove book from INQUEUE.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START: %s" % book_, wdb.SHOW_START) found, to_remove, the_nick = remove_from_queue__lirs(book_) if found: put_in_sending__linrs(to_remove, the_nick) else: if book_.startswith("!SearchOok") and book_.endswith(".txt.zip"): return wp.wprint("From INQUEUE\t Book not found.") wp.print_bad_book_name__lis(book_, "INQUEUE to SENDING")
def remove_from_queue__lirs(bkitem): """Remove book from IN_QUEUE if there.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START : %s" % bkitem, wdb.SHOW_START) found, to_remove, the_nick = find_in_dictionary(d.INQUEUE, bkitem) if found: with d.INQUEUE_LOCK__L: del d.INQUEUE[to_remove] if the_nick in d.NICKLIST: d.NICKLIST[the_nick][d.NUM_IN_QUEUE] -= 1 d.BOOK_LIST_CHANGED = True wp.update_bar__lirs() return found, to_remove, the_nick
def move_to_queue(): """Start call_back to move items. Items from REQUEST_QUEUE to go to INQUEUE. """ # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START", wdb.SHOW_START) if d.MOVE_HOOK_CHRONOLIST: w.unhook(d.MOVE_HOOK_CHRONOLIST) # wait(3000) d.MOVE_HOOK_CHRONOLIST = w.hook_timer(d.REQUEST_DELAY * 1000, 0, len(d.REQUEST_QUEUE), "cb_move_to_queue__lirs", "")
def run_queue_if_anyone_online__lbcinrs(): """Start running requests if any nick online. Checks if anyone online, then puts up to MAX_QUEUE in REQUEST_QUEUE and then starts requesting each and moving to INQUEUE. """ # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START", wdb.SHOW_START) nicks_online = n.check_if_anyone_online__lbinrs() if nicks_online: for nick in d.NICKLIST: add_items__lbcnr(nick) return restart_queue__lirs()
def move_book_from_sending_to_queue_bklist__lbcinrs(book_, nick_): """Book received and completed; checks if can remove book from INQUEUE.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START: %s" % book_, wdb.SHOW_START) found, to_remove, _ = remove_from_sending__lirs(book_) if found: if book_add__lbinrs(to_remove) > 0 and add_items__lbcnr(nick_): restart_queue__lirs() else: if book_.startswith("!SearchOok") and book_.endswith(".txt.zip"): return wp.wprint("From SENDING\t Book not found.") wp.print_bad_book_name__lis(book_, "SENDING to BKLIST/QUEUE")
def move_one_queue_to_downloading__lbcinrs(this_nick): """Start receiving a book. For a nick, changes 1 from NUM_IN_QUEUE to DOWNLOADING. """ # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START| %s" % this_nick, wdb.SHOW_START) if this_nick in d.NICKLIST and add_items__lbcnr(this_nick) > 0: # moved these lines to other functions - remove when working right.9 # NICKLIST[this_nick][NUM_IN_QUEUE] -= 1 # NICKLIST[this_nick][DOWNLOAD] += 1 restart_queue__lirs()
def start_queue__lbcinrs(): """Start INQUEUE by checking if anyone is online. Starts adding items by online nicks. """ # global QUEUE_RUNNING, NICKLIST, RUNNING # wp.debug_ print("START\tstart queue") # wp.wprint("QUEUE\t STARTING") # wp.wprint("START QUEUE\t Begin") # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START", wdb.SHOW_START) if d.RUNNING: d.QUEUE_RUNNING = run_queue_if_anyone_online__lbcinrs() # print_queue_status("QUEUE STARTING") wp.update_bar__lirs()
def save_under_notify_list(): """Save the original irc.server.'under'.notify configuration setting.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START", wdb.SHOW_START) # "mangagino,FlipMoran,FlipMoran*,FlipMoran2,Heisenburg,BenHex" # save the original notify list in variable ORIGINAL_NOTIFY_LIST # "irc.server.under.notify" d.OPTION_NOTIFY = w.config_get(d.UNDER_NOTIFY) if d.OPTION_NOTIFY: d.ORIGINAL_NOTIFY_LIST = w.config_string(d.OPTION_NOTIFY) d.NOTIFY_LIST_CHANGED = False else: wp.error_print( "Unable to save the original notify list. Tried to save: %s" % d.UNDER_NOTIFY, 2)
def check_if_anyone_online__lbinrs(): """Check if any nick is online. Returns true if yes, false if no notify online. """ # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START", wdb.SHOW_START) # check every nick(in NICKLIST) if they are in buffer any_nick_online = False for tnick in d.NICKLIST: check_if_nick_changed_status__lbinrs(tnick) if d.NICKLIST[tnick][d.ONLINE]: any_nick_online = True return any_nick_online
def remove_nick_from_queue__linrs(this_nick): """Remove a nick from NICKLIST. IE. no more books to download, alters notify list. """ # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START : %s" % this_nick, wdb.SHOW_START) if this_nick in d.NICKLIST: del d.NICKLIST[this_nick] wp.wprint("NICK Remove\tRemoved %s from Nicklist" % this_nick) d.NOTIFY_LIST_CHANGED = put_nicklist_in_notify() pull_nick_from_down_accept(this_nick) wp.update_bar__lirs() if is_nicklist_empty(): q.stop__linrs()
def move_book_from_queues_to_bklist__lbinrs(book_): """Move book from INQUEUE to BKLIST because download failed.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START : %s" % book_, wdb.SHOW_START) q_found, q_to_move, _ = remove_from_queue__lirs(book_) s_found, s_to_move, _ = remove_from_sending__lirs(book_) lost = True if q_found: lost = False book_add__lbinrs(q_to_move) if s_found: lost = False book_add__lbinrs(s_to_move) if lost: wp.print_bad_book_name__lis(book_, "INQUEUE to BOOKLIST")
def restart_queue__lirs(): """Check if need to move any books to INQUEUE from REQUEST_QUEUE. Returns the value for QUEUE_RUNNING """ # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START", wdb.SHOW_START) num_books_in_request = len(d.REQUEST_QUEUE) if num_books_in_request > 0: wp.wprint("\t Requesting %d items" % num_books_in_request) move_to_queue() # wp.wprint("RESTART QUEUE\tEnd returning true") d.QUEUE_RUNNING = True wp.update_bar__lirs() return True # wp.wprint("RESTART QUEUE\tEnd returning false") return False
def put_in_sending__linrs(to_move, t_nick): """Put this book request into the SENDING queue since we started receiving it.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START:to_move=%s, t_nick=%s" % (to_move, t_nick), wdb.SHOW_START) wp.debug(function_name, "Locking SENDING", wdb.SHOW_LOCKS) with d.SENDING_LOCK__L: d.SENDING[to_move] = {d.NICK: t_nick, d.TIME: time.time()} wp.debug(function_name, "Unlocking SENDING", wdb.SHOW_LOCKS) if t_nick in d.NICKLIST: d.NICKLIST[t_nick][d.DOWNLOAD] += 1 else: wp.debug(function_name, "Locking NICKLIST", wdb.SHOW_LOCKS) with d.NICKLIST_LOCK__L: d.NICKLIST[t_nick] = {d.ONLINE: True, d.NUM_IN_QUEUE: 0, d.DOWNLOAD: 1, d.NUM_BOOKS: 0} wp.debug(function_name, "Unlocking NICKLIST", wdb.SHOW_LOCKS) d.BOOK_LIST_CHANGED = True wp.update_bar__lirs()