From: <Blu...@us...> - 2010-09-14 21:23:33
|
Revision: 405 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=405&view=rev Author: BlueWolf_ Date: 2010-09-14 21:23:27 +0000 (Tue, 14 Sep 2010) Log Message: ----------- Better colors with screen (the program) now Modified Paths: -------------- trunk/server/callback.py trunk/server/functions.py Modified: trunk/server/callback.py =================================================================== --- trunk/server/callback.py 2010-09-14 19:28:33 UTC (rev 404) +++ trunk/server/callback.py 2010-09-14 21:23:27 UTC (rev 405) @@ -23,9 +23,9 @@ def __init__(self): self.clients = {} def data_received(self, cid, data): - log('sendin', cid + ": " + repr(data)) + log('recv', cid + ": " + repr(data)) def data_send(self, cid, data): - log('sendout', cid + ": " + repr(data)) + log('send', cid + ": " + repr(data)) def debug_crash(self, traceback): log('error', "\n*** Crash ***\n\n%s\n" % traceback) Modified: trunk/server/functions.py =================================================================== --- trunk/server/functions.py 2010-09-14 19:28:33 UTC (rev 404) +++ trunk/server/functions.py 2010-09-14 21:23:27 UTC (rev 405) @@ -24,6 +24,13 @@ try: from configobj import ConfigObj except: sys.exit("ERROR: You need the configobj-module for this to work!") + +# To get colors working in Windows. Though it works partially +if os.name == "nt": + try: import colarama + except: pass + else: + colarama.init() def config_defaults(config): @@ -71,54 +78,54 @@ config['database']['password'] = getpass("Database password: ") -def log(t, *m): - def level(i): - return config['debug']['level'] >= i - use_colors = config['debug']['use_colors'] - write = sys.stdout.write - def color(c): - write("\033[" + c + "m") - - message = "\t".join([str(part) for part in m]) - - if t == "error" and level(1): - icon = "!!!" - icon_color = "1;31;7" - text_color = "1;91" - - elif t == "warning" and level(2): - icon = "[!]" - icon_color = "1;33;7" - text_color = "93" - - elif t == "succeed" and level(3): - icon = "OK " - icon_color = "1;32;7" - text_color = "32" - - elif t == "debug" and level(4): - icon = " ~ " - icon_color = "1;7" - text_color = "" - - elif t == "sendin" and level(5): - icon = "|<-" - icon_color = "1;100;2" - text_color = "2" - - elif t == "sendout" and level(5): - icon = "|->" - icon_color = "1;100;2" - text_color = "2" - - else: - return - - if use_colors: color(icon_color) - write(" " + icon + " ") - if use_colors: color("0;" + text_color) - write("\t" + message) - if use_colors: color("0") +def log(t, *m): + def level(i): + return config['debug']['level'] >= i + use_colors = config['debug']['use_colors'] + write = sys.stdout.write + def color(c): + write("\033[" + c + "m") + + message = "\t".join([str(part) for part in m]) + + if t == "error" and level(1): + icon = "!!!" + icon_color = "1;31;7" + text_color = "1;91" + + elif t == "warning" and level(2): + icon = "[!]" + icon_color = "1;33;7" + text_color = "93" + + elif t == "succeed" and level(3): + icon = "OK " + icon_color = "1;32;7" + text_color = "32" + + elif t == "debug" and level(4): + icon = " ~ " + icon_color = "1;7" + text_color = "" + + elif t == "recv" and level(5): + icon = "|<-" + icon_color = "1;90;7" + text_color = "90" + + elif t == "send" and level(5): + icon = "|->" + icon_color = "1;90;7" + text_color = "90" + + else: + return + + if use_colors: color(icon_color) + write(" " + icon + " ") + if use_colors: color("0;" + text_color) + write("\t" + message) + if use_colors: color("0") write("\n") @@ -138,4 +145,4 @@ landscapes = LandscapeManager(db) - \ No newline at end of file + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |