summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-04-04 21:13:55 +0000
committerZac Medico <zmedico@gentoo.org>2006-04-04 21:13:55 +0000
commit36ca784c142e6954f76b299d4a97d6de327bcac4 (patch)
tree0b824114439be7727f8c21d49dca3f1c93c36cc3
parent87a1101e8fc06fda3311d50e7c9737cf1acb4e14 (diff)
downloadportage-36ca784c142e6954f76b299d4a97d6de327bcac4.tar.gz
portage-36ca784c142e6954f76b299d4a97d6de327bcac4.tar.bz2
portage-36ca784c142e6954f76b299d4a97d6de327bcac4.zip
Add support for user configuration of colors in the output module for bug #125120. Thanks to solar for the patch that this was derived from.
svn path=/main/trunk/; revision=3072
-rw-r--r--pym/output.py45
-rw-r--r--pym/portage_const.py1
-rw-r--r--pym/portage_exception.py3
3 files changed, 48 insertions, 1 deletions
diff --git a/pym/output.py b/pym/output.py
index e735d4d47..89821e52d 100644
--- a/pym/output.py
+++ b/pym/output.py
@@ -3,7 +3,10 @@
# $Id: /var/cvsroot/gentoo-src/portage/pym/output.py,v 1.24.2.4 2005/04/17 09:01:55 jstubbs Exp $
-import commands,os,sys,re
+import commands,errno,os,re,shlex,sys
+from portage_const import COLOR_MAP_FILE
+from portage_util import writemsg
+from portage_exception import PortageException, ParseError, PermissionDenied, FileNotFound
havecolor=1
dotitles=1
@@ -88,6 +91,46 @@ codes["brown"] = esc_seq + "33m"
codes["red"] = esc_seq + "31;01m"
codes["darkred"] = esc_seq + "31m"
+def parse_color_map():
+ myfile = COLOR_MAP_FILE
+ ansi_code_pattern = re.compile("^[0-9;]*m$")
+ def strip_quotes(token, quotes):
+ if token[0] in quotes and token[0] == token[-1]:
+ token = token[1:-1]
+ return token
+ try:
+ s = shlex.shlex(open(myfile))
+ s.wordchars = s.wordchars + ";" # for ansi codes
+ d = {}
+ while True:
+ k, o, v = s.get_token(), s.get_token(), s.get_token()
+ if k is s.eof:
+ break
+ if o != "=":
+ raise ParseError("%s%s'%s'" % (s.error_leader(myfile, s.lineno), "expected '=' operator: ", o))
+ k = strip_quotes(k, s.quotes)
+ v = strip_quotes(v, s.quotes)
+ if ansi_code_pattern.match(v):
+ codes[k] = esc_seq + v
+ else:
+ if v in codes:
+ codes[k] = codes[v]
+ else:
+ raise ParseError("%s%s'%s'" % (s.error_leader(myfile, s.lineno), "Undefined: ", v))
+ except (IOError, OSError), e:
+ if e.errno == errno.ENOENT:
+ raise FileNotFound(myfile)
+ elif e.errno == errno.EACCES:
+ raise PermissionDenied(myfile)
+ raise
+
+try:
+ parse_color_map()
+except FileNotFound, e:
+ pass
+except PortageException, e:
+ writemsg("%s\n" % str(e))
+
def nc_len(mystr):
tmp = re.sub(esc_seq + "^m]+m", "", mystr);
return len(tmp)
diff --git a/pym/portage_const.py b/pym/portage_const.py
index af8aac8b7..dc523b879 100644
--- a/pym/portage_const.py
+++ b/pym/portage_const.py
@@ -39,6 +39,7 @@ EBUILD_SH_ENV_FILE = USER_CONFIG_PATH+"/bashrc"
INVALID_ENV_FILE = "/etc/spork/is/not/valid/profile.env"
CUSTOM_MIRRORS_FILE = USER_CONFIG_PATH+"/mirrors"
CONFIG_MEMORY_FILE = PRIVATE_PATH + "/config"
+COLOR_MAP_FILE = USER_CONFIG_PATH + "/color.map"
INCREMENTALS=["USE","USE_EXPAND","USE_EXPAND_HIDDEN","FEATURES","ACCEPT_KEYWORDS","ACCEPT_LICENSE","CONFIG_PROTECT_MASK","CONFIG_PROTECT","PRELINK_PATH","PRELINK_PATH_MASK"]
STICKIES=["KEYWORDS_ACCEPT","USE","CFLAGS","CXXFLAGS","MAKEOPTS","EXTRA_ECONF","EXTRA_EINSTALL","EXTRA_EMAKE"]
diff --git a/pym/portage_exception.py b/pym/portage_exception.py
index c00965d6e..c90b17567 100644
--- a/pym/portage_exception.py
+++ b/pym/portage_exception.py
@@ -49,6 +49,9 @@ class DirectoryNotFound(InvalidLocation):
class OperationNotPermitted(PortageException):
"""An operation was not permitted operating system"""
+class PermissionDenied(PortageException):
+ """Permission denied"""
+
class ReadOnlyFileSystem(PortageException):
"""Read-only file system"""