Attached is the initial framework to make portage stfu.

pym/portage_util.py - (wrappers the writemsg function)
 By default writemsg() has noiselevel handling, but it sends 
 everything to stderr. We wrapper it in order to pass 
 an additional file descriptor so we can use stdout vs stderr.

pym/portage.py - (use writemsg_stdout function)
 To take advantage of the newy created writemsg_stdout() function
 we swap it in place of alot of the default print "foo" statements 
 that are in portage's merge/unmerging phases.
 Shifts env var PORTAGE_QUIET to doebuild where it can 
 be used by ebuild.sh.

bin/emerge - (-q/--quiet trigger)
 Sets noiselimit to -1
 and uses writemsg_stdout in a few places.

bin/ebuild.sh - (ulgy not attached)
bin/prepstrip - (ulgy not attached)

-- 
solar <[EMAIL PROTECTED]>
Gentoo Linux
--- pym/portage_util.py	(revision 2485)
+++ pym/portage_util.py	(working copy)
@@ -6,13 +6,20 @@
 import sys,string,shlex,os.path
 
 noiselimit = 0
-def writemsg(mystr,noiselevel=0):
+
+def writemsg(mystr,noiselevel=0,fd=None):
 	"""Prints out warning and debug messages based on the noiselimit setting"""
 	global noiselimit
+	if fd is None:
+		fd = sys.stderr
 	if noiselevel <= noiselimit:
-		sys.stderr.write(mystr)
-		sys.stderr.flush()
+		fd.write(mystr)
+		fd.flush()
 
+def writemsg_stdout(mystr,noiselevel=0):
+	"""Prints messages stdout based on the noiselimit setting"""
+	writemsg(mystr, noiselevel=noiselevel, fd=sys.stdout)
+
 def grabfile(myfilename, compat_level=0, recursive=0):
 	"""This function grabs the lines in a file, normalizes whitespace and returns lines in a list; if a line
 	begins with a #, it is ignored, as are empty lines"""
Index: pym/portage.py
===================================================================
--- pym/portage.py	(revision 2485)
+++ pym/portage.py	(working copy)
@@ -90,7 +90,7 @@
 	import portage_util
 	from portage_util import grab_multiple, grabdict, grabdict_package, grabfile, grabfile_package, \
 		grabints, map_dictlist_vals, pickle_read, pickle_write, stack_dictlist, stack_dicts, stack_lists, \
-		unique_array, varexpand, writedict, writeints, writemsg, getconfig, dump_traceback
+		unique_array, varexpand, writedict, writeints, writemsg, getconfig, dump_traceback, writemsg_stdout
 	import portage_exception
 	import portage_gpg
 	import portage_locks
@@ -2293,7 +2293,7 @@
 			print
 			return 0
 		else:
-			print ">>> checksums "+note+" ;-)",x
+			writemsg_stdout(">>> checksums "+note+" ;-) %s\n" % x)
 	return 1
 
 
@@ -2493,6 +2493,9 @@
 	mysettings["PV"] = mysplit[1]
 	mysettings["PR"] = mysplit[2]
 
