Gentoo Archives: gentoo-portage-dev

From: Mike Frysinger <vapier@g.o>
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] [PATCH] portageq: add "colormap" helper
Date: Sun, 11 Mar 2012 06:06:34
Message-Id: 1331439341-23825-1-git-send-email-vapier@gentoo.org
1 Signed-off-by: Mike Frysinger <vapier@g.o>
2 ---
3 bin/isolated-functions.sh | 2 +-
4 bin/portageq | 8 ++++++++
5 pym/portage/output.py | 6 ++++++
6 pym/portage/package/ebuild/doebuild.py | 8 ++------
7 4 files changed, 17 insertions(+), 7 deletions(-)
8
9 diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
10 index 9321ad5..98be41e 100644
11 --- a/bin/isolated-functions.sh
12 +++ b/bin/isolated-functions.sh
13 @@ -431,8 +431,8 @@ set_colors() {
14 BAD=$'\e[31;01m'
15 HILITE=$'\e[36;01m'
16 BRACKET=$'\e[34;01m'
17 + NORMAL=$'\e[0m'
18 fi
19 - NORMAL=$'\e[0m'
20 }
21
22 RC_ENDCOL="yes"
23 diff --git a/bin/portageq b/bin/portageq
24 index 5ecbb21..fcdb9d9 100755
25 --- a/bin/portageq
26 +++ b/bin/portageq
27 @@ -44,6 +44,7 @@ del pym_path
28 from portage import os
29 from portage.eapi import eapi_has_repo_deps
30 from portage.util import writemsg, writemsg_stdout
31 +from portage.output import colormap
32 portage.proxy.lazyimport.lazyimport(globals(),
33 'subprocess',
34 '_emerge.Package:Package',
35 @@ -685,6 +686,13 @@ def distdir(argv):
36 print(portage.settings["DISTDIR"])
37
38
39 +def colormap(argv):
40 + """
41 + Display the color.map as environment variables.
42 + """
43 + print(portage.output.colormap())
44 +
45 +
46 def envvar(argv):
47 """<variable>+
48 Returns a specific environment variable as exists prior to ebuild.sh.
49 diff --git a/pym/portage/output.py b/pym/portage/output.py
50 index 43d7503..98bec81 100644
51 --- a/pym/portage/output.py
52 +++ b/pym/portage/output.py
53 @@ -325,6 +325,12 @@ def style_to_ansi_code(style):
54 ret += codes.get(attr_name, attr_name)
55 return ret
56
57 +def colormap():
58 + mycolors = []
59 + for c in ("GOOD", "WARN", "BAD", "HILITE", "BRACKET", "NORMAL"):
60 + mycolors.append("%s=$'%s'" % (c, style_to_ansi_code(c)))
61 + return "\n".join(mycolors)
62 +
63 def colorize(color_key, text):
64 global havecolor
65 if havecolor:
66 diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py
67 index c45aa03..4ff3eea 100644
68 --- a/pym/portage/package/ebuild/doebuild.py
69 +++ b/pym/portage/package/ebuild/doebuild.py
70 @@ -50,7 +50,7 @@ from portage.exception import DigestException, FileNotFound, \
71 IncorrectParameter, InvalidDependString, PermissionDenied, \
72 UnsupportedAPIException
73 from portage.localization import _
74 -from portage.output import style_to_ansi_code
75 +from portage.output import colormap
76 from portage.package.ebuild.prepare_build_dirs import prepare_build_dirs
77 from portage.util import apply_recursive_permissions, \
78 apply_secpass_permissions, noiselimit, normalize_path, \
79 @@ -300,11 +300,7 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None,
80 mysettings["PORTAGE_CONFIGROOT"], EBUILD_SH_ENV_DIR)
81
82 # Allow color.map to control colors associated with einfo, ewarn, etc...
83 - mycolors = []
84 - for c in ("GOOD", "WARN", "BAD", "HILITE", "BRACKET"):
85 - mycolors.append("%s=$'%s'" % \
86 - (c, style_to_ansi_code(c)))
87 - mysettings["PORTAGE_COLORMAP"] = "\n".join(mycolors)
88 + mysettings["PORTAGE_COLORMAP"] = colormap()
89
90 if "COLUMNS" not in mysettings:
91 # Set COLUMNS, in order to prevent unnecessary stty calls
92 --
93 1.7.8.5

Replies