Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH 2/4] Use distinct colors for output msg types
Date: Tue, 28 Sep 2021 14:20:17
Message-Id: 20210928142004.1375262-3-mgorny@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH 0/4] Output rewrite for better clarify and greppability by "Michał Górny"
1 Introduce distinct colors per output function. For elog and eerror
2 the colors remain the same but the names change. For einfo and eqawarn,
3 use darker colors to distinguish them.
4
5 Signed-off-by: Michał Górny <mgorny@g.o>
6 ---
7 bin/isolated-functions.sh | 30 +++++++++++-------
8 bin/save-ebuild-env.sh | 6 ++--
9 lib/portage/elog/messages.py | 10 +++---
10 lib/portage/elog/mod_echo.py | 4 +--
11 lib/portage/output.py | 59 +++++++++++++++++++++++++++++++-----
12 5 files changed, 81 insertions(+), 28 deletions(-)
13
14 diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
15 index 3e79ea6e3..df806d403 100644
16 --- a/bin/isolated-functions.sh
17 +++ b/bin/isolated-functions.sh
18 @@ -270,7 +270,7 @@ eqawarn() {
19 __elog_base QA "$*"
20 [[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2
21 echo -e "$@" | while read -r ; do
22 - echo " ${PORTAGE_COLOR_WARN}*${PORTAGE_COLOR_NORMAL} ${REPLY}" >&2
23 + echo " ${PORTAGE_COLOR_QAWARN}*${PORTAGE_COLOR_NORMAL} ${REPLY}" >&2
24 done
25 LAST_E_CMD="eqawarn"
26 return 0
27 @@ -280,7 +280,7 @@ elog() {
28 __elog_base LOG "$*"
29 [[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2
30 echo -e "$@" | while read -r ; do
31 - echo " ${PORTAGE_COLOR_GOOD}*${PORTAGE_COLOR_NORMAL} ${REPLY}" >&2
32 + echo " ${PORTAGE_COLOR_LOG}*${PORTAGE_COLOR_NORMAL} ${REPLY}" >&2
33 done
34 LAST_E_CMD="elog"
35 return 0
36 @@ -290,7 +290,7 @@ einfo() {
37 __elog_base INFO "$*"
38 [[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2
39 echo -e "$@" | while read -r ; do
40 - echo " ${PORTAGE_COLOR_GOOD}*${PORTAGE_COLOR_NORMAL} ${REPLY}" >&2
41 + echo " ${PORTAGE_COLOR_INFO}*${PORTAGE_COLOR_NORMAL} ${REPLY}" >&2
42 done
43 LAST_E_CMD="einfo"
44 return 0
45 @@ -299,7 +299,7 @@ einfo() {
46 einfon() {
47 __elog_base INFO "$*"
48 [[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2
49 - echo -ne " ${PORTAGE_COLOR_GOOD}*${PORTAGE_COLOR_NORMAL} $*" >&2
50 + echo -ne " ${PORTAGE_COLOR_INFO}*${PORTAGE_COLOR_NORMAL} $*" >&2
51 LAST_E_CMD="einfon"
52 return 0
53 }
54 @@ -318,7 +318,7 @@ eerror() {
55 __elog_base ERROR "$*"
56 [[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2
57 echo -e "$@" | while read -r ; do
58 - echo " ${PORTAGE_COLOR_BAD}*${PORTAGE_COLOR_NORMAL} ${RC_INDENTATION}${REPLY}" >&2
59 + echo " ${PORTAGE_COLOR_ERR}*${PORTAGE_COLOR_NORMAL} ${RC_INDENTATION}${REPLY}" >&2
60 done
61 LAST_E_CMD="eerror"
62 return 0
63 @@ -378,12 +378,16 @@ __unset_colors() {
64 COLS=80
65 ENDCOL=
66
67 - PORTAGE_COLOR_GOOD=
68 - PORTAGE_COLOR_WARN=
69 PORTAGE_COLOR_BAD=
70 + PORTAGE_COLOR_BRACKET=
71 + PORTAGE_COLOR_ERR=
72 + PORTAGE_COLOR_GOOD=
73 PORTAGE_COLOR_HILITE=
74 + PORTAGE_COLOR_INFO=
75 + PORTAGE_COLOR_LOG=
76 PORTAGE_COLOR_NORMAL=
77 - PORTAGE_COLOR_BRACKET=
78 + PORTAGE_COLOR_QAWARN=
79 + PORTAGE_COLOR_WARN=
80 }
81
82 __set_colors() {
83 @@ -403,12 +407,16 @@ __set_colors() {
84 if [ -n "${PORTAGE_COLORMAP}" ] ; then
85 eval ${PORTAGE_COLORMAP}
86 else
87 - PORTAGE_COLOR_GOOD=$'\e[32;01m'
88 - PORTAGE_COLOR_WARN=$'\e[33;01m'
89 PORTAGE_COLOR_BAD=$'\e[31;01m'
90 - PORTAGE_COLOR_HILITE=$'\e[36;01m'
91 PORTAGE_COLOR_BRACKET=$'\e[34;01m'
92 + PORTAGE_COLOR_ERR=$'\e[31;01m'
93 + PORTAGE_COLOR_GOOD=$'\e[32;01m'
94 + PORTAGE_COLOR_HILITE=$'\e[36;01m'
95 + PORTAGE_COLOR_INFO=$'\e[32m'
96 + PORTAGE_COLOR_LOG=$'\e[32;01m'
97 PORTAGE_COLOR_NORMAL=$'\e[0m'
98 + PORTAGE_COLOR_QAWARN=$'\e[33m'
99 + PORTAGE_COLOR_WARN=$'\e[33;01m'
100 fi
101 }
102
103 diff --git a/bin/save-ebuild-env.sh b/bin/save-ebuild-env.sh
104 index 8d2ec67ed..98808814b 100644
105 --- a/bin/save-ebuild-env.sh
106 +++ b/bin/save-ebuild-env.sh
107 @@ -102,8 +102,10 @@ __save_ebuild_env() {
108 LAST_E_CMD LAST_E_LEN LD_PRELOAD MISC_FUNCTIONS_ARGS MOPREFIX \
109 NOCOLOR PKGDIR PKGUSE PKG_LOGDIR PKG_TMPDIR \
110 PORTAGE_BASHRC_FILES PORTAGE_BASHRCS_SOURCED \
111 - PORTAGE_COLOR_BAD PORTAGE_COLOR_BRACKET PORTAGE_COLOR_GOOD \
112 - PORTAGE_COLOR_HILITE PORTAGE_COLOR_NORMAL PORTAGE_COLOR_WARN \
113 + PORTAGE_COLOR_BAD PORTAGE_COLOR_BRACKET PORTAGE_COLOR_ERR \
114 + PORTAGE_COLOR_GOOD PORTAGE_COLOR_HILITE PORTAGE_COLOR_INFO \
115 + PORTAGE_COLOR_LOG PORTAGE_COLOR_NORMAL PORTAGE_COLOR_QAWARN \
116 + PORTAGE_COLOR_WARN \
117 PORTAGE_COMPRESS PORTAGE_COMPRESS_EXCLUDE_SUFFIXES \
118 PORTAGE_DOHTML_UNWARNED_SKIPPED_EXTENSIONS \
119 PORTAGE_DOHTML_UNWARNED_SKIPPED_FILES \
120 diff --git a/lib/portage/elog/messages.py b/lib/portage/elog/messages.py
121 index 923e10b69..6a67a45de 100644
122 --- a/lib/portage/elog/messages.py
123 +++ b/lib/portage/elog/messages.py
124 @@ -125,7 +125,7 @@ def _elog_base(level, msg, phase="other", key=None, color=None, out=None):
125 out = sys.stdout
126
127 if color is None:
128 - color = "GOOD"
129 + color = "INFO"
130
131 msg = _unicode_decode(msg, encoding=_encodings["content"], errors="replace")
132
133 @@ -183,11 +183,11 @@ def _reset_buffer():
134
135 # creating and exporting the actual messaging functions
136 _functions = {
137 - "einfo": ("INFO", "GOOD"),
138 - "elog": ("LOG", "GOOD"),
139 + "einfo": ("INFO", "INFO"),
140 + "elog": ("LOG", "LOG"),
141 "ewarn": ("WARN", "WARN"),
142 - "eqawarn": ("QA", "WARN"),
143 - "eerror": ("ERROR", "BAD"),
144 + "eqawarn": ("QA", "QAWARN"),
145 + "eerror": ("ERROR", "ERR"),
146 }
147
148
149 diff --git a/lib/portage/elog/mod_echo.py b/lib/portage/elog/mod_echo.py
150 index fa9203c32..a63939988 100644
151 --- a/lib/portage/elog/mod_echo.py
152 +++ b/lib/portage/elog/mod_echo.py
153 @@ -60,10 +60,10 @@ def _finalize():
154 for msgtype, msgcontent in logentries[phase]:
155 fmap = {
156 "INFO": printer.einfo,
157 + "LOG": printer.elog,
158 "WARN": printer.ewarn,
159 "ERROR": printer.eerror,
160 - "LOG": printer.einfo,
161 - "QA": printer.ewarn,
162 + "QA": printer.eqawarn,
163 }
164 if isinstance(msgcontent, str):
165 msgcontent = [msgcontent]
166 diff --git a/lib/portage/output.py b/lib/portage/output.py
167 index 9d8601b24..42f487f8a 100644
168 --- a/lib/portage/output.py
169 +++ b/lib/portage/output.py
170 @@ -140,12 +140,16 @@ codes["darkyellow"] = codes["0xAAAA00"]
171
172
173 # Colors from /etc/init.d/functions.sh
174 -_styles["NORMAL"] = ("normal",)
175 -_styles["GOOD"] = ("green",)
176 -_styles["WARN"] = ("yellow",)
177 _styles["BAD"] = ("red",)
178 -_styles["HILITE"] = ("teal",)
179 _styles["BRACKET"] = ("blue",)
180 +_styles["ERR"] = ("red",)
181 +_styles["GOOD"] = ("green",)
182 +_styles["HILITE"] = ("teal",)
183 +_styles["INFO"] = ("darkgreen",)
184 +_styles["LOG"] = ("green",)
185 +_styles["NORMAL"] = ("normal",)
186 +_styles["QAWARN"] = ("brown",)
187 +_styles["WARN"] = ("yellow",)
188
189 # Portage functions
190 _styles["INFORM"] = ("darkgreen",)
191 @@ -377,7 +381,18 @@ def style_to_ansi_code(style):
192
193 def colormap():
194 mycolors = []
195 - for c in ("GOOD", "WARN", "BAD", "HILITE", "BRACKET", "NORMAL"):
196 + for c in (
197 + "BAD",
198 + "BRACKET",
199 + "ERR",
200 + "GOOD",
201 + "HILITE",
202 + "INFO",
203 + "LOG",
204 + "NORMAL",
205 + "QAWARN",
206 + "WARN",
207 + ):
208 mycolors.append("PORTAGE_COLOR_{}=$'{}'".format(c, style_to_ansi_code(c)))
209 return "\n".join(mycolors)
210
211 @@ -665,7 +680,7 @@ class EOutput:
212 if not self.quiet:
213 if self.__last_e_cmd == "ebegin":
214 self._write(out, "\n")
215 - self._write(out, colorize("BAD", " * ") + msg + "\n")
216 + self._write(out, colorize("ERR", " * ") + msg + "\n")
217 self.__last_e_cmd = "eerror"
218
219 def einfo(self, msg):
220 @@ -679,7 +694,7 @@ class EOutput:
221 if not self.quiet:
222 if self.__last_e_cmd == "ebegin":
223 self._write(out, "\n")
224 - self._write(out, colorize("GOOD", " * ") + msg + "\n")
225 + self._write(out, colorize("INFO", " * ") + msg + "\n")
226 self.__last_e_cmd = "einfo"
227
228 def einfon(self, msg):
229 @@ -693,9 +708,37 @@ class EOutput:
230 if not self.quiet:
231 if self.__last_e_cmd == "ebegin":
232 self._write(out, "\n")
233 - self._write(out, colorize("GOOD", " * ") + msg)
234 + self._write(out, colorize("INFO", " * ") + msg)
235 self.__last_e_cmd = "einfon"
236
237 + def eqawarn(self, msg):
238 + """
239 + Shows a QA warning.
240 +
241 + @param msg: A very brief (shorter than one line) warning message.
242 + @type msg: StringType
243 + """
244 + out = sys.stderr
245 + if not self.quiet:
246 + if self.__last_e_cmd == "ebegin":
247 + self._write(out, "\n")
248 + self._write(out, colorize("QAWARN", " * ") + msg + "\n")
249 + self.__last_e_cmd = "ewarn"
250 +
251 + def elog(self, msg):
252 + """
253 + Shows a logged informative message terminated with a newline.
254 +
255 + @param msg: A very brief (shorter than one line) informative message.
256 + @type msg: StringType
257 + """
258 + out = sys.stdout
259 + if not self.quiet:
260 + if self.__last_e_cmd == "ebegin":
261 + self._write(out, "\n")
262 + self._write(out, colorize("LOG", " * ") + msg + "\n")
263 + self.__last_e_cmd = "elog"
264 +
265 def ewarn(self, msg):
266 """
267 Shows a warning message.
268 --
269 2.33.0