public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] portage r14710 - in main/trunk: man pym/_emerge
@ 2009-10-24  6:55 Zac Medico (zmedico)
  0 siblings, 0 replies; only message in thread
From: Zac Medico (zmedico) @ 2009-10-24  6:55 UTC (permalink / raw
  To: gentoo-commits

Author: zmedico
Date: 2009-10-24 06:55:34 +0000 (Sat, 24 Oct 2009)
New Revision: 14710

Modified:
   main/trunk/man/emerge.1
   main/trunk/pym/_emerge/actions.py
   main/trunk/pym/_emerge/help.py
   main/trunk/pym/_emerge/main.py
   main/trunk/pym/_emerge/unmerge.py
   main/trunk/pym/_emerge/userquery.py
Log:
Bug #134466 - Add a --ask-enter-invalid option. When used together with the
--ask option, interpret a single "Enter" key press as invalid input. This
helps prevent accidental acceptance of the first choice.


Modified: main/trunk/man/emerge.1
===================================================================
--- main/trunk/man/emerge.1	2009-10-24 05:12:32 UTC (rev 14709)
+++ main/trunk/man/emerge.1	2009-10-24 06:55:34 UTC (rev 14710)
@@ -264,8 +264,18 @@
 \fBWARNING: If the "Enter" key is pressed at the prompt (with no other input),
 it is interpreted as acceptance of the first choice.  Note that the input
 buffer is not cleared prior to the prompt, so an accidental press of the
-"Enter" key at any time prior to the prompt will be interpreted as a choice!\fR
+"Enter" key at any time prior to the prompt will be interpreted as a choice!
+Use the \-\-ask\-enter\-invalid option if you want a single "Enter" key
+press to be interpreted as invalid input.\fR
 .TP
+.BR "\-\-ask\-enter\-invalid"
+When used together with the \fB\-\-ask\fR option,
+interpret a single "Enter" key press as
+invalid input. This helps prevent accidental
+acceptance of the first choice. This option is
+intended to be set in the \fBmake.conf\fR(5)
+\fBEMERGE_DEFAULT_OPTS\fR variable.
+.TP
 .BR "\-\-binpkg\-respect\-use < y | n >"
 Tells emerge to ignore binary packages if their use flags
 don't match the current configuration. (default: \'n\')

Modified: main/trunk/pym/_emerge/actions.py
===================================================================
--- main/trunk/pym/_emerge/actions.py	2009-10-24 05:12:32 UTC (rev 14709)
+++ main/trunk/pym/_emerge/actions.py	2009-10-24 06:55:34 UTC (rev 14710)
@@ -134,6 +134,7 @@
 	pretend = "--pretend" in myopts
 	fetchonly = "--fetchonly" in myopts or "--fetch-all-uri" in myopts
 	ask = "--ask" in myopts
+	enter_invalid = '--ask-enter-invalid' in myopts
 	nodeps = "--nodeps" in myopts
 	oneshot = "--oneshot" in myopts or "--onlydeps" in myopts
 	tree = "--tree" in myopts
@@ -340,7 +341,7 @@
 			else:
 				prompt="Would you like to merge these packages?"
 		print()
-		if "--ask" in myopts and userquery(prompt) == "No":
+		if "--ask" in myopts and userquery(prompt, enter_invalid) == "No":
 			print()
 			print("Quitting.")
 			print()
@@ -441,6 +442,7 @@
 		return retval
 
 def action_config(settings, trees, myopts, myfiles):
+	enter_invalid = '--ask-enter-invalid' in myopts
 	if len(myfiles) != 1:
 		print(red("!!! config can only take a single package atom at this time\n"))
 		sys.exit(1)
@@ -470,7 +472,7 @@
 				print(options[-1]+") "+pkg)
 			print("X) Cancel")
 			options.append("X")
-			idx = userquery("Selection?", options)
+			idx = userquery("Selection?", enter_invalid, responses=options)
 			if idx == "X":
 				sys.exit(0)
 			pkg = pkgs[int(idx)-1]
@@ -485,7 +487,7 @@
 
 	print()
 	if "--ask" in myopts:
-		if userquery("Ready to configure "+pkg+"?") == "No":
+		if userquery("Ready to configure %s?" % pkg, enter_invalid) == "No":
 			sys.exit(0)
 	else:
 		print("Configuring pkg...")
@@ -1142,6 +1144,7 @@
 	return 0, [], False, required_pkgs_total
 
 def action_deselect(settings, trees, opts, atoms):
+	enter_invalid = '--ask-enter-invalid' in opts
 	root_config = trees[settings['ROOT']]['root_config']
 	world_set = root_config.sets['selected']
 	if not hasattr(world_set, 'update'):
@@ -1184,7 +1187,7 @@
 			if '--ask' in opts:
 				prompt = "Would you like to remove these " + \
 					"packages from your world favorites?"
-				if userquery(prompt) == 'No':
+				if userquery(prompt, enter_invalid) == 'No':
 					return os.EX_OK
 
 			remaining = set(world_set)
@@ -1679,6 +1682,7 @@
 			searchinstance.output()
 
 def action_sync(settings, trees, mtimedb, myopts, myaction):
+	enter_invalid = '--ask-enter-invalid' in myopts
 	xterm_titles = "notitles" not in settings.features
 	emergelog(xterm_titles, " === sync")
 	portdb = trees[settings["ROOT"]]["porttree"].dbapi
@@ -1924,7 +1928,9 @@
 
 			if (retries==0):
 				if "--ask" in myopts:
-					if userquery("Do you want to sync your Portage tree with the mirror at\n" + blue(dosyncuri) + bold("?"))=="No":
+					if userquery("Do you want to sync your Portage tree " + \
+						"with the mirror at\n" + blue(dosyncuri) + bold("?"),
+						enter_invalid) == "No":
 						print()
 						print("Quitting.")
 						print()

Modified: main/trunk/pym/_emerge/help.py
===================================================================
--- main/trunk/pym/_emerge/help.py	2009-10-24 05:12:32 UTC (rev 14709)
+++ main/trunk/pym/_emerge/help.py	2009-10-24 06:55:34 UTC (rev 14710)
@@ -255,17 +255,30 @@
 		print("              be displayed as USE=\"-bar dar -foo\"")
 		print()
 		print("       "+green("--ask")+" ("+green("-a")+" short option)")
-		print("              before performing the merge, display what ebuilds and tbz2s will")
-		print("              be installed, in the same format as when using --pretend; then")
-		print("              ask whether to continue with the merge or abort. Using --ask is")
-		print("              more efficient than using --pretend and then executing the same")
-		print("              command without --pretend, as dependencies will only need to be")
-		print("              calculated once. WARNING: If the \"Enter\" key is pressed at the")
-		print("              prompt (with no other input), it is interpreted as acceptance of")
-		print("              the first choice.  Note that the input buffer is not cleared prior")
-		print("              to the prompt, so an accidental press of the \"Enter\" key at any")
-		print("              time prior to the prompt will be interpreted as a choice!")
+		desc = "Before performing the action, display what will take place (server info for " + \
+			"--sync, --pretend output for merge, and so forth), then ask " + \
+			"whether to proceed with the action or abort.  Using --ask is more " + \
+			"efficient than using --pretend and then executing the same command " + \
+			"without --pretend, as dependencies will only need to be calculated once. " + \
+			"WARNING: If the \"Enter\" key is pressed at the prompt (with no other input), " + \
+			"it is interpreted as acceptance of the first choice.  Note that the input " + \
+			"buffer is not cleared prior to the prompt, so an accidental press of the " + \
+			"\"Enter\" key at any time prior to the prompt will be interpreted as a choice! " + \
+			"Use the --ask-enter-invalid option if you want a single \"Enter\" key " + \
+			"press to be interpreted as invalid input."
+		for line in wrap(desc, desc_width):
+			print(desc_indent + line)
 		print()
+		print("        " + green("--ask-enter-invalid"))
+		desc = "When used together with the --ask option, " + \
+			"interpret a single \"Enter\" key press as " + \
+			"invalid input. This helps prevent accidental " + \
+			"acceptance of the first choice. This option is " + \
+			"intended to be set in the make.conf(5) " + \
+			"EMERGE_DEFAULT_OPTS variable."
+		for line in wrap(desc, desc_width):
+			print(desc_indent + line)
+		print()
 		print("        " + green("--binpkg-respect-use") + \
 			" < " + turquoise("y") + " | " + turquoise("n") + " >")
 		desc = "Tells emerge to ignore binary packages if their use flags" + \

Modified: main/trunk/pym/_emerge/main.py
===================================================================
--- main/trunk/pym/_emerge/main.py	2009-10-24 05:12:32 UTC (rev 14709)
+++ main/trunk/pym/_emerge/main.py	2009-10-24 06:55:34 UTC (rev 14710)
@@ -49,6 +49,7 @@
 
 options=[
 "--ask",          "--alphabetical",
+"--ask-enter-invalid",
 "--buildpkg",     "--buildpkgonly",
 "--changed-use",
 "--changelog",    "--columns",

Modified: main/trunk/pym/_emerge/unmerge.py
===================================================================
--- main/trunk/pym/_emerge/unmerge.py	2009-10-24 05:12:32 UTC (rev 14709)
+++ main/trunk/pym/_emerge/unmerge.py	2009-10-24 06:55:34 UTC (rev 14710)
@@ -27,6 +27,7 @@
 	if clean_world:
 		clean_world = myopts.get('--deselect') != 'n'
 	quiet = "--quiet" in myopts
+	enter_invalid = '--ask-enter-invalid' in myopts
 	settings = root_config.settings
 	sets = root_config.sets
 	vartree = root_config.trees["vartree"]
@@ -483,7 +484,8 @@
 		#we're done... return
 		return 0
 	if "--ask" in myopts:
-		if userquery("Would you like to unmerge these packages?")=="No":
+		if userquery("Would you like to unmerge these packages?",
+			enter_invalid) == "No":
 			# enter pretend mode for correct formatting of results
 			myopts["--pretend"] = True
 			print()

Modified: main/trunk/pym/_emerge/userquery.py
===================================================================
--- main/trunk/pym/_emerge/userquery.py	2009-10-24 05:12:32 UTC (rev 14709)
+++ main/trunk/pym/_emerge/userquery.py	2009-10-24 06:55:34 UTC (rev 14710)
@@ -8,11 +8,12 @@
 
 from portage.output import bold, create_color_func
 
-def userquery(prompt, responses=None, colours=None):
+def userquery(prompt, enter_invalid, responses=None, colours=None):
 	"""Displays a prompt and a set of responses, then waits for a response
 	which is checked against the responses and the first to match is
-	returned.  An empty response will match the first value in responses.  The
-	input buffer is *not* cleared prior to the prompt!
+	returned. An empty response will match the first value in responses,
+	unless enter_invalid is True. The input buffer is *not* cleared prior
+	to the prompt!
 
 	prompt: a String.
 	responses: a List of Strings.
@@ -42,10 +43,12 @@
 				response=input("["+"/".join([colours[i](responses[i]) for i in range(len(responses))])+"] ")
 			else:
 				response=raw_input("["+"/".join([colours[i](responses[i]) for i in range(len(responses))])+"] ")
-			for key in responses:
-				# An empty response will match the first value in responses.
-				if response.upper()==key[:len(response)].upper():
-					return key
+			if response or not enter_invalid:
+				for key in responses:
+					# An empty response will match the
+					# first value in responses.
+					if response.upper()==key[:len(response)].upper():
+						return key
 			print("Sorry, response '%s' not understood." % response, end=' ')
 	except (EOFError, KeyboardInterrupt):
 		print("Interrupted.")




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-10-24  6:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-24  6:55 [gentoo-commits] portage r14710 - in main/trunk: man pym/_emerge Zac Medico (zmedico)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox