|
From: <Blu...@us...> - 2010-09-10 19:20:49
|
Revision: 399
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=399&view=rev
Author: BlueWolf_
Date: 2010-09-10 19:20:43 +0000 (Fri, 10 Sep 2010)
Log Message:
-----------
Added a better way to log text to the console. Also added a config-option to change the amount of debugging. Fixed a rather stupid error in the core
Modified Paths:
--------------
trunk/client/VP.py
trunk/client/callback.py
trunk/client/configspec
trunk/client/core/parser.py
trunk/client/downloader.py
trunk/client/functions.py
Modified: trunk/client/VP.py
===================================================================
--- trunk/client/VP.py 2010-09-09 19:34:56 UTC (rev 398)
+++ trunk/client/VP.py 2010-09-10 19:20:43 UTC (rev 399)
@@ -81,7 +81,6 @@
sh['client'].connect(sh['config']['host']['host'], \
sh['config']['host']['port'])
-
# Wait for all the events to come
try:
while 1:
@@ -125,6 +124,8 @@
except: pass
sh['downloader'].stop()
sh['config'].write()
+
+ log("succeed", "System closed")
sys.exit()
@@ -157,7 +158,7 @@
pygame.display.update(rect)
def call(self, name, data):
- print " [>] \t", name, data
+ log("debug", "Call:", name + ' - ' + str(data))
sh['playground'].call(name, data)
sh['layout'].call(name, data)
Modified: trunk/client/callback.py
===================================================================
--- trunk/client/callback.py 2010-09-09 19:34:56 UTC (rev 398)
+++ trunk/client/callback.py 2010-09-10 19:20:43 UTC (rev 399)
@@ -23,15 +23,21 @@
class Callback(core.Callback):
def data_received(self, data):
- print " --> \t" + repr(data)
+ name = data.keys()[0]
+ value = data[name]
+ log("sendin", name + " - " + repr(data))
def data_send(self, data):
- print " <-- \t" + repr(data)
+ name = data.keys()[0]
+ value = data[name]
+ log("sendout", name + " - " + repr(data))
def connection_ready(self, public_rsa, reconnecting):
# We are connected
if reconnecting:
+ log("succeed", "Connection ready!", "Core is logging in again")
+
sh['main'].call("status", {
"status": "login",
"where": "logging in"
@@ -39,6 +45,9 @@
else:
# Do we need to log in automatically?
if sh['config']['user']['username'] != "":
+ log("succeed", "Connection ready!", "App is logging in based "+\
+ "on config-settings")
+
sh['main'].call("status", {
"status": "login",
"where": "logging in"
@@ -47,12 +56,16 @@
sh['config']['user']['password'])
else:
+ log("succeed", "Connection ready!")
+
sh['main'].call("status", {
"status": "login",
"where": "waiting"
})
def logged_in(self, username, cid, owner):
+ log("succeed", "We're logged in")
+
sh['main'].call("status", {
"status": "login",
"where": "downloading"
@@ -68,6 +81,8 @@
def failed_logging_in(self, reason):
# [TODO] Send the reason in some way
+ log("warning", "Failed logging in:", reason)
+
sh['main'].call("status", {
"status": "login",
"where": "waiting"
@@ -80,7 +95,10 @@
def disconnected(self, reason):
- print " !!! \tConnection closed: " + reason
+ if reason == "manual":
+ log("debug", "Connection closed:", reason)
+ else:
+ log("warning", "Connection closed:", reason)
sh['login_info'] = None
Modified: trunk/client/configspec
===================================================================
--- trunk/client/configspec 2010-09-09 19:34:56 UTC (rev 398)
+++ trunk/client/configspec 2010-09-10 19:20:43 UTC (rev 399)
@@ -9,3 +9,7 @@
[host]
host = string(default=vp.bluewolf.nl)
port = integer(default=6653)
+
+[debug]
+level = integer(min=1, max=5, default=2)
+use_colors = boolean(default=True)
Modified: trunk/client/core/parser.py
===================================================================
--- trunk/client/core/parser.py 2010-09-09 19:34:56 UTC (rev 398)
+++ trunk/client/core/parser.py 2010-09-10 19:20:43 UTC (rev 399)
@@ -56,8 +56,7 @@
self.sh['rsakey'] = msg['public']
- reconnect = (self.core.cid == None and self.sh['auto_login'])
-
+ reconnect = (self.core.cid == None and bool(self.sh['auto_login']))
self.call.connection_ready(msg['public'], reconnect)
if reconnect:
Modified: trunk/client/downloader.py
===================================================================
--- trunk/client/downloader.py 2010-09-09 19:34:56 UTC (rev 398)
+++ trunk/client/downloader.py 2010-09-10 19:20:43 UTC (rev 399)
@@ -40,7 +40,7 @@
def get_file(self, filename, filetype, callback, *arg):
- print " !!! \tDownload task:", filename
+ log("debug", "Download task:", filename)
# First check if we already have this file loaded
if filename in self.loaded_files:
@@ -68,7 +68,7 @@
self.queue.put((1, filename))
else:
- print "File '" + filename + "' is not in the repository!"
+ log("warning", "File '" + filename + "' is not in the repository!")
callback(filename, self.error(filetype, "not in repos"), *arg)
@@ -124,7 +124,7 @@
filename)
if not filename in sh['filetable']:
- print "File '" + filename + "' is not in the repository!"
+ log("warning", "File '"+filename+"' is not in the repository!")
self.callbacks(filename, task['callbacks'], \
self.error(task['filetype'], "not in repos"))
return
@@ -158,7 +158,7 @@
try: f = urllib2.urlopen(request)
except urllib2.URLError, e:
- print "Url '" + url + "' could not be found!"
+ log("warning", "Url '" + url + "' could not be found!")
self.callbacks(filename, task['callbacks'], \
self.error(filename, "not found"))
return
@@ -180,8 +180,8 @@
filename + ".tmp")
if checksum != filehash:
- print "Checksum mismatch for '" + filename + "! " + \
- filehash + " > " + checksum
+ log("warning" "Checksum mismatch for '" + filename + "!", \
+ filehash + " > " + checksum)
self.callbacks(filename, task['callbacks'], \
self.error(task['filetype'], "checksum"))
Modified: trunk/client/functions.py
===================================================================
--- trunk/client/functions.py 2010-09-09 19:34:56 UTC (rev 398)
+++ trunk/client/functions.py 2010-09-10 19:20:43 UTC (rev 399)
@@ -48,7 +48,7 @@
else:
image = image.convert_alpha()
except pygame.error, message:
- print 'Cannot load image:', fullname
+ log("error", 'Cannot load image:', fullname)
raise SystemExit, message
return image
@@ -70,8 +70,8 @@
sh['config'] = configobj.ConfigObj(real_path("config.conf"), \
configspec = real_path("configspec"))
except configobj.ParseError:
- print "Config: The config-file is malformed. Please check the file " + \
- "or remove it to create a new default one"
+ log("error", "Config:", "The config-file is malformed. Please check " +\
+ "the file or remove it to create a new default one")
sys.exit()
validator = Validator()
@@ -81,9 +81,60 @@
for (section_list, key, _) in configobj.flatten_errors(sh['config'], \
result):
if key is not None:
- print "Config: Something is wrong with the " + \
- "'%s/%s' key. Please check" % (section_list[0], key)
+ log("error", "Config:", "Something is wrong with the " + \
+ "'%s/%s' key. Please check" % (section_list[0], key))
else:
- print "Config: The '%s' section is missing" % section_list[0]
+ log("error", "Config:", \
+ "The '%s' section is missing" % section_list[0])
sys.exit()
+
+def log(t, *m):
+ def level(i):
+ return sh['config']['debug']['level'] >= i
+ use_colors = sh['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")
+ write("\n")
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|