From c399a6690b7981f1bd6c513666c4b37d71b5a855 Mon Sep 17 00:00:00 2001 From: necoro <> Date: Sat, 10 Mar 2007 19:19:33 +0000 Subject: First plugin support --- portato/helper.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'portato/helper.py') diff --git a/portato/helper.py b/portato/helper.py index d66e256..b41dbbe 100644 --- a/portato/helper.py +++ b/portato/helper.py @@ -10,7 +10,7 @@ # # Written by René 'Necoro' Neumann et.al. -import traceback, os.path +import traceback, os.path, sys DEBUG = True @@ -33,7 +33,7 @@ def debug(*args, **kwargs): If you pass the optional keyword-argument "name", it is used for the function-name instead of the original one.""" - if not DEBUG : return + if not DEBUG and not ("warn" in kwargs or "error" in kwargs): return stack = traceback.extract_stack() minus = -2 @@ -50,14 +50,24 @@ def debug(*args, **kwargs): else: text = 'In %s (%s:%s): %s' % (c, a, b, text) - text = "***DEBUG*** %s ***DEBUG***" % text + outfile = sys.stdout + surround = "DEBUG" + + if "warn" in kwargs: + outfile = sys.stderr + surround = "WARNING" + elif "error" in kwargs: + outfile = sys.stderr + surround = "ERROR" + + text = ("***%s*** %s ***%s***" % (surround, text, surround)) if "file" in kwargs: f = open(kwargs["file"], "a+") f.write(text+"\n") f.close() else: - print text + print >> outfile, text def am_i_root (): """Returns True if the current user is root, False otherwise. -- cgit v1.2.3