public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Alexander Berntsen" <bernalex@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: man/, pym/_emerge/
Date: Sat, 14 Jun 2014 21:46:14 +0000 (UTC)	[thread overview]
Message-ID: <1402781596.22637f20342dfd65d571212e9b426e697de1642a.bernalex@gentoo> (raw)

commit:     22637f20342dfd65d571212e9b426e697de1642a
Author:     Alexander Berntsen <bernalex <AT> gentoo <DOT> org>
AuthorDate: Sat Jun 14 21:14:12 2014 +0000
Commit:     Alexander Berntsen <bernalex <AT> gentoo <DOT> org>
CommitDate: Sat Jun 14 21:33:16 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=22637f20

Revert "emerge: Implement "--alert""

This reverts commit 1a00ddf5fb089724a127c8dc72d63f10ae72abbf. It had
some furiously annoying mistakes in the commit message. Also, someone
alluded to the man page being too short. Thanks, Brian.

Signed-off-by: Alexander Berntsen <bernalex <AT> gentoo.org>

---
 man/emerge.1             |  5 ----
 pym/_emerge/UserQuery.py | 71 ------------------------------------------------
 pym/_emerge/actions.py   | 19 +++++--------
 pym/_emerge/depgraph.py  |  9 ++----
 pym/_emerge/main.py      | 13 ---------
 pym/_emerge/unmerge.py   |  5 ++--
 pym/_emerge/userquery.py | 55 +++++++++++++++++++++++++++++++++++++
 7 files changed, 67 insertions(+), 110 deletions(-)

diff --git a/man/emerge.1 b/man/emerge.1
index bbcf569..abb0ed8 100644
--- a/man/emerge.1
+++ b/man/emerge.1
@@ -297,11 +297,6 @@ re\-distributable. With default
 configuration, this would result in an effective
 \fBACCEPT_RESTRICT\fR value of "* -bindist".
 .TP
-.BR "\-\-alert "
-Add a terminal bell character ('\\a') to all interactive prompts. This is
-especially useful if dependency resolution is taking a long time, and
-you want emerge to alert you when it is finished.
-.TP
 .BR "\-\-alphabetical "
 When displaying USE and other flag output, combines the enabled and
 disabled lists into one list and sorts the whole list alphabetically.

diff --git a/pym/_emerge/UserQuery.py b/pym/_emerge/UserQuery.py
deleted file mode 100644
index c866a0d..0000000
--- a/pym/_emerge/UserQuery.py
+++ /dev/null
@@ -1,71 +0,0 @@
-# Copyright 1999-2014 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-
-from __future__ import print_function
-
-import signal
-import sys
-
-from portage.output import bold, create_color_func
-
-
-class UserQuery(object):
-	"""The UserQuery class is used to prompt the user with a set of responses,
-	as well as accepting and handling the responses."""
-
-	def __init__(self, myopts):
-		self.myopts = myopts
-
-	def query(self, prompt, enter_invalid, responses=None, colours=None):
-		"""Display a prompt and a set of responses, then waits for user input
-		and check it against the responses. The first match is returned.
-
-		An empty response will match the first value in the list of responses,
-		unless enter_invalid is True. The input buffer is *not* cleared prior
-		to the prompt!
-
-		prompt: The String to display as a prompt.
-		responses: a List of Strings with the acceptable responses.
-		colours: a List of Functions taking and returning a String, used to
-		process the responses for display. Typically these will be functions
-		like red() but could be e.g. lambda x: "DisplayString".
-
-		If responses is omitted, it defaults to ["Yes", "No"], [green, red].
-		If only colours is omitted, it defaults to [bold, ...].
-
-		Returns a member of the List responses. (If called without optional
-		arguments, it returns "Yes" or "No".)
-
-		KeyboardInterrupt is converted to SystemExit to avoid tracebacks being
-		printed."""
-		if responses is None:
-			responses = ["Yes", "No"]
-			colours = [
-				create_color_func("PROMPT_CHOICE_DEFAULT"),
-				create_color_func("PROMPT_CHOICE_OTHER")
-			]
-		elif colours is None:
-			colours=[bold]
-		colours=(colours*len(responses))[:len(responses)]
-		if "--alert" in self.myopts:
-			prompt = '\a' + prompt
-		print(bold(prompt), end=' ')
-		try:
-			while True:
-				if sys.hexversion >= 0x3000000:
-					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))])+"] ")
-				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.")
-			sys.exit(128 + signal.SIGINT)

diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py
index b935139..4ca2f1c 100644
--- a/pym/_emerge/actions.py
+++ b/pym/_emerge/actions.py
@@ -84,7 +84,7 @@ from _emerge.sync.old_tree_timestamp import old_tree_timestamp_warn
 from _emerge.unmerge import unmerge
 from _emerge.UnmergeDepPriority import UnmergeDepPriority
 from _emerge.UseFlagDisplay import pkg_use_display
-from _emerge.UserQuery import UserQuery
+from _emerge.userquery import userquery
 
 if sys.hexversion >= 0x3000000:
 	long = int
@@ -387,9 +387,8 @@ def action_build(settings, trees, mtimedb,
 			else:
 				prompt="Would you like to merge these packages?"
 		print()
-		uq = UserQuery(myopts)
 		if prompt is not None and "--ask" in myopts and \
-			uq.query(prompt, enter_invalid) == "No":
+			userquery(prompt, enter_invalid) == "No":
 			print()
 			print("Quitting.")
 			print()
@@ -469,7 +468,6 @@ def action_build(settings, trees, mtimedb,
 
 def action_config(settings, trees, myopts, myfiles):
 	enter_invalid = '--ask-enter-invalid' in myopts
-	uq = UserQuery(myopts)
 	if len(myfiles) != 1:
 		print(red("!!! config can only take a single package atom at this time\n"))
 		sys.exit(1)
@@ -499,7 +497,7 @@ def action_config(settings, trees, myopts, myfiles):
 				print(options[-1]+") "+pkg)
 			print("X) Cancel")
 			options.append("X")
-			idx = uq.query("Selection?", enter_invalid, responses=options)
+			idx = userquery("Selection?", enter_invalid, responses=options)
 			if idx == "X":
 				sys.exit(128 + signal.SIGINT)
 			pkg = pkgs[int(idx)-1]
@@ -514,7 +512,7 @@ def action_config(settings, trees, myopts, myfiles):
 
 	print()
 	if "--ask" in myopts:
-		if uq.query("Ready to configure %s?" % pkg, enter_invalid) == "No":
+		if userquery("Ready to configure %s?" % pkg, enter_invalid) == "No":
 			sys.exit(128 + signal.SIGINT)
 	else:
 		print("Configuring pkg...")
@@ -1366,8 +1364,7 @@ def action_deselect(settings, trees, opts, atoms):
 			if '--ask' in opts:
 				prompt = "Would you like to remove these " + \
 					"packages from your world favorites?"
-				uq = UserQuery(opts)
-				if uq.query(prompt, enter_invalid) == 'No':
+				if userquery(prompt, enter_invalid) == 'No':
 					return 128 + signal.SIGINT
 
 			remaining = set(world_set)
@@ -2405,8 +2402,7 @@ def _sync_repo(emerge_config, repo):
 
 			if (retries==0):
 				if "--ask" in myopts:
-					uq = UserQuery(myopts)
-					if uq.query("Do you want to sync your Portage tree " + \
+					if userquery("Do you want to sync your Portage tree " + \
 						"with the mirror at\n" + blue(dosyncuri) + bold("?"),
 						enter_invalid) == "No":
 						print()
@@ -3845,8 +3841,7 @@ def run_action(emerge_config):
 						(access_desc,), noiselevel=-1)
 					if portage.data.secpass < 1 and not need_superuser:
 						portage.data.portage_group_warning()
-					uq = UserQuery(emerge_config.opts)
-					if uq.query("Would you like to add --pretend to options?",
+					if userquery("Would you like to add --pretend to options?",
 						"--ask-enter-invalid" in emerge_config.opts) == "No":
 						return 128 + signal.SIGINT
 					emerge_config.opts["--pretend"] = True

diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py
index 8177b74..bede7c6 100644
--- a/pym/_emerge/depgraph.py
+++ b/pym/_emerge/depgraph.py
@@ -73,7 +73,7 @@ from _emerge.SetArg import SetArg
 from _emerge.show_invalid_depstring_notice import show_invalid_depstring_notice
 from _emerge.UnmergeDepPriority import UnmergeDepPriority
 from _emerge.UseFlagDisplay import pkg_use_display
-from _emerge.UserQuery import UserQuery
+from _emerge.userquery import userquery
 
 from _emerge.resolver.backtracking import Backtracker, BacktrackParameter
 from _emerge.resolver.package_tracker import PackageTracker, PackageTrackerDbapiWrapper
@@ -520,9 +520,6 @@ class depgraph(object):
 		self._event_loop = (portage._internal_caller and
 			global_event_loop() or EventLoop(main=False))
 
-		self.uq = UserQuery(myopts)
-		self.query = UserQuery.query
-
 	def _load_vdb(self):
 		"""
 		Load installed package metadata if appropriate. This used to be called
@@ -7658,7 +7655,7 @@ class depgraph(object):
 		if ask and write_to_file and file_to_write_to:
 			prompt = "\nWould you like to add these " + \
 				"changes to your config files?"
-			if self.query(prompt, enter_invalid) == 'No':
+			if userquery(prompt, enter_invalid) == 'No':
 				write_to_file = False
 
 		if write_to_file and file_to_write_to:
@@ -7925,7 +7922,7 @@ class depgraph(object):
 					"favorites?"
 				enter_invalid = '--ask-enter-invalid' in \
 					self._frozen_config.myopts
-				if self.query(prompt, enter_invalid) == "No":
+				if userquery(prompt, enter_invalid) == "No":
 					skip = True
 
 			if not skip:

diff --git a/pym/_emerge/main.py b/pym/_emerge/main.py
index 1a920f7..eddb16c 100644
--- a/pym/_emerge/main.py
+++ b/pym/_emerge/main.py
@@ -124,7 +124,6 @@ def insert_optional_args(args):
 	new_args = []
 
 	default_arg_opts = {
-		'--alert'                : y_or_n,
 		'--ask'                  : y_or_n,
 		'--autounmask'           : y_or_n,
 		'--autounmask-keep-masks': y_or_n,
@@ -170,7 +169,6 @@ def insert_optional_args(args):
 	# since existence of -n makes it too ambiguous.
 	short_arg_opts_n = {
 		'a' : y_or_n,
-		'A' : y_or_n,
 		'b' : y_or_n,
 		'g' : y_or_n,
 		'G' : y_or_n,
@@ -302,12 +300,6 @@ def parse_opts(tmpcmdline, silent=False):
 	true_y = ("True", "y")
 	argument_options = {
 
-		"--alert": {
-			"shortopt" : "-A",
-			"help"    : "alert (terminal bell) on prompts",
-			"choices" : true_y_or_n
-		},
-
 		"--ask": {
 			"shortopt" : "-a",
 			"help"    : "prompt before performing any actions",
@@ -683,11 +675,6 @@ def parse_opts(tmpcmdline, silent=False):
 
 	myoptions, myargs = parser.parse_known_args(args=tmpcmdline)
 
-	if myoptions.alert in true_y:
-		myoptions.alert = True
-	else:
-		myoptions.alert = None
-
 	if myoptions.ask in true_y:
 		myoptions.ask = True
 	else:

diff --git a/pym/_emerge/unmerge.py b/pym/_emerge/unmerge.py
index 8f98563..b04f8f3 100644
--- a/pym/_emerge/unmerge.py
+++ b/pym/_emerge/unmerge.py
@@ -17,8 +17,8 @@ from portage.versions import cpv_sort_key, _pkg_str
 
 from _emerge.emergelog import emergelog
 from _emerge.Package import Package
-from _emerge.UserQuery import UserQuery
 from _emerge.UninstallFailure import UninstallFailure
+from _emerge.userquery import userquery
 from _emerge.countdown import countdown
 
 def _unmerge_display(root_config, myopts, unmerge_action,
@@ -529,8 +529,7 @@ def unmerge(root_config, myopts, unmerge_action,
 		#we're done... return
 		return os.EX_OK
 	if "--ask" in myopts:
-		uq = UserQuery(myopts)
-		if uq.query("Would you like to unmerge these packages?",
+		if userquery("Would you like to unmerge these packages?",
 			enter_invalid) == "No":
 			# enter pretend mode for correct formatting of results
 			myopts["--pretend"] = True

diff --git a/pym/_emerge/userquery.py b/pym/_emerge/userquery.py
new file mode 100644
index 0000000..efae80a
--- /dev/null
+++ b/pym/_emerge/userquery.py
@@ -0,0 +1,55 @@
+# Copyright 1999-2012 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+from __future__ import print_function
+
+import signal
+import sys
+
+from portage.output import bold, create_color_func
+
+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,
+	unless enter_invalid is True. The input buffer is *not* cleared prior
+	to the prompt!
+
+	prompt: a String.
+	responses: a List of Strings.
+	colours: a List of Functions taking and returning a String, used to
+	process the responses for display. Typically these will be functions
+	like red() but could be e.g. lambda x: "DisplayString".
+	If responses is omitted, defaults to ["Yes", "No"], [green, red].
+	If only colours is omitted, defaults to [bold, ...].
+
+	Returns a member of the List responses. (If called without optional
+	arguments, returns "Yes" or "No".)
+	KeyboardInterrupt is converted to SystemExit to avoid tracebacks being
+	printed."""
+	if responses is None:
+		responses = ["Yes", "No"]
+		colours = [
+			create_color_func("PROMPT_CHOICE_DEFAULT"),
+			create_color_func("PROMPT_CHOICE_OTHER")
+		]
+	elif colours is None:
+		colours=[bold]
+	colours=(colours*len(responses))[:len(responses)]
+	print(bold(prompt), end=' ')
+	try:
+		while True:
+			if sys.hexversion >= 0x3000000:
+				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))])+"] ")
+			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.")
+		sys.exit(128 + signal.SIGINT)


             reply	other threads:[~2014-06-14 21:46 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-14 21:46 Alexander Berntsen [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-02-03  3:07 [gentoo-commits] proj/portage:master commit in: man/, pym/_emerge/ Zac Medico
2018-01-30  4:24 Zac Medico
2017-05-14 18:12 Zac Medico
2016-08-08 15:56 Zac Medico
2014-12-07 23:14 Zac Medico
2014-10-21 23:11 Zac Medico
2014-10-20  0:08 Zac Medico
2014-09-24 22:36 Brian Dolbec
2014-06-14 21:46 Alexander Berntsen
2014-06-14 20:58 Alexander Berntsen
2013-07-18 20:25 Zac Medico
2013-07-18 20:23 Zac Medico
2013-02-23 19:17 Zac Medico
2012-12-29 22:35 Zac Medico
2012-12-08  9:25 Zac Medico
2012-11-29  7:53 Zac Medico
2012-10-08 20:30 Zac Medico
2011-12-14  4:47 Zac Medico
2011-10-16 18:58 Zac Medico
2011-10-10 18:05 Zac Medico
2011-09-21 14:00 Zac Medico
2011-09-19 16:03 Zac Medico
2011-09-19 14:15 Zac Medico
2011-09-18 20:16 Zac Medico
2011-07-19  8:38 Zac Medico
2011-06-04 23:32 Zac Medico
2011-06-03  5:40 Zac Medico
2011-05-17  4:31 Zac Medico
2011-05-15 19:20 Zac Medico
2011-05-11 19:04 Zac Medico
2011-04-28 16:16 Zac Medico
2011-04-27 22:07 Zac Medico
2011-04-27 22:03 Zac Medico
2011-04-27 22:00 Zac Medico
2011-03-24 18:18 Zac Medico
2011-03-14 17:52 Zac Medico
2011-02-13  0:24 Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1402781596.22637f20342dfd65d571212e9b426e697de1642a.bernalex@gentoo \
    --to=bernalex@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox