Ejemplo n.º 1
0
    def run(self):
        try:
            while not self.stopped or not self.queue.empty():
                try:
                    # get will wait .1 seconds before throwing an exception
                    outargs = self.queue.get(True, 0.1)
                    outtype = outargs[0]
                    outdata = outargs[1]
                except Exception, e:  # get throws an exception if it reached the time and didn't get anything
                    continue

                ###Handle calls to chop.json
                if outtype == "json":
                    self.handle_json(outdata, outargs[2])  # outargs[2] is the custom encoder
                    continue

                ###Handle calls to chop.savefile
                if outtype == "savefile":
                    # outargs[2] is data
                    # outargs[3] is mode
                    # outargs[4] is finalize
                    self.handle_savefile(outdata, outargs[2], outargs[3], outargs[4])
                    continue

                ###Handle calls to chop.prnt and chop.debug
                ###Below are for text and dbg types
                # outargs[2] is supress
                # outargs[3] is color
                self.handle_text_dbg(outtype, outdata, outargs[2], outargs[3])
        except:
            CSD.debug_out("Exception in CoreHelper\n")
            raise
Ejemplo n.º 2
0
    def json(self, obj):
        if not self.outq:
            CSD.debug_out("No outq for " + self.name + "\n")
            return

        tosend = ["json", obj, self.cls]
        self.outq.put(tosend)
Ejemplo n.º 3
0
    def appendfile(self, filename, data, finalize=False):
        if not self.outq:
            CSD.debug_out("No outq for " + self.name + "\n")
            return

        tosend = ["savefile", filename, data, "a", finalize]
        self.outq.put(tosend)
Ejemplo n.º 4
0
    def resize_ui(self, use_self, attempts=0):

        CSD.debug_out("Resize Called (" + ` attempts ` + ") -\n\t" +
                      ` curses.LINES ` + " " + ` curses.COLS ` + "\n")

        if use_self:  #there's no need to do another lookup if called by check_resize_ui
            (w, h) = (self.windowW, self.windowH)
        else:
            try:
                (h, w) = self.check_term_size()
            except:
                CSD.debug_out("Exception in check_term_size\n")
                raise

        CSD.debug_out("\t" + ` h ` + " " + ` w ` + "\n")

        if (curses.COLS == w and curses.LINES == h):
            return

        (curses.COLS, self.windowW) = (w, w)
        (curses.LINES, self.windowH) = (h, h)

        #clear all of the windows
        self.stdscr.clear()
        self.nav_window.clear()
        self.title_window.clear()
        self.data_window.clear()

        #Need to refresh to remove extraneous characters that might be leftover
        self.nav_window.nooutrefresh()
        self.title_window.nooutrefresh()
        self.stdscr.nooutrefresh()

        #Get the new dimensions of the navigation and data windows
        self.calculate_dimensions()

        CSD.debug_out("Resizing Nav - " + ` curses.LINES - 2 ` + " " +
                      ` curses.COLS / 8 ` + "\n")

        #Resize Windows
        self.title_window.resize(1, curses.COLS)
        self.nav_window.resize(self.nlines, self.ncols)
        self.data_window.resize(BUFFER_SIZE, self.dcols)

        self.update_title()

        #Reset autoscroll on all panels
        for key in self.panel_id_list:
            self.panels[key].autoscroll = True

        #Attempt to refresh the windows
        #if it fails, retry up to 5 times -- haven't seen it make it higher than 3
        try:
            self.update_windows()
        except curses.error:
            if (attempts > 5):
                raise
            self.resize_ui(False, attempts + 1)
Ejemplo n.º 5
0
 def run(self):
     try:
         while not self.stopped or not self.dataq.empty():
             try:
                 # get will wait .1 seconds before throwing an exception
                 outargs = self.dataq.get(True, 0.1)
                 outpan = outargs[0]
                 outtype = outargs[1]
                 outdata = outargs[2]
             except Queue.Empty, e:
                 continue
             except Exception, e:
                 CSD.debug_out("UiHelper Exception %s\n" % str(e))
Ejemplo n.º 6
0
    def check_resize_ui(self):
        try:
            (h,w) = self.check_term_size()
        except:
            CSD.debug_out("Exception in check_term_size\n")
            raise

        if (w != self.windowW) or (h != self.windowH):
            self.windowW = w
            self.windowH = h
            self.resize_ui(True)
            return True

        return False
Ejemplo n.º 7
0
    def check_resize_ui(self):
        try:
            (h, w) = self.check_term_size()
        except:
            CSD.debug_out("Exception in check_term_size\n")
            raise

        if (w != self.windowW) or (h != self.windowH):
            self.windowW = w
            self.windowH = h
            self.resize_ui(True)
            return True

        return False
Ejemplo n.º 8
0
    def scroll_end(self): #scrolls to the end of the data_window
        #Scrolls to the "end"
        CSD.debug_out("Window positions Y,X: %u, %u\n" % self.data_window.getyx())
        (y, x) = self.data_window.getyx() # get current position of cursor

        end = y
        end_pos = 0
        if end - self.dlines > 0:
            end_pos = end - ((self.dlines/16) * 15) #arbitrarily 15/16 of the screen

        if end_pos > BUFFER_SIZE:
            end_pos = BUFFER_SIZE

        CSD.debug_out("Setting end position to: " + str(end_pos) + "\n")

        self.__current_panel__().position = end_pos
Ejemplo n.º 9
0
    def resize_ui(self, use_self, attempts = 0):

        CSD.debug_out("Resize Called (" + `attempts` +") -\n\t" + `curses.LINES` + " " + `curses.COLS` + "\n")

        if use_self: #there's no need to do another lookup if called by check_resize_ui
            (w,h) = (self.windowW, self.windowH)
        else:
            try:
                (h,w) = self.check_term_size()
            except:
                CSD.debug_out("Exception in check_term_size\n")
                raise

        CSD.debug_out("\t" + `h` + " " +`w` + "\n")

        if(curses.COLS == w and curses.LINES == h):
            return

        (curses.COLS, self.windowW) = (w,w)
        (curses.LINES,self.windowH) = (h,h)

        #clear all of the windows
        self.stdscr.clear()
        self.nav_window.clear()
        self.title_window.clear()
        self.data_window.clear()

        #Need to refresh to remove extraneous characters that might be leftover
        self.nav_window.nooutrefresh()
        self.title_window.nooutrefresh()
        self.stdscr.nooutrefresh()

        #Get the new dimensions of the navigation and data windows
        self.calculate_dimensions()

        CSD.debug_out("Resizing Nav - " + `curses.LINES - 2` + " " + `curses.COLS/8` + "\n")

        #Resize Windows
        self.title_window.resize(1,curses.COLS)
        self.nav_window.resize(self.nlines, self.ncols)
        self.data_window.resize(BUFFER_SIZE, self.dcols)

        self.update_title()
            
        #Reset autoscroll on all panels
        for key in self.panel_id_list:
            self.panels[key].autoscroll = True

        #Attempt to refresh the windows
        #if it fails, retry up to 5 times -- haven't seen it make it higher than 3
        try:
            self.update_windows()
        except curses.error:
            if(attempts > 5):
                raise 
            self.resize_ui(False, attempts + 1)
Ejemplo n.º 10
0
    def scroll_end(self):  #scrolls to the end of the data_window
        #Scrolls to the "end"
        CSD.debug_out("Window positions Y,X: %u, %u\n" %
                      self.data_window.getyx())
        (y, x) = self.data_window.getyx()  # get current position of cursor

        end = y
        end_pos = 0
        if end - self.dlines > 0:
            end_pos = end - (
                (self.dlines / 16) * 15)  #arbitrarily 15/16 of the screen

        if end_pos > BUFFER_SIZE:
            end_pos = BUFFER_SIZE

        CSD.debug_out("Setting end position to: " + str(end_pos) + "\n")

        self.__current_panel__().position = end_pos
Ejemplo n.º 11
0
    def run(self):
        self.calculate_dimensions()
        self.windowH = curses.LINES
        self.windowW = curses.COLS

        self.title_window = curses.newwin(1,0,0,0)
        self.nav_window = curses.newwin(self.nlines, self.ncols, self.nyval, self.nxval)
        #Create the pad window
        self.data_window = curses.newpad(BUFFER_SIZE, self.dcols)
        self.data_window.keypad(1)
        self.data_window.timeout(100) #100 ms

        self.update_title()
        self.update_windows()

        CSD.debug_out("Before While Loop\n")

        counter = time.time()
        self.started = True
        while not self.stopped:
            c = self.data_window.getch()

            self.check_resize_ui()
            #Update every 1 seconds
            newtime = time.time()
            if newtime - counter >= 1 :
                counter = newtime
                if self.panels[self.current_win].autoscroll:
                    self.scroll_end()

                #check to see if window has been resized
                if not self.check_resize_ui():
                    self.update_windows()

            if not self.handle_input(c):
                break
