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 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 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 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 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 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 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 move_request_to_inqueue__lirs(): """Actual move one item from REQUEST_QUEUE to INQUEUE.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START", wdb.SHOW_START) popitem = {} wp.debug(function_name, "Locking REQUEST", wdb.SHOW_LOCKS) with d.RQ_LOCK__L: if d.REQUEST_QUEUE: popitem = d.REQUEST_QUEUE.pop() wp.debug(function_name, "Unlocking REQUEST", wdb.SHOW_LOCKS) for tbook, tnick in popitem.items(): request_book__lirs(d.SERVER, d.CHANNEL, tbook) with d.INQUEUE_LOCK__L: d.INQUEUE[tbook] = {d.NICK: tnick, d.TIME: time.time()} wp.update_bar__lirs()
def remove_from_sending__lirs(book_): """Remove book from SENDING when book has been downloaded.""" # 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 = find_in_dictionary(d.SENDING, book_) if found: wp.debug(function_name, "Locking SENDING", wdb.SHOW_LOCKS) with d.SENDING_LOCK__L: del d.SENDING[to_remove] if the_nick in d.NICKLIST: d.NICKLIST[the_nick][d.DOWNLOAD] -= 1 wp.debug(function_name, "Unlocking SENDING", wdb.SHOW_LOCKS) d.BOOK_LIST_CHANGED = True wp.update_bar__lirs() return found, to_remove, the_nick
def remove_from_request_queue__lirs(bkitem): """Remove book from REQUEST_QUEUE if there.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START", wdb.SHOW_START) found, to_remove, the_nick = find_in_request_queue(bkitem) if found: wp.debug(function_name, "Locking REQUEST", wdb.SHOW_LOCKS) with d.RQ_LOCK__L: del d.REQUEST_QUEUE[to_remove] if the_nick in d.NICKLIST: d.NICKLIST[the_nick][d.NUM_IN_QUEUE] -= 1 wp.debug(function_name, "Unlocking REQUEST", wdb.SHOW_LOCKS) d.BOOK_LIST_CHANGED = True wp.update_bar__lirs() return found, to_remove
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 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()
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 remove_from_booklist__lbirs(bkitem): """Remove book from BKLIST if there.""" # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START", wdb.SHOW_START) # Find the book in BKLIST. found, to_remove, the_nick = find_in_book_list__lb(bkitem) # If book is found, then remove it from the BKLIST, indicate the BKLIST has changed, and update # the status bar. if found: wp.debug(function_name, "Locking BOOKLIST", wdb.SHOW_LOCKS) with d.BOOKLIST_LOCK__L: del d.BKLIST[to_remove] if the_nick in d.NICKLIST: d.NICKLIST[the_nick][d.NUM_BOOKS] -= 1 wp.debug(function_name, "Unlocking BOOKLIST", wdb.SHOW_LOCKS) d.BOOK_LIST_CHANGED = True wp.update_bar__lirs() # Return whether the book was found and the name of the book. return found, to_remove
def book_add__lbinrs(th_book): """Add book to BKLIST, book list from a line of a search. From the original line in a search on UnderNet server, this will remove extra info and add the nick, book to the BKLIST. """ # noinspection PyProtectedMember function_name = sys._getframe().f_code.co_name # pylint: disable=W0212 wp.debug(function_name, "START : %s" % th_book, wdb.SHOW_START) # // check if starts with a '!' following by a nick added = 0 if th_book.startswith("!"): # // pull out the ending ::INFO::.*$ # // remove any extra part to downloading books - from most nick/bots book = (re.sub("::INFO::.*$", "", th_book)).strip() # remove the ---- xx.x KB form other nicks like !new # noinspection Annotator book = (re.sub(r'\s+-+\s[.\d]+\s[MKG]B', "", book)).strip() # // pull out the nick nick = (re.findall(r"(?<=^!)\w+", book))[0] wp.debug(function_name, "Locking BOOKLIST", wdb.SHOW_LOCKS) with d.BOOKLIST_LOCK__L: wp.debug(function_name, "Locking NICKLIST", wdb.SHOW_LOCKS) with d.NICKLIST_LOCK__L: if book not in d.BKLIST: d.BKLIST[book] = nick d.BOOK_LIST_CHANGED = True added = 1 if nick in d.NICKLIST: d.NICKLIST[nick][d.NUM_BOOKS] += 1 else: d.NICKLIST[nick] = {d.ONLINE: False, d.NUM_IN_QUEUE: 0, d.DOWNLOAD: 0, d.NUM_BOOKS: 1} n.put_nicklist_in_notify() wp.debug(function_name, "Unlocking NICKLIST", wdb.SHOW_LOCKS) wp.debug(function_name, "Unlocking BOOKLIST", wdb.SHOW_LOCKS) wp.update_bar__lirs() return added