Merged from trunk 4905:4912 a colourful set of patches
authorFabian Groffen <grobian@gentoo.org>
Thu, 2 Nov 2006 18:38:24 +0000 (18:38 -0000)
committerFabian Groffen <grobian@gentoo.org>
Thu, 2 Nov 2006 18:38:24 +0000 (18:38 -0000)
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
man/emerge.1
man/make.conf.5
pym/emergehelp.py
pym/output.py

index fda949f5384811fc7d9b279c1dc6a088be6090fb..405b22ea0b97c2a220d326856b620079c39ab70c 100755 (executable)
@@ -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
index a06c0bebc5b91694bd123533a997060119987fed..f2bb05cc4a4b444295e96add3e5e7db3af6681e9 100644 (file)
@@ -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
index eb04a85332a6a95a6f937bc26aaa411b9b83a336..d8c0732d29444470edbbc106c2c9b37f2a606542 100644 (file)
@@ -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/
index c6c0e465de6a7f17b61ab13c5f12a716616c2dfc..e9949dd2ae983111602bab9e328ac76360ac7ff0 100644 (file)
@@ -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"
index 55082a5fcce4852e1ff82228f3eebb001731c1e8..2904d974c69827e64cb3a67e0e78b0bb7dd48f56 100644 (file)
@@ -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",