summaryrefslogtreecommitdiff
path: root/portato/__init__.py
diff options
context:
space:
mode:
authornecoro <>2007-07-13 04:09:51 +0000
committernecoro <>2007-07-13 04:09:51 +0000
commitfc6d232a9357211a44dad3300ff64571620aa1bf (patch)
tree2f31112805b8d05c94978775a183668dc260367c /portato/__init__.py
parentb5e8e2eb2b8bc9936070028ecf91ff8d0b7c33ef (diff)
downloadportato-fc6d232a9357211a44dad3300ff64571620aa1bf.tar.gz
portato-fc6d232a9357211a44dad3300ff64571620aa1bf.tar.bz2
portato-fc6d232a9357211a44dad3300ff64571620aa1bf.zip
new fancier log output
Diffstat (limited to '')
-rw-r--r--portato/__init__.py48
1 files changed, 47 insertions, 1 deletions
diff --git a/portato/__init__.py b/portato/__init__.py
index 4b1f42f..0166170 100644
--- a/portato/__init__.py
+++ b/portato/__init__.py
@@ -3,9 +3,55 @@
# File: portato/__init__.py
# This file is part of the Portato-Project, a graphical portage-frontend.
#
-# Copyright (C) 2006 René 'Necoro' Neumann
+# Copyright (C) 2006-2007 René 'Necoro' Neumann
# This is free software. You may redistribute copies of it under the terms of
# the GNU General Public License version 2.
# There is NO WARRANTY, to the extent permitted by law.
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
+
+import logging
+import sys
+import os
+
+class OutputFormatter (logging.Formatter):
+
+ colors = {
+ "blue" : 34,
+ "green" : 32,
+ "red" : 31,
+ "yellow": 33
+ }
+
+ def __init__(self, *args, **kwargs):
+ logging.Formatter.__init__(self, *args, **kwargs)
+
+ for key, value in self.colors.iteritems():
+ self.colors[key] = "\x1b[01;%02dm*\x1b[39;49;00m" % value
+
+ def format (self, record):
+ string = logging.Formatter.format(self, record)
+ color = None
+
+ if os.isatty(sys.stderr.fileno()):
+ if record.levelno <= logging.DEBUG:
+ color = self.colors["blue"]
+ elif record.levelno <= logging.INFO:
+ color = self.colors["green"]
+ elif record.levelno <= logging.WARNING:
+ color = self.colors["yellow"]
+ else:
+ color = self.colors["red"]
+ else:
+ color = "%s:" % record.levelname
+
+ return "%s %s" % (color, string)
+
+# set the whole logging stuff
+formatter = OutputFormatter("%(message)s (%(filename)s:%(lineno)s)")
+
+handler = logging.StreamHandler()
+handler.setFormatter(formatter)
+logging.getLogger().addHandler(handler)
+
+logging.getLogger().setLevel(logging.DEBUG)
bly.1.1Jason A. Donenfeld2-2/+2 2012-09-04No echo mode.Jason A. Donenfeld2-16/+42 2012-09-04Properly quote the path too.Jason A. Donenfeld1-1/+1 2012-09-04Allow passwords having spaces to go unbroken to the clipboard.Bernardo Freitas Paulo da Costa1-1/+1 2012-09-04Separate out the massive git example.Jason A. Donenfeld1-10/+14 2012-09-04Prepare for debianification.1.0Jason A. Donenfeld9-4/+60 2012-09-03Fix readme typo.Jason A. Donenfeld1-1/+1 2012-09-03Show program name properly in error message.Jason A. Donenfeld1-1/+1 2012-09-03Move examples into manpage.Jason A. Donenfeld4-93/+224 2012-09-03Make into a real project.Jason A. Donenfeld8-5/+173 2012-09-03Support pass gitJason A. Donenfeld2-1/+15 2012-08-31Add remove synonyms.Jason A. Donenfeld1-2/+2 2012-08-31Use basename in usage.Jason A. Donenfeld1-2/+1 2012-08-19now using gpg_id as a varMatthew Ramirez1-2/+2 2012-08-07Forty five seconds.Jason A. Donenfeld1-1/+1 2012-08-06Deal with klipper and new lines.Jason A. Donenfeld1-3/+19 2012-08-06Update examples.Jason A. Donenfeld1-7/+7 2012-08-06Update readme.Jason A. Donenfeld1-11/+13 2012-08-06Be slicker and more like git.Jason A. Donenfeld1-114/+173