Ejemplo n.º 12
0
    def prettyprnt(self, color, *fmtstring):
        if not self.outq:
            CSD.debug_out("No outq for " + self.name + "\n")
            return

        mystring = ""

        supress = False
        extents = None
        if fmtstring[-1] is None:
            extents = -1
            supress = True

        for strn in fmtstring[0:extents]:
            strn = str(strn)
            if mystring != "":
                mystring += " "
            mystring += strn

        tosend = ["text", mystring, supress, color]
        self.outq.put(tosend)

        tosendm = [self.index, "text", mystring, supress, color]
        self.dataq.put(tosendm)
Ejemplo n.º 13
0
 def update_windows(self):
     CSD.debug_out("Updating Window\n")
     self.update_navigation()
     self.update_pad()
Ejemplo n.º 14
0
 def stop(self):
     CSD.debug_out("ChopUi stop called\n")
     self.stopped = True
Ejemplo n.º 15
0
 def stop(self):
     CSD.debug_out("ChopShopCurses stop called\n")
     self.nui.stop()#should run once more then quit
     self.nui.join()
     self.teardown()
     CSD.debug_out("ChopShopCurses stop complete\n")
Ejemplo n.º 16
0
 def join(self):
     while self.nui.is_alive(): #loop so signals still work
         self.nui.join(.1)
     self.teardown()
     CSD.debug_out("ChopShopCurses join complete\n")
Ejemplo n.º 17
0
            try:
                self.ui_stop_fn()
            except Exception, e:
                #TODO
                pass
            return False
        elif (c == ord('Q')):
            #Stop the Core
            try:
                self.lib_stop_fn()
            except:
                pass
        else:
            if c != -1:
                CSD.debug_out("Unknown Key\n")

        return True

    def add_panel(self, panel_id, name):
        ndvwin = vpanel(name)
        self.panels[panel_id] = ndvwin

        current_key = None
        if len(self.panel_id_list) > self.current_win:
            current_key = self.panel_id_list[self.current_win]
            
        self.panel_id_list = []
        for j in self.panels.iterkeys():
            self.panel_id_list.append(j)
Ejemplo n.º 18
0
                    pass
                sys.stdout.write("\n") 
            outq.put('fini')
            return
        elif data[0] == 'cont':
            break
        elif data[0] == 'exit':
            return

    try:
        f = open('/dev/null', 'w')
        os.dup2(f.fileno(), 1)
        g = open('/dev/null', 'r')
        os.dup2(g.fileno(), 0)
    except:
        CSD.debug_out("Error assigning dev/null as output\n")
        pass

    corecommand.setup_var(options)
    #Setup main and debug handlers
    ccore = ChopCore(options, module_list)

    global chop
    #Setups up main/debug panels/windows and also informs other side that we're ready
    #to setup module windows/panels
    chop = corecommand.setup_modules_begin(ccore)

    #setup ccore Core
    #Sets up 'chop' class and windows/panels
    ccore.prep_modules()
Ejemplo n.º 19
0
 def stop(self):
     CSD.debug_out("ChopGui stop called\n")
     self.cui.stop()
     self.cui.join()
Ejemplo n.º 20
0
 def stop(self):
     CSD.debug_out("ChopGui stop called\n")
     self.cui.stop()
     self.cui.join()