+	if portage_util.noiselimit < 0:
+		mysettings["PORTAGE_QUIET"] = "1"
+
 	if mydo != "depend":
 		try:
 			mysettings["INHERITED"], mysettings["RESTRICT"] = db[root][tree].dbapi.aux_get( \
@@ -5704,7 +5707,7 @@
 						#we skip this if we're dealing with a symlink
 						#because os.path.exists() will operate on the
 						#link target rather than the link itself.
-						print "--- !found "+str(pkgfiles[obj][0]), obj
+						writemsg_stdout("--- !found "+str(pkgfiles[obj][0])+ " %s\n" % obj)
 						continue
 				# next line includes a tweak to protect modules from being unmerged,
 				# but we don't protect modules from being overwritten if they are
@@ -5712,56 +5715,56 @@
 				# functionality for /lib/modules. For portage-ng both capabilities
 				# should be able to be independently specified.
 				if self.isprotected(obj) or ((len(obj) > len(modprotect)) and (obj[0:len(modprotect)]==modprotect)):
-					print "--- cfgpro "+str(pkgfiles[obj][0]), obj
+					writemsg_stdout("--- cfgpro %s %s\n" % (pkgfiles[obj][0], obj))
 					continue
 
 				lstatobj=os.lstat(obj)
 				lmtime=str(lstatobj[stat.ST_MTIME])
 				if (pkgfiles[obj][0] not in ("dir","fif","dev")) and (lmtime != pkgfiles[obj][1]):
-					print "--- !mtime", pkgfiles[obj][0], obj
+					writemsg_stdout("--- !mtime %s %s\n" % (pkgfiles[obj][0], obj))
 					continue
 
 				if pkgfiles[obj][0]=="dir":
 					if not os.path.isdir(obj):
-						print "--- !dir  ","dir", obj
+						writemsg_stdout("--- !dir  %s %s\n" % ("dir", obj))
 						continue
 					mydirs.append(obj)
 				elif pkgfiles[obj][0]=="sym":
 					if not os.path.islink(obj):
-						print "--- !sym  ","sym", obj
+						writemsg_stdout("--- !sym  %s %s\n" % ("sym", obj))
 						continue
 					try:
 						os.unlink(obj)
-						print "<<<       ","sym",obj
+						writemsg_stdout("<<<       %s %s\n" % ("sym",obj))
 					except (OSError,IOError),e:
-						print "!!!       ","sym",obj
+						writemsg_stdout("!!!       %s %s\n" % ("sym",obj))
 				elif pkgfiles[obj][0]=="obj":
 					if not os.path.isfile(obj):
-						print "--- !obj  ","obj", obj
+						writemsg_stdout("--- !obj  %s %s\n" % ("obj", obj))
 						continue
 					mymd5=portage_checksum.perform_md5(obj, calc_prelink=1)
 
 					# string.lower is needed because db entries used to be in upper-case.  The
 					# string.lower allows for backwards compatibility.
 					if mymd5 != string.lower(pkgfiles[obj][2]):
-						print "--- !md5  ","obj", obj
+						writemsg_stdout("--- !md5  %s %s\n" % ("obj", obj))
 						continue
 					try:
 						os.unlink(obj)
 					except (OSError,IOError),e:
 						pass
-					print "<<<       ","obj",obj
+					writemsg_stdout("<<<       %s %s\n" % ("obj",obj))
 				elif pkgfiles[obj][0]=="fif":
 					if not stat.S_ISFIFO(lstatobj[stat.ST_MODE]):
-						print "--- !fif  ","fif", obj
+						writemsg_stdout("--- !fif  %s %s\n" % ("fif", obj))
 						continue
 					try:
 						os.unlink(obj)
 					except (OSError,IOError),e:
 						pass
-					print "<<<       ","fif",obj
+					writemsg_stdout("<<<       %s %s\n" % ("fif",obj))
 				elif pkgfiles[obj][0]=="dev":
-					print "---       ","dev",obj
+					writemsg_stdout("---       %s %s\n" % ("dev",obj))
 
 			mydirs.sort()
 			mydirs.reverse()
@@ -5771,14 +5774,14 @@
 				if not last_non_empty.startswith(obj) and not listdir(obj):
 					try:
 						os.rmdir(obj)
-						print "<<<       ","dir",obj
+						writemsg_stdout("<<<       %s %s\n" % ("dir",obj))
 						last_non_empty = ""
 						continue
 					except (OSError,IOError),e:
 						#immutable?
 						pass
 
-				print "--- !empty dir", obj
+				writemsg_stdout("--- !empty dir %s\n" % obj)
 				last_non_empty = obj
 				continue
 
@@ -5942,7 +5945,7 @@
 		if not os.path.exists(self.dbtmpdir):
 			os.makedirs(self.dbtmpdir)
 
-		print ">>> Merging",self.mycpv,"to",destroot
+		writemsg_stdout(">>> Merging %s %s %s\n" % (self.mycpv,"to",destroot))
 
 		# run preinst script
 		if myebuild:
@@ -6025,11 +6028,11 @@
 		outfile.close()
 
 		if (oldcontents):
-			print ">>> Safely unmerging already-installed instance..."
+			writemsg_stdout(">>> Safely unmerging already-installed instance...\n")
 			self.dbdir = self.dbpkgdir
 			self.unmerge(oldcontents,trimworld=0)
 			self.dbdir = self.dbtmpdir
-			print ">>> original instance of package unmerged safely."
+			writemsg_stdout(">>> original instance of package unmerged safely.\n")
 
 		# We hold both directory locks.
 		self.dbdir = self.dbpkgdir
@@ -6085,7 +6088,7 @@
 		global dircache
 		if dircache.has_key(self.dbcatdir):
 			del dircache[self.dbcatdir]
-		print ">>>",self.mycpv,"merged."
+		writemsg_stdout(">>> %s %s\n" % (self.mycpv,"merged."))
 
 		# Process ebuild logfiles
 		elog_process(self.mycpv, self.settings)
@@ -6219,7 +6222,7 @@
 
 					if stat.S_ISLNK(mydmode) or stat.S_ISDIR(mydmode):
 						# a symlink to an existing directory will work for us; keep it:
-						print "---",mydest+"/"
+						writemsg_stdout("--- %s\n" % mydest+"/")
 						if bsd_chflags:
 							bsd_chflags.lchflags(mydest, dflags)
 					else:
@@ -6237,7 +6240,7 @@
 							bsd_chflags.lchflags(mydest, dflags)
 						os.chmod(mydest,mystat[0])
 						os.chown(mydest,mystat[4],mystat[5])
-						print ">>>",mydest+"/"
+						writemsg_stdout(">>> %s\n" % mydest+"/")
 				else:
 					#destination doesn't exist
 					if selinux_enabled:
@@ -6249,7 +6252,7 @@
 					if bsd_chflags:
 						bsd_chflags.lchflags(mydest, bsd_chflags.lgetflags(mysrc))
 					os.chown(mydest,mystat[4],mystat[5])
-					print ">>>",mydest+"/"
+					writemsg_stdout(">>> %s\n" % mydest+"/")
 				outfile.write("dir "+myrealdest+"\n")
 				# recurse and merge this directory
 				if self.mergeme(srcroot,destroot,outfile,secondhand,offset+x+"/",cfgfiledict,thismtime):
@@ -6266,7 +6269,7 @@
 					if stat.S_ISDIR(mydmode):
 						# install of destination is blocked by an existing directory with the same name
 						moveme=0
-						print "!!!",mydest
+						writemsg_stdout("!!! %s\n" % mydest)
 					elif stat.S_ISREG(mydmode) or (stat.S_ISLNK(mydmode) and os.path.exists(mydest) and stat.S_ISREG(os.stat(mydest)[stat.ST_MODE])):
 						cfgprot=0
 						# install of destination is blocked by an existing regular file,
@@ -6370,7 +6373,7 @@
 				if mymtime!=None:
 					zing=">>>"
 					outfile.write("obj "+myrealdest+" "+mymd5+" "+str(mymtime)+"\n")
-				print zing,mydest
+				writemsg_stdout("%s %s\n" % (zing,mydest))
 			else:
 				# we are merging a fifo or device node
 				zing="!!!"
@@ -6384,7 +6387,7 @@
 							outfile.write("fif "+myrealdest+"\n")
 					else:
 						sys.exit(1)
-				print zing+" "+mydest
+				writemsg_stdout(zing+" "+mydest+"\n")
 
 	def merge(self,mergeroot,inforoot,myroot,myebuild=None,cleanup=0):
 		return self.treewalk(mergeroot,myroot,inforoot,myebuild,cleanup=cleanup)
@@ -6466,7 +6469,7 @@
 		shutil.rmtree(tmploc+"/"+mypkg,1)
 	os.makedirs(pkgloc)
 	os.makedirs(infloc)
-	print ">>> extracting info"
+	writemsg_stdout(">>> extracting info\n")
 	xptbz2.unpackinfo(infloc)
 	# run pkg_setup early, so we can bail out early
 	# (before extracting binaries) if there's a problem
@@ -6475,7 +6478,7 @@
 
 	mysettings.configdict["pkg"]["CATEGORY"] = mycat;
 	a=doebuild(myebuild,"setup",myroot,mysettings,tree="bintree")
-	print ">>> extracting",mypkg
+	writemsg_stdout(">>> extracting %s\n" % mypkg)
 	notok=spawn("bzip2 -dqc -- '"+mytbz2+"' | tar xpf -",mysettings,free=1)
 	if notok:
 		print "!!! Error extracting",mytbz2
Index: bin/prepstrip
===================================================================
--- bin/emerge  (revision 2483)
+++ bin/emerge  (working copy)
@@ -326,7 +326,7 @@
 
 if ("--quiet" in myopts):
        update_spinner = update_quiet_spinner
-       os.environ["PORTAGE_QUIET"] = "1"
+       portage_util.noiselimit = -1
 
 # Always create packages if FEATURES=buildpkg
 # Imply --buildpkg if --buildpkgonly
@@ -2318,11 +2318,11 @@
                                        numselected=numselected+1
                                #ok, now the last-merged package is protected, 
and the rest are selected
        if global_unmerge and not numselected:
-               print "\n>>> No outdated packages were found on your system.\n"
+               portage_util.writemsg_stdout("\n>>> No outdated packages were 
found on your system.\n")
                return 0
 
        if not numselected:
-               print "\n>>>",unmerge_action+": No packages selected for 
removal.\n"
+               portage_util.writemsg_stdout("\n>>> %s\n" % unmerge_action+": 
No packages selected for removal.\n")
                return 0
 
        for x in pkgmap.keys():
@@ -3348,6 +3348,6 @@
                if portage.mtimedb.has_key("resume"):
                        del portage.mtimedb["resume"]
                if portage.settings["AUTOCLEAN"] and 
"yes"==portage.settings["AUTOCLEAN"]:
-                       print ">>> Auto-cleaning packages ..."
+                       portage_util.writemsg_stdout(">>> Auto-cleaning 
packages ...\n")
                        unmerge("clean", ["world"])
        post_emerge()
Index: bin/ebuild.sh
===================================================================

Reply via email to