Bug #253563 - Replace hardcoded green/red color strings with GOOD/BAD. Thanks
authorZac Medico <zmedico@gentoo.org>
Mon, 12 Jan 2009 08:20:03 +0000 (08:20 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 12 Jan 2009 08:20:03 +0000 (08:20 -0000)
to Vsevolod Kozlov <sevakda@gmail.com> for the initial patch. (trunk r12401)

svn path=/main/branches/2.1.6/; revision=12461

pym/portage/__init__.py
pym/portage/data.py
pym/portage/dbapi/__init__.py
pym/portage/dbapi/bintree.py
pym/portage/dbapi/vartree.py
pym/portage/getbinpkg.py

index decedb8228e43d4d4d3d3672a3516be97d131636..db6ce822f72452e5ee01d42154d82e22fa5f5a6c 100644 (file)
@@ -2516,8 +2516,9 @@ class config(object):
 
                                        if x[0]=="+":
                                                # Not legal. People assume too much. Complain.
-                                               writemsg(red("USE flags should not start with a '+': %s\n" % x),
-                                                       noiselevel=-1)
+                                               writemsg(colorize("BAD",
+                                                       "USE flags should not start with a '+': %s" % x) \
+                                                       + "\n", noiselevel=-1)
                                                x=x[1:]
                                                if not x:
                                                        continue
@@ -3413,7 +3414,8 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",
 
        if not os.access(mysettings["DISTDIR"],os.W_OK) and fetch_to_ro:
                if use_locks:
-                       writemsg(red("!!! For fetching to a read-only filesystem, " + \
+                       writemsg(colorize("BAD",
+                               "!!! For fetching to a read-only filesystem, " + \
                                "locking should be turned off.\n"), noiselevel=-1)
                        writemsg("!!! This can be done by adding -distlocks to " + \
                                "FEATURES in /etc/make.conf\n", noiselevel=-1)
@@ -7202,16 +7204,16 @@ def deprecated_profile_check(settings=None):
        deprecatedfile = open(deprecated_profile_file, "r")
        dcontent = deprecatedfile.readlines()
        deprecatedfile.close()
-       writemsg(red("\n!!! Your current profile is deprecated and not supported anymore.\n"),
-               noiselevel=-1)
+       writemsg(colorize("BAD", "\n!!! Your current profile is " + \
+               "deprecated and not supported anymore.") + "\n", noiselevel=-1)
        if not dcontent:
-               writemsg(red("!!! Please refer to the Gentoo Upgrading Guide.\n"),
-                       noiselevel=-1)
+               writemsg(colorize("BAD","!!! Please refer to the " + \
+                       "Gentoo Upgrading Guide.") + "\n", noiselevel=-1)
                return True
        newprofile = dcontent[0]
-       writemsg(red("!!! Please upgrade to the following profile if possible:\n"),
-               noiselevel=-1)
-       writemsg(8*" "+green(newprofile)+"\n", noiselevel=-1)
+       writemsg(colorize("BAD", "!!! Please upgrade to the " + \
+               "following profile if possible:") + "\n", noiselevel=-1)
+       writemsg(8*" " + colorize("GOOD", newprofile) + "\n", noiselevel=-1)
        if len(dcontent) > 1:
                writemsg("To upgrade do the following steps:\n", noiselevel=-1)
                for myline in dcontent[1:]:
@@ -7291,7 +7293,8 @@ def _global_updates(trees, prev_mtimes):
                timestamps = {}
                for mykey, mystat, mycontent in update_data:
                        writemsg_stdout("\n\n")
-                       writemsg_stdout(green("Performing Global Updates: ")+bold(mykey)+"\n")
+                       writemsg_stdout(colorize("GOOD",
+                               "Performing Global Updates: ")+bold(mykey)+"\n")
                        writemsg_stdout("(Could take a couple of minutes if you have a lot of binary packages.)\n")
                        writemsg_stdout("  " + bold(".") + "='update pass'  " + \
                                bold("*") + "='binary update'  " + bold("#") + \
index 5f4d056300e264ba1098bb995173d87fcf5f6e40..a7ebd9cb3452bca4c8c6098106205d38d535cbef 100644 (file)
@@ -5,7 +5,7 @@
 
 import os, sys, pwd, grp, platform
 from portage.util import writemsg
-from portage.output import green,red
+from portage.output import colorize
 from portage.output import create_color_func
 bad = create_color_func("BAD")
 
@@ -28,7 +28,8 @@ if not lchown:
                        lchown = missingos.lchown
                except ImportError:
                        def lchown(*pos_args, **key_args):
-                               writemsg(red("!!!") + " It seems that os.lchown does not" + \
+                               writemsg(colorize("BAD", "!!!") + \
+                                       " It seems that os.lchown does not" + \
                                        " exist.  Please rebuild python.\n", noiselevel=-1)
                        lchown()
 
@@ -78,17 +79,16 @@ try:
 except KeyError:
        portage_uid=0
        portage_gid=0
-       writemsg("\n")
-       writemsg(  red("portage: 'portage' user or group missing. Please update baselayout\n"))
-       writemsg(  red("         and merge portage user(250) and group(250) into your passwd\n"))
-       writemsg(  red("         and group files. Non-root compilation is disabled until then.\n"))
-       writemsg(      "         Also note that non-root/wheel users will need to be added to\n")
-       writemsg(      "         the portage group to do portage commands.\n")
-       writemsg("\n")
-       writemsg(      "         For the defaults, line 1 goes into passwd, and 2 into group.\n")
-       writemsg(green("         portage:x:250:250:portage:/var/tmp/portage:/bin/false\n"))
-       writemsg(green("         portage::250:portage\n"))
-       writemsg("\n")
+       writemsg(colorize("BAD",
+               "portage: 'portage' user or group missing.") + "\n", noiselevel=-1)
+       writemsg(
+               "         For the defaults, line 1 goes into passwd, " + \
+               "and 2 into group.\n", noiselevel=-1)
+       writemsg(colorize("GOOD",
+               "         portage:x:250:250:portage:/var/tmp/portage:/bin/false") \
+               + "\n", noiselevel=-1)
+       writemsg(colorize("GOOD", "         portage::250:portage") + "\n",
+               noiselevel=-1)
        portage_group_warning()
 
 userpriv_groups = [portage_gid]
index 435ffebbb941a2dd9f51a6944842ee33ae535505..cdae94573307c5b3abbe2d0bcbf63504ccb80d8e 100644 (file)
@@ -8,7 +8,7 @@ import os
 import re
 from portage.dep import match_from_list
 from portage.locks import unlockfile
-from portage.output import red
+from portage.output import colorize
 from portage.util import writemsg
 from portage import auxdbkeys, dep_expand
 from portage.versions import catpkgsplit, pkgcmp
@@ -196,7 +196,8 @@ class dbapi(object):
                                pass
                elif '/-MERGING-' in mypath:
                        if os.path.exists(mypath):
-                               writemsg(red("INCOMPLETE MERGE:")+" "+mypath+"\n", noiselevel=-1)
+                               writemsg(colorize("BAD","INCOMPLETE MERGE:")+" %s\n" % mypath,
+                                       noiselevel=-1)
                else:
                        writemsg("!!! Invalid db entry: %s\n" % mypath, noiselevel=-1)
 
index 9b6953b791f4b466747a799bd76bd56b9e1fbbd3..7f2c0cbf08e629e3612a356b7612a817d107495c 100644 (file)
@@ -9,7 +9,7 @@ from portage.dep import isvalidatom, isjustname, dep_getkey, match_from_list
 from portage.dbapi.virtual import fakedbapi
 from portage.exception import InvalidPackageName, \
        PermissionDenied, PortageException
-from portage.output import green, EOutput
+from portage.output import EOutput, colorize
 from portage.util import ensure_dirs, normalize_path, writemsg, writemsg_stdout
 from portage.versions import best, catpkgsplit, catsplit
 from portage.update import update_dbentries
@@ -737,7 +737,7 @@ class binarytree(object):
                                chunk_size = 3000
                        writemsg_stdout("\n")
                        writemsg_stdout(
-                               green("Fetching bininfo from ") + \
+                               colorize("GOOD", "Fetching bininfo from ") + \
                                re.sub(r'//(.+):.+@(.+)/', r'//\1:*password*@\2/', base_url) + "\n")
                        self.remotepkgs = portage.getbinpkg.dir_get_metadata(
                                self.settings["PORTAGE_BINHOST"], chunk_size=chunk_size)
index 4ce11f108e305e76cbb91e8c34dea7d056a59875..f9da7ad0769460766753fc8aaefb53af7b582775 100644 (file)
@@ -17,7 +17,7 @@ from portage.exception import CommandNotFound, \
        InvalidData, InvalidPackageName, \
        FileNotFound, PermissionDenied, UnsupportedAPIException
 from portage.locks import lockdir, unlockdir
-from portage.output import bold, red, green
+from portage.output import bold, colorize
 from portage.update import fixdbentries
 from portage.util import apply_secpass_permissions, ConfigProtect, ensure_dirs, \
        writemsg, writemsg_level, write_atomic, atomic_ofstream, writedict, \
@@ -1816,8 +1816,8 @@ class dblink(object):
                        collisions = []
                        destroot = normalize_path(destroot).rstrip(os.path.sep) + \
                                os.path.sep
-                       showMessage("%s checking %d files for package collisions\n" % \
-                               (green("*"), len(mycontents)))
+                       showMessage(" %s checking %d files for package collisions\n" % \
+                               (colorize("GOOD", "*"), len(mycontents)))
                        for i, f in enumerate(mycontents):
                                if i % 1000 == 0 and i != 0:
                                        showMessage("%d files checked ...\n" % i)
@@ -2427,7 +2427,6 @@ class dblink(object):
                        showMessage(">>> Original instance of package unmerged safely.\n")
 
                if len(others_in_slot) > 1:
-                       from portage.output import colorize
                        showMessage(colorize("WARN", "WARNING:")
                                + " AUTOCLEAN is disabled.  This can cause serious"
                                + " problems due to overlapping packages.\n",
@@ -2543,18 +2542,7 @@ class dblink(object):
                        # myrealdest is mydest without the $ROOT prefix (makes a difference if ROOT!="/")
                        myrealdest = join(sep, offset, x)
                        # stat file once, test using S_* macros many times (faster that way)
-                       try:
-                               mystat = os.lstat(mysrc)
-                       except OSError, e:
-                               writemsg("\n")
-                               writemsg(red("!!! ERROR: There appears to be ")+bold("FILE SYSTEM CORRUPTION.")+red(" A file that is listed\n"))
-                               writemsg(red("!!!        as existing is not capable of being stat'd. If you are using an\n"))
-                               writemsg(red("!!!        experimental kernel, please boot into a stable one, force an fsck,\n"))
-                               writemsg(red("!!!        and ensure your filesystem is in a sane state. ")+bold("'shutdown -Fr now'\n"))
-                               writemsg(red("!!!        File:  ")+str(mysrc)+"\n", noiselevel=-1)
-                               writemsg(red("!!!        Error: ")+str(e)+"\n", noiselevel=-1)
-                               return 1
-
+                       mystat = os.lstat(mysrc)
                        mymode = mystat[stat.ST_MODE]
                        # handy variables; mydest is the target object on the live filesystems;
                        # mysrc is the source object in the temporary install dir
index cd1bd0dc1d7ff9658ee986c39d68c3d41384a4ed..9d59437b40d11465abd68fd5520fb9f3910c06be 100644 (file)
@@ -3,7 +3,7 @@
 # Distributed under the terms of the GNU General Public License v2
 # $Id$
 
-from portage.output import red, yellow, green
+from portage.output import colorize
 from portage.cache.mappings import slot_dict_class
 import portage.xpak
 import HTMLParser
@@ -22,12 +22,12 @@ except ImportError:
 try:
        import ftplib
 except ImportError, e:
-       sys.stderr.write(red("!!! CANNOT IMPORT FTPLIB: ")+str(e)+"\n")
+       sys.stderr.write(colorize("BAD","!!! CANNOT IMPORT FTPLIB: ")+str(e)+"\n")
 
 try:
        import httplib
 except ImportError, e:
-       sys.stderr.write(red("!!! CANNOT IMPORT HTTPLIB: ")+str(e)+"\n")
+       sys.stderr.write(colorize("BAD","!!! CANNOT IMPORT HTTPLIB: ")+str(e)+"\n")
 
 def make_metadata_dict(data):
        myid,myglob = data
@@ -139,7 +139,9 @@ def create_conn(baseurl,conn=None):
                        if password:
                                conn.login(username,password)
                        else:
-                               sys.stderr.write(yellow(" * No password provided for username")+" '"+str(username)+"'\n\n")
+                               sys.stderr.write(colorize("WARN",
+                                       " * No password provided for username")+" '%s'" % \
+                                       (username,) + "\n\n")
                                conn.login(username)
                        conn.set_pasv(passive)
                        conn.set_debuglevel(0)
@@ -231,9 +233,12 @@ def make_http_request(conn, address, params={}, headers={}, dest=None):
                                parts = x.split(": ",1)
                                if parts[0] == "Location":
                                        if (rc == 301):
-                                               sys.stderr.write(red("Location has moved: ")+str(parts[1])+"\n")
+                                               sys.stderr.write(colorize("BAD",
+                                                       "Location has moved: ") + str(parts[1]) + "\n")
                                        if (rc == 302):
-                                               sys.stderr.write(red("Location has temporarily moved: ")+str(parts[1])+"\n")
+                                               sys.stderr.write(colorize("BAD",
+                                                       "Location has temporarily moved: ") + \
+                                                       str(parts[1]) + "\n")
                                        address = parts[1]
                                        break
        
@@ -587,8 +592,9 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache=
                                self.last_update = cur_time
                                self.display()
                def display(self):
-                       self.out.write("\r"+yellow("cache miss: '"+str(self.misses)+"'")+\
-                               " --- "+green("cache hit: '"+str(self.hits)+"'"))
+                       self.out.write("\r"+colorize("WARN",
+                               "cache miss: '"+str(self.misses)+"'") + \
+                               " --- "+colorize("GOOD","cache hit: '"+str(self.hits)+"'"))
                        self.out.flush()
 
        cache_stats = CacheStats(out)
@@ -630,7 +636,8 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache=
                        if myid and myid[0]:
                                metadata[baseurl]["data"][x] = make_metadata_dict(myid)
                        elif verbose:
-                               sys.stderr.write(red("!!! Failed to retrieve metadata on: ")+str(x)+"\n")
+                               sys.stderr.write(colorize("BAD",
+                                       "!!! Failed to retrieve metadata on: ")+str(x)+"\n")
                                sys.stderr.flush()
                else:
                        cache_stats.hits += 1