Ejemplo n.º 21
0
    def handle_input(self, c):
        if (c == -1): #means the timeout was reached and no key was received
            return True
        if (c == curses.KEY_RESIZE):#Due to timeout and whatnot this event is not always received
            self.resize_ui(False)
        elif (c == curses.KEY_LEFT or c == ord('h')):
            if self.current_win != 0:
                self.current_win -= 1
                self.update_windows()
        elif (c == curses.KEY_RIGHT or c == ord('l')):
            if self.current_win != len(self.panels) - 1:
                self.current_win += 1
                self.update_windows()
        elif (c == curses.KEY_UP or c == ord('k')):
            if self.panels[self.current_win].position > 0:
                self.panels[self.current_win].position -= 1
                self.update_pad_simple()
        elif (c == curses.KEY_DOWN or c == ord('j')):
            if self.panels[self.current_win].position < BUFFER_SIZE:
                self.panels[self.current_win].position += 1
                self.update_pad_simple()
        elif (c == curses.KEY_NPAGE or c == ord('J')):
            if self.panels[self.current_win].position >= BUFFER_SIZE - 10:
                self.panels[self.current_win].position = BUFFER_SIZE
            else:
                self.panels[self.current_win].position += 10
            self.update_pad_simple()
        elif (c == curses.KEY_PPAGE or c == ord('K')):
            if self.panels[self.current_win].position <= 10:
                self.panels[self.current_win].position = 0
            else:
                self.panels[self.current_win].position -= 10
            self.update_pad_simple()
        elif (c == ord('b')): #scroll to the beginning
            self.panels[self.current_win].position = 0
            self.update_pad_simple()
        elif (c == ord('n')): #scroll to the end
            self.scroll_end()
            self.update_pad_simple()
        elif (c == ord('s')):#Toggles autoscrolling -- by default this is enabled
            if self.panels[self.current_win].autoscroll:
                self.panels[self.current_win].autoscroll = False
            else:
                self.panels[self.current_win].autoscroll = True
        elif (c == ord('q')):
            #Stop the Core
            try:
                self.core.put(['stop'])
            except:
                pass
            return False
        elif (c == ord('Q')):
            #Stop the Core
            try:
                self.core.put(['stop'])
            except:
                pass
        else:
            if c != -1:
                CSD.debug_out("Unknown Key\n")

        return True
Ejemplo n.º 22
0
 def resize(self):
     CSD.debug_out("Resize called\n")
     start = len(self.data)/4
     self.data = self.data[start:]
Ejemplo n.º 23
0
            try:
                self.ui_stop_fn()
            except Exception, e:
                #TODO
                pass
            return False
        elif (c == ord('Q')):
            #Stop the Core
            try:
                self.lib_stop_fn()
            except:
                pass
        else:
            if c != -1:
                CSD.debug_out("Unknown Key\n")

        return True

    def add_panel(self, panel_id, name):
        ndvwin = vpanel(name)
        self.panels[panel_id] = ndvwin

        current_key = None
        if len(self.panel_id_list) > self.current_win:
            current_key = self.panel_id_list[self.current_win]

        self.panel_id_list = []
        for j in self.panels.iterkeys():
            self.panel_id_list.append(j)
Ejemplo n.º 24
0
 def join(self):
     while self.nui.is_alive():  #loop so signals still work
         self.nui.join(.1)
     self.teardown()
     CSD.debug_out("ChopShopCurses join complete\n")
Ejemplo n.º 25
0
 def stop(self):
     CSD.debug_out("ChopShopCurses stop called\n")
     self.nui.stop()  #should run once more then quit
     self.nui.join()
     self.teardown()
     CSD.debug_out("ChopShopCurses stop complete\n")
Ejemplo n.º 26
0
 def update_windows(self):
     CSD.debug_out("Updating Window\n")
     self.update_navigation()
     self.update_pad()
Ejemplo n.º 27
0
                newline = "\n"
                if supress:
                    newline = ""

                self.panellist[panid].add_data(data + newline, color)

    def run(self):
        try:
            while not self.stopped or not self.dataq.empty():
                try:
                    # get will wait .1 seconds before throwing an exception
                    outargs = self.dataq.get(True, 0.1)
                    outpan = outargs[0]
                    outtype = outargs[1]
                    outdata = outargs[2]
                except Queue.Empty, e:
                    continue
                except Exception, e:
                    CSD.debug_out("UiHelper Exception %s\n" % str(e))

                ###Handle calls to chop.prnt and chop.debug
                ###Below are for text and dbg types
                # outargs[2] is supress
                # outargs[3] is color
                if outpan == -1:
                    outpan = self.dbgid
                self.handle_text_dbg(outtype, outpan, outdata, outargs[3], outargs[4])
        except:
            CSD.debug_out("Exception in UiHelper\n")
            raise