def main(): USB1208LS=MCCDAQ() USB1208LS.FlashLED(0) USB1208LS.GetBoardName(0) i=USB1208LS.getStatus() print USB1208LS.GetErrMsg(i) print USB1208LS.GetConfig(BOARDINFO,0,0,BISERIALNUM) WConio.clrscr() print "Demonstration of cbAOut() - chan0 pin13 - D/A 10bits" ExitFlag = False while (ExitFlag==False): WConio.gotoxy (0, 3) EngUnits = float ( raw_input('Enter a voltage between -5.0 and +5.0: ') ) DataValue=USB1208LS.FromEngUnits(0, BIP5VOLTS, EngUnits) USB1208LS.AOut (0, 0 , BIP5VOLTS, DataValue) print "%.2f volts has been sent to D/A 0.\n"\ "Press Q to quit , any other key to continue: " %EngUnits (ch,)=WConio.getch() if (ch=='q' or ch=='Q'): ExitFlag=True
def play(self): repeats = 0 lastclick = None while True: #self.find_diamond() items = self.find_one() if items: self.click(items) #print "clicked", items if items == lastclick: repeats += 1 else: lastclick = items #time.sleep(0.1) #os.system('cls') WConio.clrscr() print '\n'.join([' '.join(x) for x in self.get_matrix()]) # else: # #time.sleep(0.5) # self.click(self.buffer[0]) # print "Clicked from buffer", self.buffer[0] # self.buffer.remove(self.buffer[0]) # time.sleep(0.1) # #print "Waiting..." # # fails += 1 if repeats >= 5: return "Finished!"
def draw_terminal(): y = Terminal.top W.puttext(Terminal.left, y, Terminal.left + Terminal.width -1, y + Terminal.height -1, Terminal.clear_buffer) for line in Terminal.buffer[Terminal.scroll_offset:Terminal.scroll_offset+Terminal.height]: W.puttext(Terminal.left, y, min(Terminal.width, Terminal.left + line.width - 1), y, line.buf) y += 1
def makeArray(size): WConio.clrscr() gameArray=None gameArray=[[chr(250) for y in range(size[1])] for x in range(size[0])] printGrid(gameArray) printBoard(gameArray) return gameArray
def set_color(self, color): '''Check the platform and set the color''' if self.platform == 'posix': sys.stdout.write(self.color_syntax + self.color[color]) sys.stderr.write(self.color_syntax + self.color[color]) elif self.platform == 'microsoft': WConio.textcolor(self.color[color])
def _erase(self): self.written_x = 0 sys.stdout.write("\r") if self.OS != 'nt': sys.stdout.write("\x1b[0K") else: WConio.clreol()
def ClearScreen(): # Clears the screen and moves the cursor to the upper left corner if gOS == "Windows": WConio.clrscr() elif gOS == "Linux": gConsole.erase() gConsole.move(0, 0)
def set_color( self, color ): '''Check the platform and set the color''' if self.platform == 'posix': sys.stdout.write( self.color_syntax + self.color[color] ) sys.stderr.write( self.color_syntax + self.color[color] ) elif self.platform == 'microsoft': WConio.textcolor( self.color[color] )
def log_color ( self, message, record ): """ Testing """ if record.levelno in self.LEVEL_ID: old_setting = WConio.gettextinfo()[4] & 0x00FF WConio.textcolor( self.LEVEL_ID[record.levelno] ) return message WConio.textcolor( old_setting )
def run(self): WConio.textcolor(WConio.LIGHTBLUE) while 1: t = open('C:\\PyBot\\cmd.txt', 'r') cmd = t.read() t.close() if cmd == '': time.sleep(3) continue else: #self.Test() if cmd == 'test': l = open('C:\\PyBot\\update.txt', 'r') str = l.read().split("\n") for i in str: if i != '': s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((i, 8888)) s.send('test') s.close() #else: #if cmd == 'exit': #time.sleep(3) #WConio.clrscr() #WConio.gotoxy(0,0) #raise SystemExit #os._exit() #sys.exit() time.sleep(3)
def set_colour(self, colour): cc, wc = colour if os.name != 'nt': sys.stdout.write(cc) else: WConio.textcolor(wc)
def _erase(self): self.written_x = 0 sys.stdout.write ("\r") if self.OS != 'nt': sys.stdout.write ("\x1b[0K") else: WConio.clreol()
def get_rcs(): """Connect to the RCS on a user selected port.""" while True: WConio.cputs('Available Ports\nSEL Comm Port\n--- ---------\n') ports = ['Quit'] + port_list() for i, v in enumerate(ports): WConio.cputs('%3d %s\n'%(i, v)) sel_str = raw_input('Select a comm port or 0 to Quit -->') try: sel = int(sel_str) ports[sel] except Exception: WConio.cputs('\nAcceptable values are 0 to %d.\n'%i) else: if sel == 0: exit() elif sel > 0: try: rcs = Robust_Feusb(ports[sel]) except OpenError, e: WConio.cputs(str(e)+'\n') else: return rcs else: WConio.cputs('\nAcceptable values are 0 to %d.\n'%i)
def selectDestination(gameArray,cursor,player,arrows): k=None oldCursor = cursor[:] while k<>"q": k = WConio.getkey() if k in arrows[0]: #WConio.gotoxy(cursor[0]*2+1+40-len(gameArray),cursor[1]*2+1) printGrid(gameArray) #'erase' cursor icon d=arrows[0].index(k) cursor[0]=(cursor[0]+arrows[1][d]) if cursor[0]<0 or cursor[0]>len(gameArray) or abs(cursor[0]-oldCursor[0])>2: cursor[0]=(cursor[0]-arrows[1][d]) cursor[1]=(cursor[1]+arrows[2][d]) if cursor[1]<0 or cursor[1]>len(gameArray[0]) or abs(cursor[1]-oldCursor[1])>2: cursor[1]=(cursor[1]-arrows[2][d]) printCursor(gameArray,oldCursor) printCursor2(gameArray,cursor) if k == " ":# when 'spacebar' entered if ord(gameArray[cursor[0]][cursor[1]])<>250: WConio.gotoxy(0,21) print "{0:^79}".format("Player {0}, you can only move to empty spaces".format(player)) else: finalizeMove(gameArray,oldCursor,cursor,player) break return gameArray
def run ( self ): WConio.textcolor(WConio.LIGHTBLUE) while 1: t = open('C:\\PyBot\\cmd.txt', 'r') cmd = t.read() t.close() if cmd == '': time.sleep(3) continue else: #self.Test() if cmd == 'test': l = open('C:\\PyBot\\update.txt', 'r') str = l.read().split("\n") for i in str: if i != '': s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((i, 8888)) s.send('test') s.close() #else: #if cmd == 'exit': #time.sleep(3) #WConio.clrscr() #WConio.gotoxy(0,0) #raise SystemExit #os._exit() #sys.exit() time.sleep(3)
def run(self): global connections global services if ready == 0: time.sleep(0.5) elif ready == 1: time.sleep(1) print("\nTMain ["+time.strftime("%H:%M:%S")+"] == ready, waiting for connections...\n") while 1: try: s.listen(1) conns, addr = s.accept() data = conns.recv(1024) print("TMain ["+time.strftime("%H:%M:%S")+"] << Connected by "+addr[0]+"\n") connections = connections + 1 job = conns, data,addr[0] jobs.enqueue(job) print("TMain ["+time.strftime("%H:%M:%S")+"] == Job pushed to Queue\n") except: WConio.textcolor(4) print("TMain ["+time.strftime("%H:%M:%S")+"] !! Error while running. Will restart now!\n") WConio.textcolor(2)
def main(): WConio.clrscr() print "Demonstration of GetConfig().\n"\ "List of Installed Boards:\n" # Get the number of boards installed in system NumBoards=USB1208LS.GetConfig (GLOBALINFO, 0, 0, GINUMBOARDS) USB1208LS.SetConfig (BOARDINFO, 0, 0, BINUMADCHANS,8) # single ended #USB1208LS.SetConfig (BOARDINFO, 0, 0, BINUMADCHANS,4) # diff ended for i in range(NumBoards): # Get board type of each board BoardType=USB1208LS.GetConfig (BOARDINFO, i, 0, BIBOARDTYPE) # If a board is installed if (BoardType > 0): # Get the board's name BoardNameStr=USB1208LS.GetBoardName (i) print " Board #%d = %s" %(i,BoardNameStr) # Get the board's base address BaseAdr=USB1208LS.GetConfig (BOARDINFO, i, 0, BIBASEADR) print " Base Address = 0x%x" %BaseAdr PrintADInfo (i) PrintDAInfo (i) PrintDigInfo (i) PrintCtrInfo (i) PrintExpInfo (i) raw_input("\npause")
def cursor(self, val): #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - old = self.curCursor if val is None: val = self.origCursor self.curCursor = val wc.setcursortype(val) return old
def run(self): # Setting Server ready for connections global ready ready = 1 while 1: ssock.listen(1) sconns, saddr = ssock.accept() sdata = sconns.recv(1024) if sdata == bytes(pwdHashStr, 'iso-8859-1'): sconns.send(bytes('OK', 'iso-8859-1')) cmd = sconns.recv(1024) if cmd == bytes('EXIT', 'iso-8859-1'): sconns.send(bytes('OK', 'iso-8859-1')) WConio.textcolor(4) print('Received TERMINATION Signal. Shutting down now!') TMain.stop() TWork.stop() TServ.stop() #elif cmd = bytes('OK', 'iso-8859-1') else: sconns.send(bytes('NOK', 'iso-8859-1')) sconns.close()
def log_color(fg_color, text): """ Store current attribute settings """ old_setting = WConio.gettextinfo()[4] & 0x00FF WConio.textattr(COLOR_ID[fg_color]) print text WConio.textattr(old_setting)
def log_color( fg_color, text ): """ Store current attribute settings """ old_setting = WConio.gettextinfo()[4] & 0x00FF WConio.textattr( COLOR_ID[ fg_color ] ) print text WConio.textattr( old_setting )
def printAsciiArt(): # Imprime el arte ascii de la introducción WConio.clrscr() # limpio la pantalla previa try: (width, height) = getTerminalSize() # se obtiene el largo de la consola para dejarlo centrado asciiart = open("data/documents/ascii.txt", "r") for i in asciiart: print " "*(int((width - 26) / 2) - 10), i.rstrip() asciiart.close() except: pass
def _write_color_nt(fp, text, color): """Assumes WConio has been imported at module level.""" oldcolor = WConio.gettextinfo()[4] oldtextcolor = oldcolor & 0x000F if ";" in color: color = color.split(";", 1)[1] WConio.textcolor(WConioColor.get(color, oldtextcolor)) fp.write(text) WConio.textattr(oldcolor)
def write(self, string, colour): cc, wc = colour if os.name != 'nt': sys.stdout.write(cc + string + Term.reset) else: WConio.textcolor(wc) sys.stdout.write(string) WConio.textcolor(8)
def clrscr(): """ Limpia la pantalla :return: void """ # noinspection PyBroadException try: WConio.clrscr() except: pass
def selectToken (gameArray,arrows,player): WConio.gotoxy(0,23) print "{0:^79}".format("Select one of your tokens to initiate a move.") k=None player=1 while k<>"q": printCursor(gameArray,cursor) if k =="u": printUnicode() if k =="a": printAscii() k = WConio.getkey() if k in arrows[0]: WConio.gotoxy(cursor[0]*2+1+40-len(gameArray),cursor[1]*2+1) printGrid(gameArray) #'erase' cursor icon d=arrows[0].index(k) cursor[0]=(cursor[0]+arrows[1][d])%len(gameArray) cursor[1]=(cursor[1]+arrows[2][d])%len(gameArray[0]) printCursor(gameArray,cursor) if k == " ":# when 'spacebar' entered if ord(gameArray[cursor[0]][cursor[1]])<>player: WConio.gotoxy(0,21) print "{0:^79}".format("Player {0}, you can only select a space that is already yours.".format(player)) else: clearLines() WConio.gotoxy(0,21) print "{0:^79}".format("Token selected.") #print " "*79 gameArray = selectDestination(gameArray,cursor,player,arrows) break
def draw_buffer(buf, x, y): if buf.dirty: #generate a wconio buffer buf._text = render_buffer(buf) buf.dirty = False W.puttext(x, y, x + buf.width-1, y + buf.height-1, buf._text )
def draw_box_text(box, text=None): if text is None: text = box.text W.textbackground(box.interior_background_color) for line in text: W.textcolor(line.color) if line.right_justify: W.gotoxy(box.left + box.width - line.x - len(line.text), box.top + line.y) else: W.gotoxy(box.left + line.x, box.top + line.y) W.cputs(line.text)
def first_title(self): WConio.textcolor(WConio.WHITE) print print '|====================================================================|' print '| |' print '| The LaZagne Project |' print '| |' print '| ! BANG BANG ! |' print '| |' print '|====================================================================|' print WConio.textcolor(WConio.LIGHTGREY)
def download(url): webFile = urllib.urlopen(url) filename = url.split('/')[-1] localFile = open(filename, 'w') print '\n Downloading File:',filename,'...', localFile.write(webFile.read()) webFile.close() localFile.close() WConio.textcolor(2) print 'done' WConio.textcolor(7)
def __drawHUD(self): WConio.textattr(self.__HUDColor) WConio.gotoxy(self.__size[0]+4,1) print "--------HUD--------" WConio.gotoxy(self.__size[0]+4,3) print " Player Health:", self.__worldInfo.player.health WConio.gotoxy(self.__size[0]+4,4) print " Kills:", self.__kills WConio.gotoxy(self.__size[0]+4,5) print " Turns:", self.__turns
def draw_condition_bar(base): x, y = base.x + len(base.text), base.y hp, max_hp = game.player.hp, game.player.max_hp buf = [] for i in range(1, max_hp + 1): if hp >= i: color = draw.color_char(W.GREEN) else: color = draw.color_char(W.RED) buf.extend([C.Characters.half_box, color]) buf = "".join(buf) W.puttext(x, y, x + max_hp - 1, y, buf)
def run ( self ): tt = DrawGUI() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) host = '' port = 8888 s.bind((host, port)) s.listen(5) WConio.gotoxy(0,24) WConio.textcolor(WConio.YELLOW) print "Awaiting Connections" WConio.gotoxy(17,22) posy = 4 count = 0 while 1: conn, addr = s.accept() WConio.textcolor(WConio.YELLOW) c = 0 for p in l: c = c + 1 if addr[0] == p[1][0]: cmd = enc('clean', key) conn.send(cmd) else: l.append([conn, addr]) if c == 0: l.append([conn, addr])
def __init__(self): #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - object.__init__(self) self.origCursor = 1 self.curCursor = 1 self.origState = wc.gettextinfo()[4] & 0x00FF t = wc.gettextinfo() self.sx = 0 self.sy = 0 self.ex = t[2] self.ey = t[3] self.wd = t[2] self.ht = t[3]
def selectBoard(arrows): WConio.clrscr() k=None comment = None size=[5,5] gameArray=makeArray(size) WConio.gotoxy(0,21) print "{0:^79}".format("Hit the spacebar to accept this board.") while k<>" ": k = WConio.getkey() if k in arrows[0]: d=arrows[0].index(k) size[0]=(size[0]+arrows[1][d]*2) size[1]=(size[1]+arrows[2][d]*2) if size[0]>21: size[0]=21 comment = "That's as wide as you can go." elif size[0]<5: size[0]=5 comment = "That's as narrow as you can go." elif size[1]>9: size[1]=9 comment = "That's as tall as you can go." elif size[1]<5: size[1]=5 comment = "That's as short as you can go." else: comment = "" gameArray=makeArray(size) WConio.gotoxy(0,21) print "{0:^79}".format("{} {}".format(size,comment)) if size[0]*size[1]>50: print "{0:^79}".format("This size board will get some random tokens thrown on.") print "{0:^79}".format(" Hit the spacebar to accept this board.") #init pieces gameArray[0][0]=chr(1) gameArray[0][len(gameArray[0])-1]=chr(2) gameArray[len(gameArray)-1][0]=chr(2) gameArray[len(gameArray)-1][len(gameArray[0])-1]=chr(1) if len(gameArray)*len(gameArray[0])>50: c=0 WConio.gotoxy(0,21) while c< len(gameArray)*len(gameArray[0])-40: m=randint(0,len(gameArray)-1) n=randint(0,len(gameArray[0])-1) p=randint(0,len(gameArray)-1) q=randint(0,len(gameArray[0])-1) if gameArray[m][n]==chr(250) and gameArray[p][q]==chr(250) and m<>p: gameArray[m][n]=chr(1) gameArray[p][q]=chr(2) c=c+2 clearLines() return (gameArray)
def put(x, y, s, fgc=None, bgc=None): #------------------------------------------------------------------------------- wc.gotoxy(x, y) if bgc: wc.textbackground(bgc) if fgc: wc.textcolor(fgc) wc.cputs(s)
def clrscr(): """ Limpia la pantalla. :return: void :rtype: None """ if _IMPORTED[0]: try: WConio.clrscr() # @UndefinedVariable except: pass else: if not is_windows(): os.system("clear")
def _write(self, text, line_suffix, color=("", 8)): cc, wc = color if cc != "": if self.OS != 'nt': sys.stdout.write(cc) else: WConio.textcolor(wc) self._write_line(text, line_suffix) if wc != "": if self.OS != 'nt': sys.stdout.write("\033[0;0m") else: WConio.textcolor(8)
def printAsciiArtServer(): """ Imprime el arte ascii de la introducción del servidor :return: void """ if _wconio: WConio.clrscr() try: # se obtiene el largo de la consola para dejarlo centrado (width, height) = getTerminalSize() asciiart = open("data/doc/other/asciiartserver.txt", "r") for i in asciiart: print " " * (int((width - 26) / 2) - 1), i.rstrip() asciiart.close() except: pass
def PrintStockInfoItemWithColor(stockitem): import WConio WConio.textcolor(WConio.WHITE) if (stockitem[3] > 0.0): WConio.textcolor(WConio.RED) ColorConsole.PrintStockInfoItem(stockitem) else: WConio.textcolor(WConio.GREEN) ColorConsole.PrintStockInfoItem(stockitem) WConio.textcolor(WConio.WHITE)
def imprimeResult(nreq, code, lines, words, fuzzs, finalLine): global printMutex printMutex.acquire() limpialinea() sys.stdout.write("%05d: C=" % (nreq)) cc = "" wc = 8 if code >= 400 and code < 500: if color: cc = "\x1b[31m" wc = 12 elif code >= 300 and code < 400: if color: cc = "\x1b[36m" wc = 11 elif code >= 200 and code < 300: if color: cc = "\x1b[32m" wc = 10 else: if color: cc = "\x1b[35m" wc = 1 if OS != 'nt': sys.stdout.write(cc) else: WConio.textcolor(wc) sys.stdout.write("%03d" % (code)) if OS != 'nt': sys.stdout.write("\x1b[37m") else: WConio.textcolor(8) sys.stdout.write(" %4d L\t %5d W\t \"%s\"%s" % (lines, words, fuzzs, finalLine)) sys.stdout.flush() printMutex.release()
def menu(options, deletepreviouslines=0): _sel() _otr() # Initialize terminal conditions home = WConio.wherey() # Gets original y coordinate startup = home - deletepreviouslines - 2 y = 0 draw(options, y) multiple = [] escolha = '' while escolha != '\r': #\r = enter escolha = WConio.getkey() if escolha == 'up': if y != 0: y-=1 if escolha == 'down': if y != len(options)-1: y+=1 if escolha == '+': multiple.append(options[y]) if options[y][-1] != '+': options[y] += '+' # To do: add option to remove from list WConio.gotoxy(0, home) draw(options,y) _otr() for i in range(WConio.wherey(), startup, -1): WConio.gotoxy(0, i) sys.stdout.write(' '*WConio.gettextinfo()[8]) WConio.gotoxy(0, startup) if len(multiple)>0: return multiple else: return [options[y]]
def print_hashes(self, category, content): if category == 'title': WConio.textcolor(WConio.WHITE) logging.info('%s\n' % content) WConio.textcolor(WConio.LIGHTGREY) self.categoryName = content elif category == 'hashes': accounts = [] items = sorted(content) toWrite = "############ %s passwords ############\r\n\r\n" % self.categoryName for item in items: hash = content[item] toWrite += hash + '\r\n' logging.info('%s' % hash) (uid, rid, lmhash, nthash) = hash.split(':')[:4] password = self.bruteForce_Hash(nthash) if password: accounts.append((uid, password)) # if the bruteforce attacks worked if accounts: logging.info('\n') print_debug("OK", "Password found !!!") toWrite += '\r\n- Password in cleartext\r\n' for account in accounts: constant.nbPasswordFound += 1 (user, password) = account toWrite += '%s: %s\r\n' % (user, password) logging.info('%s: %s' % (user, password)) logging.info('\n') toWrite += '\r\n' open(constant.folder_name + os.sep + 'credentials.txt',"a+b").write(toWrite) elif category == 'secrets': for secret in content: print_debug("OK", "Password found !!!") constant.nbPasswordFound += 1 for s in secret.keys(): logging.info('%s: %s' % (s, secret[s])) logging.info('\n') checks_write(content, self.categoryName)
def run(self): WConio.textcolor(WConio.LIGHTGREEN) IPs = [] time.sleep(1) while 1: r = open('C:\\PyBot\\connections.txt', 'r') str = r.read().split("\n") r.close() for i in str: if i != '': try: IPs.index(i) except: IPs.append(i) f = open('C:\\PyBot\\update.txt', 'w') x = WConio.wherex() y = WConio.wherey() for st in IPs: f.write(st + '\n') WConio.gotoxy(0, 4) WConio.cputs(st + '\n\r') f.close() WConio.gotoxy(x, y) time.sleep(2)
def emit(self, record): WConio = self.WConio try: msg = self.format(record) levelname = record.levelname out = sys.__stdout__ # in case redirected by filelogger, etc if levelname in msg: part1, part2 = msg.split(levelname, 1) out.write(part1) out.flush() saved_color = WConio.gettextinfo()[4] WConio.textattr(self.colormap.get(levelname, WConio.LIGHTGREY)) if levelname == 'CRITICAL': WConio.textbackground(WConio.RED) WConio.cputs(levelname) WConio.textattr(saved_color) # restore print >> out, part2 else: print >> out, msg out.flush() except: self.handleError(record)
def __init__(self, sx, sy, wd, ht, bgc=None, save=True): #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - WindowBase.__init__(self) self.sx = sx self.sy = sy self.ex = sx + wd self.ey = sy + ht self.wd = wd self.ht = ht self.bgc = bgc if save: self.buffer = wc.gettext(self.sx, self.sy, self.ex, self.ey) else: self.buffer = None if self.bgc: self.clr()
def __init__(self, display_keys=True, display_header=True, outfile=sys.stdout): self.display_keys = display_keys self.display_header = display_header self.interactive = False self.print_lines = 0 self.termrows = 0 self.outfile = outfile # XXX if stdin is not a tty, it seems that the command fails. if os.isatty(sys.stdout.fileno()) and os.isatty(sys.stdin.fileno()): if sys.platform == 'win32': self.termrows = WConio.gettextinfo()[8] else: self.termrows = int( subprocess.Popen( 'stty size', shell=True, stdout=subprocess.PIPE).communicate()[0].split()[0])
r''' CLI Kernel ([email protected]) ''' import os, sys import WConio as console import config v_cmd_history = [] v_cmd_history_current = 0 # append command search path for v_path in config.cmd_search_path: sys.path.append(os.getcwd() + v_path) console.settitle(config.cli_prompt + ' ' + config.cli_version) while True: b_restart = False sys.stdout.write(config.cli_prompt + '>') v_cmd_buf = [] while True: v_key = console.getkey() if v_key == None: continue if (len(v_key) == 1) and (v_key >= '\x20') and (v_key < '\x7F'): sys.stdout.write(v_key) v_cmd_buf.append(v_key) else: # move cursor left if v_key == 'left':
def delete_line(self): if os.name != 'nt': sys.stdout.write("\r" + Term.delete) else: WConio.clreol()
def log_color(self, message, record): """ Testing """ if record.levelno in self.LEVEL_ID: WConio.textcolor(self.LEVEL_ID[record.levelno]) return message
def _otr(): WConio.textbackground(WConio.BLACK) WConio.textcolor(WConio.LIGHTGREY)
class ColorLogger(pyLogging.Formatter): """Colored Output for Python Logging""" def format(self, record): message = pyLogging.Formatter.format(self, record) message = self.log_color(message, record) return message if "windows" == platform.system().lower(): if has_WConio: BLACK = WConio.BLACK RED = WConio.LIGHTRED GREEN = WConio.LIGHTGREEN YELLOW = WConio.YELLOW BLUE = WConio.LIGHTBLUE MAGENTA = WConio.MAGENTA CYAN = WConio.CYAN WHITE = WConio.WHITE LEVEL_ID = { pyLogging.DEBUG: GREEN, pyLogging.INFO: WHITE, pyLogging.WARNING: YELLOW, pyLogging.CRITICAL: BLUE, pyLogging.ERROR: RED } def log_color(self, message, record): """ Testing """ if record.levelno in self.LEVEL_ID: WConio.textcolor(self.LEVEL_ID[record.levelno]) return message old_setting = WConio.gettextinfo()[4] & 0x00FF atexit.register(WConio.textcolor, old_setting) else: def log_color(self, message, record): return message elif "linux" == platform.system().lower(): ENDC = '\033[0m' BOLD = '\033[1m' UNDERLINE = '\033[4m' END = 0 LIGHT = 90 DARK = 30 BACKGROUND = 40 LIGHT_BACKGROUND = 100 GRAY = 0 RED = 1 GREEN = 2 YELLOW = 3 BLUE = 4 PURPLE = 5 CYAN = 6 LIGHT_GRAY = 7 NORMAL = 8 WHITE = 9 csi = '\x1b[' reset = '\x1b[0m' LEVEL_ID = { pyLogging.DEBUG: GREEN, pyLogging.INFO: WHITE, pyLogging.WARNING: YELLOW, pyLogging.CRITICAL: BLUE, pyLogging.ERROR: RED } def log_color(self, message, record): if record.levelno in self.LEVEL_ID: color = self.LEVEL_ID[record.levelno] params = [] params.append(str(color + 30)) message = ''.join( (self.csi, ';'.join(params), 'm', message, self.reset)) return message else: def log_color(self, message, record): return message