Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 114985 - emerge --pretend output is not suitable as a list of packages
Summary: emerge --pretend output is not suitable as a list of packages
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core - Interface (emerge) (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-09 07:01 UTC by Ramana Kumar
Modified: 2006-06-03 13:08 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
patch to emerge sorry, didn't know to diff -u. done now. (emerge.patch,2.28 KB, patch)
2005-12-09 07:02 UTC, Ramana Kumar
Details | Diff
patch to emergehelp.py (emergehelp.py.patch,271 bytes, patch)
2005-12-09 07:03 UTC, Ramana Kumar
Details | Diff
emerge patch (emerge.patch,5.25 KB, patch)
2005-12-09 07:28 UTC, Ramana Kumar
Details | Diff
emergehelp.py patch (emergehelp.py.patch,801 bytes, patch)
2005-12-09 07:29 UTC, Ramana Kumar
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ramana Kumar 2005-12-09 07:01:00 UTC
Sometimes users would like to use the output of emerge --pretend somepackage as
a list of packages to later feed back to emerge. For example emerge -p package >
list.txt && do some stuff to list.txt && emerge `cat list.txt`. Although this is
possible with some manual string parsing (e.g. using sed or cut) for less
experienced users it would be nice if emerge did it by itself. Therefore I have
attached a patch to emerge (and to emergehelp.py) which adds a --namesonly (-y
short option) option to emerge to accomplish this task. It is my first ever
patch to anything Gentoo (or anything at all) so there may be some problems, but
it seems to work on my machine - hope it comes to some use =)

Reproducible: Always
Steps to Reproduce:
1.
2.
3.
Comment 1 Ramana Kumar 2005-12-09 07:02:19 UTC
Created attachment 74378 [details, diff]
patch to emerge
sorry, didn't know to diff -u. done now.

patch for my emerge.
emerge --version:
Portage 2.0.53 (default-linux/amd64/2005.0, gcc-3.4.4, glibc-2.3.5-r3,
2.6.14-gentoo-r4 x86_64)
Comment 2 Ramana Kumar 2005-12-09 07:03:12 UTC
Created attachment 74379 [details, diff]
patch to emergehelp.py

patch to my /usr/lib/portage/pym/emergehelp.py
(Portage 2.0.53 (default-linux/amd64/2005.0, gcc-3.4.4, glibc-2.3.5-r3,
2.6.14-gentoo-r4 x86_64))
Comment 3 SpanKY gentoo-dev 2005-12-09 07:18:54 UTC
that's the point of --columns

$ emerge openssh --columns -p
[ebuild   R   ] net-misc/openssh                                       [4.2_p1]

considering how trivial it is to then extract just the package name,
this patch is just fluff
Comment 4 SpanKY gentoo-dev 2005-12-09 07:19:22 UTC
Comment on attachment 74378 [details, diff]
patch to emerge
sorry, didn't know to diff -u. done now.

this patch is unreadable

always use `diff -u`
Comment 5 Ramana Kumar 2005-12-09 07:25:12 UTC
(In reply to comment #3)
> that's the point of --columns
> 
> $ emerge openssh --columns -p
> [ebuild   R   ] net-misc/openssh                                       [4.2_p1]
> 
> considering how trivial it is to then extract just the package name,
> this patch is just fluff

it's not easy to copy package names from --columns output in a xterm... unless
i'm missing something? and what if you wanted to include the output in a script
so you didn't have to do any manual copying?
Comment 6 Ramana Kumar 2005-12-09 07:26:57 UTC
Comment on attachment 74378 [details, diff]
patch to emerge
sorry, didn't know to diff -u. done now.

--- /usr/bin/emerge.bak 2005-12-02 11:51:36.000000000 +1100
+++ /usr/bin/emerge	2005-12-10 01:58:15.000000000 +1100
@@ -37,6 +37,8 @@
		 "Inaccuracy saves a world of explanation.",
		]

+def update_no_spinner():
+	return

 def update_basic_spinner():
	global spinner, spinpos
@@ -72,7 +74,6 @@
 if not sys.stdout.isatty() or ("--nospinner" in sys.argv):
	update_spinner = update_basic_spinner

-
 if (not sys.stdout.isatty()) or (portage.settings["NOCOLOR"] in
["yes","true"]):
	nocolor()

@@ -176,6 +177,7 @@
 "--fetchonly",    "--fetch-all-uri",
 "--getbinpkg",    "--getbinpkgonly",
 "--help",	   "--noconfmem",
+"--namesonly",
 "--newuse",	   "--nocolor",
 "--nodeps",	   "--noreplace",
 "--nospinner",    "--oneshot",
@@ -209,7 +211,8 @@
 "s":"--search",    "S":"--searchdesc",
 't':"--tree",
 "u":"--update",    "U":"--upgradeonly",
-"v":"--verbose",   "V":"--version"
+"v":"--verbose",   "V":"--version",
+"y":"--namesonly"
 }

 myaction=None
@@ -287,8 +290,10 @@
	else:
		myfiles.append(x)

+if ("--namesonly" in myopts):
+	update_spinner = update_no_spinner

-if "moo" in myfiles:
+if "moo" in myfiles and "--namesonly" not in myopts:
	print """

   Gentoo (""" + os.uname()[0] + """)
@@ -329,6 +334,14 @@
	print ">>> --tree implies --pretend... adding --pretend to options."
	myopts.append("--pretend")

+# --namesonly only makes sense with --pretend
+if "--namesonly" in myopts and not (("--pretend" in myopts) or ("--ask" in
myopts)):
+	myopts.append("--pretend")
+
+# Allow --namesonly to use --quiet
+if "--namesonly" in myopts and not ("--quiet" in myopts):
+	myopts.append("--quiet")
+
 # Also allow -S to invoke search action (-sS)
 if ("--searchdesc" in myopts):
	if myaction and myaction != "search":
@@ -379,6 +392,14 @@
	print ">>> --pretend disables --ask... removing --ask from options."
	myopts.remove("--ask")

+# Allow --namesonly to remove --verbose
+if ("--namesonly" in myopts) and ("--verbose" in myopts):
+	myopts.remove("--verbose")
+
+# Allow --namesonly to remove --columns
+if ("--namesonly" in myopts) and ("--columns" in myopts):
+	myopts.remove("--columns")
+	
 # forbid --ask when not in a terminal
 # note: this breaks `emerge --ask | tee logfile`, but that doesn't work
anyway.
 if ("--ask" in myopts) and (not sys.stdin.isatty()):
@@ -1652,6 +1673,8 @@
							myprint=myprint+"
"*(oldlp-nc_len(myprint))
						myprint=myprint+myoldbest
						myprint=myprint+darkgreen("  to
"+x[1])+" "+verboseadd
+					elif "--namesonly" in myopts:
+						myprint="="+darkgreen(x[2])
					else:
						myprint="["+x[0]+" "+addl+"]
"+darkgreen(x[2])+" "+myoldbest+" "+darkgreen("to "+x[1])+" "+verboseadd
				else:
@@ -1663,6 +1686,8 @@
						if (oldlp-nc_len(myprint)) > 0:
							myprint=myprint+("
"*(oldlp-nc_len(myprint)))
						myprint=myprint+myoldbest+" 
"+verboseadd
+					elif "--namesonly" in myopts:
+						myprint="="+darkgreen(x[2])
					else:
						if x[3]=="nomerge":
						       
myprint=darkblue("[nomerge	] "+indent+x[2]+" "+myoldbest+" ")+verboseadd
@@ -1670,7 +1695,7 @@
							myprint="["+x[0]+"
"+addl+"] "+indent+darkgreen(x[2])+" "+myoldbest+" "+verboseadd
				p.append(myprint)

-			if ("--tree" not in myopts):
+			if ("--tree" not in myopts and "--namesonly" not in
myopts):
				mysplit=portage.pkgsplit(x[2])

				# XXX mysplit _can_ be None.... Why?
@@ -2122,7 +2147,7 @@
				print "="+string.join(sp_absx[sp_vdb_len:],"/")
			       
candidate_catpkgs.append("="+string.join(sp_absx[sp_vdb_len:],"/"))

-	if ("--pretend" in myopts) or ("--ask" in myopts):
+	if (("--pretend" in myopts) and ("--namesonly" not in myopts)) or
("--ask" in myopts):
		print darkgreen("\n>>> These are the packages that I would
unmerge:")

	pkgmap={}
@@ -3089,7 +3114,7 @@
 else:
	favorites=[]
	syslist=getlist("system")
-	if (("--pretend" in myopts) and not ("--fetchonly" in myopts or
"--fetch-all-uri" in myopts)) or ("--ask" in myopts):
+	if (("--pretend" in myopts) and not ("--fetchonly" in myopts or
"--fetch-all-uri" in myopts) and not ("--namesonly" in myopts)) or ("--ask" in
myopts):
		if "--tree" in myopts:
			print
			print darkgreen("These are the packages that I would
merge, in reverse order:")
@@ -3122,24 +3147,28 @@

		mydepgraph=depgraph(myaction,myopts)
		if myaction in ["system","world"]:
-			print "Calculating",myaction,"dependencies  ",
-			sys.stdout.flush()
+			if ("--namesonly" not in myopts):
+				print "Calculating",myaction,"dependencies  ",
+				sys.stdout.flush()
			if not mydepgraph.xcreate(myaction):
				print "!!! Depgraph creation failed."
				sys.exit(1)
-			print "\b\b ...done!"
+			if ("--namesonly" not in myopts):
+				print "\b\b ...done!"
		else:
			if not myfiles:
				print "emerge: please tell me what to do."
				help()
				sys.exit(1)
				#we don't have any files to process; skip this
step and exit
-			print "Calculating dependencies  ",
-			sys.stdout.flush()
+			if ("--namesonly" not in myopts):
+				print "Calculating dependencies  ",
+				sys.stdout.flush()
			retval,favorites=mydepgraph.select_files(myfiles)
			if not retval:
				sys.exit(1)
-			print "\b\b ...done!"
+			if ("--namesonly" not in myopts):
+				print "\b\b ...done!"

			if ("--usepkgonly" in myopts) and
mydepgraph.missingbins:
				sys.stderr.write(red("The following binaries
are not available for merging...\n"))
Comment 7 Ramana Kumar 2005-12-09 07:28:25 UTC
Created attachment 74380 [details, diff]
emerge patch
Comment 8 Ramana Kumar 2005-12-09 07:29:17 UTC
Created attachment 74381 [details, diff]
emergehelp.py patch
Comment 9 SpanKY gentoo-dev 2005-12-09 07:29:44 UTC
$ emerge openssh -p --columns | awk '{print $4}'
net-misc/openssh
Comment 10 Ramana Kumar 2005-12-09 13:56:50 UTC
(In reply to comment #9)
> $ emerge openssh -p --columns | awk '{print $4}'
> net-misc/openssh

try 
emerge -pe --columns openssh | awk '{print $4}'

the output includes junk like
packages

...done!

and 
portage
so
-u

because of the introductory text emerge prints and also the portage update
message. these are suppressed by my patch but would require more complicated
shell scripts to get rid of on a regular basis.
Comment 11 Stephen Bennett (RETIRED) gentoo-dev 2005-12-09 14:00:13 UTC
(In reply to comment #10)
> because of the introductory text emerge prints and also the portage update
> message. these are suppressed by my patch but would require more complicated
> shell scripts to get rid of on a regular basis.

 emerge openssh -ep --columns | awk '/\[ebuild/{print $4}'

Doesn't seem too complicated to me.
Comment 12 Ramana Kumar 2005-12-09 14:05:54 UTC
(In reply to comment #11)
> (In reply to comment #10)
> > because of the introductory text emerge prints and also the portage update
> > message. these are suppressed by my patch but would require more complicated
> > shell scripts to get rid of on a regular basis.
> 
>  emerge openssh -ep --columns | awk '/\[ebuild/{print $4}'
> 
> Doesn't seem too complicated to me.
> 

ok then. but is there a somewhere this could be published? i know for one
population of people awk is obvious and second-nature, but for another--the ones
who ask me why emerge can't print names only--awk is unheard of. do gentoo users
not have the choice to remain oblivious to awk and similar external solutions?
(at least for this issue which seems to be fairly common to me)

Comment 13 SpanKY gentoo-dev 2005-12-09 14:09:09 UTC
i plan on fixing up emerge in portage to better respect --quiet to ease
scripting purposes

thus `emerge -qp --columns world` would only output the stuff needed
Comment 14 Ramana Kumar 2005-12-09 15:49:33 UTC
i concede the uselessness. it was a good experience to look at the emerge code =)
Comment 15 Eric Thibodeau 2006-06-02 05:39:39 UTC
Uhm... I'd like to re-open this one, I write many scripts to automate and manage machines and it's harder to explain the: 

sed -e 's:.*] \(.*\)-[0-9].*:\1:'

in

emerge -pe --nocolor world | sed -e 's:.*] \(.*\)-[0-9].*:\1:'

To console neophytes. The "output package names only" feature would be greatly appreciated and, IMHO, closer to the Linux/Unix philosophy of CLI tools.
Comment 16 solar (RETIRED) gentoo-dev 2006-06-03 12:30:54 UTC
Try this for your scripting needs.

qatom $(emerge --nospinner -qpuND world | grep ^'\[ebuild '| \
  cut -d ']' -f 2- |awk '{print $1}') | awk '{print $1"/"$2}'

qatom comes from portage-utils and is intended for uses like the one you need.
Comment 17 Eric Thibodeau 2006-06-03 13:02:15 UTC
(In reply to comment #16)
Uhm, you ralize your command line piping is much more complicated and less efficient than my present approach (calling 5 external apps in stead of 1):

> qatom $(emerge --nospinner -qpuND world | grep ^'\[ebuild '| \
>   cut -d ']' -f 2- |awk '{print $1}') | awk '{print $1"/"$2}'
> 
> qatom comes from portage-utils and is intended for uses like the one you need.

My present "hack" to only get package names is:
emerge --nospinner --nocolor -qpuNDe world | sed -e 's:.*] \(.*\)-[0-9].*:\1:'

As stated before, I'm only adding :
sed -e 's:.*] \(.*\)-[0-9].*:\1:'

The point is, there should be a way for portage to produce an output with requires no pre-treatment for direct piping purposes. ;)
Comment 18 Alec Warner (RETIRED) archtester gentoo-dev Security 2006-06-03 13:08:27 UTC
(In reply to comment #17)
> (In reply to comment #16)
> Uhm, you ralize your command line piping is much more complicated and less
> efficient than my present approach (calling 5 external apps in stead of 1):
> 
> > qatom $(emerge --nospinner -qpuND world | grep ^'\[ebuild '| \
> >   cut -d ']' -f 2- |awk '{print $1}') | awk '{print $1"/"$2}'
> > 
> > qatom comes from portage-utils and is intended for uses like the one you need.
> 
> My present "hack" to only get package names is:
> emerge --nospinner --nocolor -qpuNDe world | sed -e 's:.*] \(.*\)-[0-9].*:\1:'
> 
> As stated before, I'm only adding :
> sed -e 's:.*] \(.*\)-[0-9].*:\1:'
> 
> The point is, there should be a way for portage to produce an output with
> requires no pre-treatment for direct piping purposes. ;)
> 

If the dep resolver wasn't built into emerge this would be trivial, I don't want to add more silly --hacks and if("foo") then display crap to depgraph.display(). If nothing else, depgraph needs a seperate display function that only displays the nodes in it.