From 97c79670dd5fec4ccc6302dade0f9e2cc47c2394 Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Thu, 2 Nov 2006 18:38:24 +0000 Subject: [PATCH] Merged from trunk 4905:4912 a colourful set of patches Implement --color < y | n > for bug #42115 and deprecate --nocolor. When --color is not specified, rely on the old NOCOLOR variable and/or stdout auto-detection. Document the new --color < y | n > option for bug #42115. Add --color < y | n > help output for bug #42115. Remove broken nocolor() call, since thats handled internally by the output module anyway. Fix the USE_ORDER docs for bug #153764. Thanks to Alec Warner for the initial patch. svn path=/main/branches/prefix/; revision=4914 --- bin/emerge | 37 ++++++++++++++++++++++++++++--------- man/emerge.1 | 8 +++++--- man/make.conf.5 | 29 ++++++++++++++++++++++------- pym/emergehelp.py | 14 ++++++++------ pym/output.py | 9 ++++++--- 5 files changed, 69 insertions(+), 28 deletions(-) diff --git a/bin/emerge b/bin/emerge index fda949f53..405b22ea0 100755 --- a/bin/emerge +++ b/bin/emerge @@ -32,6 +32,7 @@ del os.environ["PORTAGE_LEGACY_GLOBALS"] from portage import digraph import emergehelp, xpak, commands, errno, re, socket, string, time, types +import output from output import blue, bold, colorize, darkblue, darkgreen, darkred, green, \ havecolor, nc_len, nocolor, red, teal, turquoise, white, xtermTitle, \ xtermTitleReset, yellow @@ -4069,6 +4070,11 @@ def parse_opts(tmpcmdline): longopt_aliases = {"--cols":"--columns", "--skip-first":"--skipfirst"} argument_options = { + "--color": { + "help":"enable or disable color output", + "type":"choice", + "choices":("y", "n") + }, "--with-bdeps": { "help":"include unnecessary build time dependencies", "type":"choice", @@ -4129,6 +4135,11 @@ def parse_opts(tmpcmdline): else: myfiles.append(x) + if "--nocolor" in myopts: + print "*** Deprecated use of '--nocolor', use '--color=n' instead." + del myopts["--nocolor"] + myopts["--color"] = "n" + return myaction, myopts, myfiles def validate_ebuild_environment(trees): @@ -4228,8 +4239,18 @@ def adjust_config(myopts, settings): settings["PORTAGE_DEBUG"] = str(PORTAGE_DEBUG) settings.backup_changes("PORTAGE_DEBUG") - # Set color output - if "--nocolor" in myopts: + """The explicit --color < y | n > option overrides the NOCOLOR environment + variable and stdout auto-detection.""" + if "--color" in myopts: + if "y" == myopts["--color"]: + output.havecolor = 1 + settings["NOCOLOR"] = "false" + else: + output.havecolor = 0 + settings["NOCOLOR"] = "true" + settings.backup_changes("NOCOLOR") + elif not sys.stdout.isatty(): + output.havecolor = 0 settings["NOCOLOR"] = "true" settings.backup_changes("NOCOLOR") @@ -4247,6 +4268,9 @@ def emerge_main(): ldpath_mtimes = mtimedb["ldpath"] xterm_titles = "notitles" not in settings.features + """Disable color as early as possible via NOCOLOR and stdout + auto-detection. This initial setting may later be overridden via the + --color < yes | no > option.""" if settings.get("NOCOLOR","").lower() in ("yes","true"): nocolor() elif (not sys.stdout.isatty()) and \ @@ -4386,11 +4410,6 @@ def emerge_main(): print "* --tree is currently broken with --resume. Disabling..." del myopts["--tree"] - # Set color output - if "--nocolor" in myopts or \ - settings["NOCOLOR"] in ("yes","true"): - nocolor() - if not ("--quiet" in myopts): if not sys.stdout.isatty() or ("--nospinner" in myopts): spinner.update = spinner.update_basic @@ -4401,7 +4420,7 @@ def emerge_main(): trees[settings["ROOT"]]["vartree"].dbapi) sys.exit(0) elif "--help" in myopts: - emergehelp.help(myaction, myopts, havecolor) + emergehelp.help(myaction, myopts, output.havecolor) sys.exit(0) if portage.wheelgid == portage.portage_gid and portage.wheelgid < 500: @@ -4413,7 +4432,7 @@ def emerge_main(): print "myopts", myopts if not myaction and not myfiles and "--resume" not in myopts: - emergehelp.help(myaction, myopts, havecolor) + emergehelp.help(myaction, myopts, output.havecolor) sys.exit(1) # check if root user is the current user for the actions where emerge needs this diff --git a/man/emerge.1 b/man/emerge.1 index a06c0bebc..f2bb05cc4 100644 --- a/man/emerge.1 +++ b/man/emerge.1 @@ -225,6 +225,11 @@ dependencies must already be emerged on the system. Use this in conjunction with the \fB\-\-pretend\fR option. This will show the ChangeLog entries for all the packages that will be upgraded. .TP +.BR "\-\-color < y | n >" +Enable or disable color output. This option will override \fINOCOLOR\fR +(see \fBmake.conf\fR(5)) and may also be used to force color output when stdout +is not a tty (by default, color is disabled unless stdout is a tty). +.TP .BR "\-\-columns" Used alongside \fB\-\-pretend\fR to cause the package name, new version, and old version to be displayed in an aligned format for easy cut\-n\-paste. @@ -280,9 +285,6 @@ Tells emerge to include installed packages where USE flags have changed since compilation. An asterisk marks when a USE flag has changed since the package was compiled. .TP -.BR "\-\-nocolor " -Suppresses all coloring of portage's output. -.TP .BR "\-\-noconfmem" Causes portage to disregard merge records indicating that a config file inside of a \fBCONFIG_PROTECT\fR directory has been merged already. Portage diff --git a/man/make.conf.5 b/man/make.conf.5 index eb04a8533..d8c0732d2 100644 --- a/man/make.conf.5 +++ b/man/make.conf.5 @@ -408,19 +408,34 @@ can be found in \fI/usr/portage/profiles/use.desc\fR. Names of \fBUSE_EXPAND\fR variables that should not be shown in the verbose merge list output of the \fBemerge\fR(1) command. .TP -\fBUSE_ORDER\fR = \fI"env:pkg:conf:auto:defaults"\fR -Determines precedence for incrementing the setting of the USE variable. -The above setting will cause the environment (env) to override per package (pkg) -settings to override make.conf (conf) to override auto generated values -from merged packages (auto) to override make.defaults (defaults). -.br +\fBUSE_ORDER\fR = \fI"env:pkg:conf:defaults:pkginternal"\fR +Determines the precedence of layers in the incremental stacking of the USE +variable. Precedence decreases from left to right such that env overrides +pkg, pkg overrides conf, and so forth. + \fB***warning***\fR .br Do not modify this value unless you're a developer and you know what you're doing. If you change this and something breaks, we will not help you fix it. .br -Defaults to "env:pkg:conf:defaults". +.RS +.TP +.B env +USE from the current USE environment variable if it exists +.TP +.B pkg +Per-package USE from \fB/etc/portage/package.use\fR (see \fBportage\fR(5)) +.TP +.B conf +USE from make.conf +.TP +.B defaults +USE from make.defaults and package.use in the profile (see \fBportage\fR(5)) +.TP +.B pkginternal +USE from ebuild IUSE defaults (flags enabled via a + prefix; see \fBebuild\fR(5)) +.RE .SH "REPORTING BUGS" Please report bugs via http://bugs.gentoo.org/ diff --git a/pym/emergehelp.py b/pym/emergehelp.py index c6c0e465d..e9949dd2a 100644 --- a/pym/emergehelp.py +++ b/pym/emergehelp.py @@ -16,14 +16,13 @@ def shorthelp(): print " "+turquoise("emerge")+" "+turquoise("--resume")+" [ "+green("--pretend")+" | "+green("--ask")+" | "+green("--skipfirst")+" ]" print " "+turquoise("emerge")+" "+turquoise("--help")+" [ "+green("system")+" | "+green("world")+" | "+green("config")+" | "+green("--sync")+" ] " print bold("Options:")+" "+green("-")+"["+green("abBcCdDefgGhikKlnNoOpqPsStuvV")+"] ["+green("--oneshot")+"] ["+green("--newuse")+"] ["+green("--noconfmem")+"]" - print " ["+green("--columns")+"] ["+green("--nocolor")+"] ["+green("--nospinner")+"]" + print " [ " + green("--color")+" < " + turquoise("y") + " | "+ turquoise("n")+" > ] [ "+green("--columns")+" ]" + print " ["+green("--nospinner")+"]" print " [ "+green("--deep")+" ] [" + green("--with-bdeps")+" < " + turquoise("y") + " | "+ turquoise("n")+" > ]" print bold("Actions:")+" [ "+green("--clean")+" | "+green("--depclean")+" | "+green("--prune")+" | "+green("--regen")+" | "+green("--search")+" | "+green("--unmerge")+" ]" print def help(myaction,myopts,havecolor=1): - if not havecolor: - nocolor() if not myaction and ("--help" not in myopts): shorthelp() print @@ -186,6 +185,12 @@ def help(myaction,myopts,havecolor=1): print " When pretending, also display the ChangeLog entries for packages" print " that will be upgraded." print + print " "+green("--color") + " < " + turquoise("y") + " | "+ turquoise("n")+" >" + print " Enable or disable color output. This option will override NOCOLOR" + print " (see make.conf(5)) and may also be used to force color output when" + print " stdout is not a tty (by default, color is disabled unless stdout" + print " is a tty)." + print print " "+green("--columns") print " Display the pretend output in a tabular form. Versions are" print " aligned vertically." @@ -237,9 +242,6 @@ def help(myaction,myopts,havecolor=1): print " Tells emerge to include installed packages where USE flags have " print " changed since installation." print - print " "+green("--nocolor") - print " Suppresses color in the output." - print print " "+green("--noconfmem") print " Portage keeps track of files that have been placed into" print " CONFIG_PROTECT directories, and normally it will not merge the" diff --git a/pym/output.py b/pym/output.py index 55082a5fc..2904d974c 100644 --- a/pym/output.py +++ b/pym/output.py @@ -210,15 +210,18 @@ def notitles(): def nocolor(): "turn off colorization" + global havecolor havecolor=0 - for x in codes.keys(): - codes[x]="" def resetColor(): return codes["reset"] def colorize(color_key, text): - return codes[color_key] + text + codes["reset"] + global havecolor + if havecolor: + return codes[color_key] + text + codes["reset"] + else: + return text compat_functions_colors = ["bold","white","teal","turquoise","darkteal", "fuscia","fuchsia","purple","blue","darkblue","green","darkgreen","yellow", -- 2.26.2