def add_item__lbnr(this_nick): """Find a book from a nick and adds to 0 and requests from server.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START: %s" % this_nick, wdb.SHOW_START) book, nick = get_item_from_list(d.BKLIST, this_nick) if this_nick == nick: dict_item = {book: nick} wp.debug(function_name, "Locking REQUEST", wdb.SHOW_LOCKS) with d.RQ_LOCK__L: d.REQUEST_QUEUE.append(dict_item) wp.debug(function_name, "Unlocking REQUEST", wdb.SHOW_LOCKS) wp.debug(function_name, "Locking NICKLIST", wdb.SHOW_LOCKS) with d.NICKLIST_LOCK__L: if this_nick in d.NICKLIST: d.NICKLIST[this_nick][d.NUM_IN_QUEUE] += 1 d.NICKLIST[this_nick][d.NUM_BOOKS] -= 1 wp.debug(function_name, "Unlocking NICKLIST", wdb.SHOW_LOCKS) wp.debug(function_name, "DOWNLOAD %s for %s" % (dict_item, this_nick), wdb.SHOW_INFO) wp.wprint("Added to Request\t %s" % book) wp.debug(function_name, "locking BOOKLIST", wdb.SHOW_LOCKS) with d.BOOKLIST_LOCK__L: del d.BKLIST[book] d.BOOK_LIST_CHANGED = True wp.debug(function_name, "Unlocking BOOKLIST", wdb.SHOW_LOCKS)
def check_if_nick_changed_status__lbinrs(this_nick): """Look if one nick has gone from online to offline or vice versa.""" # 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_value = False if this_nick in d.NICKLIST: wp.debug(function_name, "Locking NICKLIST", wdb.SHOW_LOCKS) with d.NICKLIST_LOCK__L: current_status = d.NICKLIST[this_nick][d.ONLINE] d.NICKLIST[this_nick][d.ONLINE] = channel_has_nick( d.SERVER, d.CHANNEL, this_nick) wp.debug(function_name, "Unlocking NICKLIST", wdb.SHOW_LOCKS) if current_status: if not d.NICKLIST[this_nick][d.ONLINE]: q.clear_queue__lbinrs(this_nick) if check_if_nick_done(this_nick): remove_nick_from_queue__linrs(this_nick) wp.wprint("Nick\t %s changed status to OFFLINE" % this_nick) # wp.update_bar__lirs() return_value = True elif d.NICKLIST[this_nick][d.ONLINE]: wp.wprint("NICK\t %s changed status to ONLINE" % this_nick) return_value = True if return_value: wp.update_bar__lirs() return return_value
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 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 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 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 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 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 add_items__lbcnr(this_nick): # type: (str) -> int """Determines the number of books which can be added for this_nick. Checks if Nick is online. Starts checking if can put items INQUEUE and requests to add can_add items. """ # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START", wdb.SHOW_START) # Find number already in queue for nick and the number of books for nick in list. if this_nick in d.NICKLIST: thnum_in_queue = d.NICKLIST[this_nick][d.NUM_IN_QUEUE] thnum_books = d.NICKLIST[this_nick][d.NUM_BOOKS] else: # Nick is not in list nicklist, so error, print the error. wp.error_print("Nick not in LIST:%s" % this_nick, 3) return 0 # Check if nick is online and if any can be added. If not, return 0.(last line) # wp.wprint("q.add_items\t Nick:%s, Books:%d, Queued:%d" % # (this_nick, thnum_books, thnum_in_queue)) if n.is_nick_online(this_nick) and thnum_in_queue < d.QUEUE_MAX: # Determine how many can be added. MAX(usually 2) - number currently in queue. can_add = d.QUEUE_MAX - thnum_in_queue # Check if number of books in list is > number that can be added, otherwise set can be added # to the number of books in list. if thnum_books < can_add: can_add = thnum_books wp.wprint("Can add %d Books for %s from list consisting of %d Books, %d Queued, %s is Online" % (can_add, this_nick, thnum_books, thnum_in_queue, this_nick)) # If books can be added, make sure there is not another hook for added books and add them. if can_add > 0: if this_nick in d.CHRONOLIST: wp.debug(function_name, "Locking CHRONOLIST", wdb.SHOW_LOCKS) with d.CHRONOLIST_LOCK__L: w.unhook(d.CHRONOLIST[this_nick]) del d.CHRONOLIST[this_nick] wp.debug(function_name, "Unlocking CHRONOLIST", wdb.SHOW_LOCKS) # Add the books to INQUEUE. for _ in range(can_add): add_item__lbnr(this_nick) # return the number of books added. return can_add return 0
def check_join_again__lj(nick_, times_called): """Restart the joining hook for a nick.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START", wdb.SHOW_START) wp.wprint(function_name + "\t " + "%s: called=%d" % (nick_, times_called)) if times_called > 0: times_called *= 2 else: times_called = 4 wp.debug(function_name, "Locking JOINING_CHRONOLIST", wdb.SHOW_LOCKS) with d.JOINING_CHRONOLIST_LOCK__L: if nick_ in d.JOINING_CHRONOLIST: w.unhook(d.JOINING_CHRONOLIST[nick_]) del d.JOINING_CHRONOLIST[nick_] if times_called < 100: d.JOINING_CHRONOLIST[nick_] = w.hook_timer( times_called * d.JOINING_DELAY, 0, 2, "cb_joining__lbcijnrs", str(times_called) + "," + nick_) wp.debug(function_name, "Unlocking JOINING_CHRONOLIST", wdb.SHOW_LOCKS)
def stop__linrs(): """Stop script; remove notify hooks, stop__linrs queue.""" # global ORIGINAL_NOTIFY_LIST, NOTIFY_LIST_CHANGED, NICK_HOOKJ, NICK_HOOKB # global NICK_HOOKQ, NICK_HOOKA, RUNNING # stop__linrs the queue, boolean running means current state of queue # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START", wdb.SHOW_START) d.RUNNING = stop_queue__linrs() # reset notify list for under to original value if d.NOTIFY_LIST_CHANGED: n.set_under_notify_list(d.ORIGINAL_NOTIFY_LIST) d.NOTIFY_LIST_CHANGED = False h.remove_my_hooks() h.remove_new_hooks() # # # Received file send completed # = w.hook_signal('xfer_ended', 'cb_XFER_ENDED_SIGNAL', '') # # # Started receiving the file # hooks_list[HOOKS_DCC] = w.hook_signal('irc_DCC', 'cb_DCC', '') # # # This NEVER happened and the CallBack is missing!!! # CHECK WHY YOU ADDED THIS # hooks_list[HOOKS_rISON] = w.hook_hsignal('irc_redirection_%s_ison' % SCRIPT_NAME, # 'redirect_ison handler', '') # # # START timed hook every 30 minutes to check if not received book in 35 minutes if d.HOOK_BOOK_WAIT_TIMER is not None: w.unhook(d.HOOK_BOOK_WAIT_TIMER) d.HOOK_BOOK_WAIT_TIMER = None # # check if anyone is online every 10 minutes if d.HOOK_TIME_CONNECT is not None: w.unhook(d.HOOK_TIME_CONNECT) d.HOOK_TIME_CONNECT = None wp.update_bar__lirs() wp.wprint("Book Downloads are stopped.")
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)