public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Paul Varner" <fuzzyray@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoolkit:gentoolkit commit in: bin/
Date: Tue, 29 Mar 2011 02:18:14 +0000 (UTC)	[thread overview]
Message-ID: <d48d1c9525f6632e9ba58202e028bb517b0a118c.fuzzyray@gentoo> (raw)

commit:     d48d1c9525f6632e9ba58202e028bb517b0a118c
Author:     Paul Varner <fuzzyray <AT> gentoo <DOT> org>
AuthorDate: Tue Mar 29 02:12:44 2011 +0000
Commit:     Paul Varner <fuzzyray <AT> gentoo <DOT> org>
CommitDate: Tue Mar 29 02:12:44 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=d48d1c95

Latest euse changes from Jared Hancock
Prefers /etc/portage/make.conf when modifing global flags only if it
defines the USE variable

Also fixes a bug where euse would refuse to add hyphenated use flags.
So you can:

	euse -E bash-completion

---
 bin/euse |   79 ++++++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 46 insertions(+), 33 deletions(-)

diff --git a/bin/euse b/bin/euse
index dbbb129..8262271 100755
--- a/bin/euse
+++ b/bin/euse
@@ -29,10 +29,13 @@ warn() {
 	echo -e "WARNING: ${*}"
 }
 
-# /etc/make.conf can now exist in /etc/portage/make.conf, prefer it over /etc/make.conf for changes
-if [ -e "${ETC}/portage/make.conf" ]; then
+# /etc/make.conf can now exist in /etc/portage/make.conf, prefer it over
+# /etc/make.conf for changes. Since this will only be used for modifying
+# the USE variable, we need to make sure the one we pick is the one with
+# the USE variable defined.
+if [[ -n $(grep '^USE="' "${ETC}/portage/make.conf" 2>/dev/null) ]]; then
 	MAKE_CONF_PATH="${ETC}/portage/make.conf"
-elif [ -e "${ETC}/make.conf" ]; then
+elif [[ -e "${ETC}/make.conf" ]]; then
 	MAKE_CONF_PATH="${ETC}/make.conf"
 else
 	fatal "make.conf does not exist"
@@ -56,7 +59,7 @@ else
 fi
 PACKAGE_USE_PATH=${ETC}/portage/package.use
 
-[ -z "${MODE}" ] && MODE="showhelp"		# available operation modes: showhelp, showversion, showdesc, showflags, modify
+[ -z "${MODE:-}" ] && MODE="showhelp"		# available operation modes: showhelp, showversion, showdesc, showflags, modify
 
 parse_arguments() {
 	if [ -z "${1}" ]; then
@@ -74,8 +77,8 @@ parse_arguments() {
 			-E | --enable)         MODE="modify"; ACTION="add";;
 			-D | --disable)        MODE="modify"; ACTION="remove";;
 			-P | --prune | -R | --remove)
-                                               MODE="modify"; ACTION="prune";;
-			-p | --package)	       MODE="modify"; shift; PACKAGE=${1}; SCOPE="local";;
+			                       MODE="modify"; ACTION="prune";;
+			-p | --package)        MODE="modify"; shift; PACKAGE=${1}; SCOPE="local";;
 			-*)
 				echo "ERROR: unknown option ${1} specified."
 				echo
@@ -83,10 +86,10 @@ parse_arguments() {
 				;;
 			"%active")
 				get_portageuseflags
-				ARGUMENTS="${ARGUMENTS} ${ACTIVE_FLAGS[9]}"
+				ARGUMENTS="${ARGUMENTS:-} ${ACTIVE_FLAGS[9]}"
 				;;
 			*)
-				ARGUMENTS="${ARGUMENTS} ${1}"
+				ARGUMENTS="${ARGUMENTS:-} ${1}"
 				;;
 		esac
 		shift
@@ -128,6 +131,7 @@ check_sanity() {
 	done
 	[ "${MODE}" == "modify" -a ! -w "${MAKE_CONF_PATH}" ] && fatal ""${MAKE_CONF_PATH}" is not writable"
 	[ "${MODE}" == "modify" -a -s "${PACKAGE_USE_PATH}" -a ! -w "${PACKAGE_USE_PATH}" ] && fatal ""${PACKAGE_USE_PATH}" is not writable"
+	return 0
 } # }}}
 
 showhelp() {
@@ -435,7 +439,7 @@ get_all_make_conf() {
 traverse_profile() {
 	local curdir
 	local parent
-	local rvalue
+	local rvalue=""
 	
 	curdir="${2:-$(get_real_path ${MAKE_PROFILE_PATH})}"
 	
@@ -458,7 +462,7 @@ traverse_profile() {
 # Function: get_all_make_defaults {{{
 # Det all make.defaults by traversing the cascaded profile directories
 get_all_make_defaults() {
-	if [[ -z $MAKE_DEFAULTS ]]; then
+	if [[ -z ${MAKE_DEFAULTS:-} ]]; then
 		MAKE_DEFAULTS=$(traverse_profile "make.defaults")
 	fi
 	echo $MAKE_DEFAULTS
@@ -606,7 +610,7 @@ get_flagstatus() {
 # Flag status for package.use and ebuild, slot and version, and overlay
 # the version lives is if not PORTDIR
 #
-# Full positive would be "[+PB]", full negative would be "[-pb], and full 
+# Full positive would be "[+PB]", full negative would be "[-pb]", and full 
 # missing would be "[?  ]", question because the sign will default to the 
 # sign of the global status of the flag
 get_flagstatus_pkg() {
@@ -671,8 +675,10 @@ get_flagstatus_pkg() {
 # Outputs:
 # Location of portage tree root
 get_portdir() {
-	if [ -z "${PORTDIR}" ]; then
-		use_backup="${USE}"
+	# Use a subshell so we don't have to protect the variables in
+	# the current scope
+	(
+	if [ -z "${PORTDIR:-}" ]; then
 		source "${MAKE_GLOBALS_PATH}"
 		for x in $(get_all_make_defaults); do
 			source "${x}"
@@ -680,9 +686,9 @@ get_portdir() {
 		for x in $(get_all_make_conf); do
 			source "${x}"
 		done
-		USE="${use_backup}"
 	fi
 	echo "${PORTDIR}"
+	)
 } # }}}
 # This won't change while the script is running, so cache it
 PORTDIR="$(get_portdir)"
@@ -691,10 +697,14 @@ PORTDIR="$(get_portdir)"
 # Outputs list of portage overlays as defined in the PORTDIR_OVERLAY
 # variable defined in make.conf 
 get_all_overlays() {
-	use_backup="${USE}"
-	source "${MAKE_CONF_PATH}"
-	USE="${use_backup}"
-	echo ${PORTDIR_OVERLAY}
+	# Use a subshell so we don't have to protect the variables in
+	# the current scope
+	( 
+		for x in $(get_all_make_conf); do
+			[[ -r "${x}" ]] && source "${x}"
+		done
+		echo ${PORTDIR_OVERLAY}
+	)
 } # }}}
 ALL_PORTDIRS=( "$PORTDIR" $(get_all_overlays) )
 
@@ -761,8 +771,7 @@ showdesc() {
 			if array_contains "${useflags[*]}" "$1"; then
 				get_flagstatus "${1}"
 				# XXX: Handle overlay
-				grep "^${1}  *-" ${ALL_PORTDIRS[@]/%//profiles/use.desc} 2> /dev/null \
-					| sed -re "s/^([^:]+)://"
+				grep -h "^${1}  *-" ${ALL_PORTDIRS[@]/%//profiles/use.desc} 2> /dev/null
 				foundone=1
 			fi
 		fi
@@ -773,14 +782,14 @@ showdesc() {
 				foundone=1
 			fi
 			# Fetch all the packages data using this flag
-			infos=$( grep ":${1}  *-" ${ALL_PORTDIRS[@]/%//profiles/use.local.desc} 2> /dev/null \
-				| sed -re "s/^([^:]+):([^:]+):(${1}) *- *(.+)/\1|\2|\3|\4/g")
+			infos=$( grep -h ":${1}  *-" ${ALL_PORTDIRS[@]/%//profiles/use.local.desc} 2> /dev/null \
+				| sed -re "s/^([^:]+):(${1}) *- *(.+)/\1|\2|\3/g")
 			OIFS=$IFS; IFS=$'\n'; infos=($infos); IFS=$OIFS;
 			for line in "${infos[@]}"; do
 				OIFS=$IFS; IFS="|"; line=($line); IFS=$OIFS
-				pkg=${line[1]} 
-				flag=${line[2]}
-				desc=${line[3]}
+				pkg=${line[0]} 
+				flag=${line[1]}
+				desc=${line[2]}
 				if get_flagstatus "${flag}"; then
 					ACTIVE="+"
 				else
@@ -925,18 +934,22 @@ showflags() {
 
 # two small helpers to add or remove a flag from a USE string
 add_flag() {
-	if [[ -n $(grep " -${1//-/} " <<< " ${ACTIVE_FLAGS[6]} ") ]]; then
-		error "Use flag \"${1//-/}\" is masked and should not be added" \
+	# Remove leading '-' from flag if found
+	local flag=$1
+	[[ ${flag:0:1} == "-" ]] && flag=${1:1}
+
+	if [[ -n $(grep " -${flag} " <<< " ${ACTIVE_FLAGS[6]} ") ]]; then
+		error "Use flag \"${flag}\" is masked and should not be added" \
 			  "to make.conf."
 		return 1
 	# Bug #104396 -- Only add use flags defined in use.desc and use.local.desc
-	elif [[ -z $(grep "^${1//-/}$" <<< "$(get_useflaglist)") ]]; then
-		error "Use flag \"${1//-/}\" is not defined in use.desc and should" \
+	elif [[ -z $(grep "^${flag}$" <<< "$(get_useflaglist)") ]]; then
+		error "Use flag \"${flag}\" is not defined in use.desc and should" \
 			  "not be added\nto make.conf."
 		return 1
 	else
 		NEW_MAKE_CONF_USE="${NEW_MAKE_CONF_USE} ${1}"
-		echo "Adding flag \"${1}\" to make.conf" >&2
+	echo "Adding flag \"${1}\" to make.conf" >&2
 	fi
 }
 
@@ -981,9 +994,8 @@ scrub_use_flag() {
 		elif [[ -n "${PACKAGE}" ]]; then
 			if [[ -n $(echo "${line}" | grep -Ee "${pkg_re}") ]]; then	
 				# If this is the only (remaining) use flag defined
-				# for this package, then remove the whole line
-				if [[ -z $(echo "${line}" | \
-						grep -Ee "${pkg_re} *-?${flag} *$") ]]; then
+		# for this package, then remove the whole line
+		if [[ -z $(echo "${line}" | grep -Ee "${pkg_re} *-?${flag} *$") ]]; then
 					# Remove flag from this line
 					echo "${line}" | sed -re "s/ *-?\b${flag}\b//"
 				fi
@@ -1231,6 +1243,7 @@ modify() {
 		fi
 	done
 
+	# Bail if there is no need to modify make.conf
 	[[ ${make_conf_modified} == 1 ]] || return
 	# make a backup just in case the user doesn't like the new make.conf
 	cp -p "${MAKE_CONF_PATH}" "${MAKE_CONF_BACKUP_PATH}"



             reply	other threads:[~2011-03-29  2:18 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-29  2:18 Paul Varner [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-06-02 19:32 [gentoo-commits] proj/gentoolkit:gentoolkit commit in: bin/ Paul Varner
2015-04-23 21:20 Paul Varner
2015-01-23 21:22 Paul Varner
2014-10-24 18:02 Paul Varner
2014-03-06 16:39 Paul Varner
2014-02-12 10:22 Brian Dolbec
2013-11-20 20:38 Vikraman Choudhury
2013-11-20  2:34 Paul Varner
2013-11-05 17:24 Paul Varner
2013-09-10 23:03 Paul Varner
2013-09-10 18:53 Paul Varner
2013-09-10 16:01 Paul Varner
2013-09-04 21:44 Paul Varner
2013-08-29 17:37 Paul Varner
2013-07-08 19:20 Paul Varner
2012-09-26  6:13 Paul Varner
2012-06-20 17:17 Paul Varner
2012-06-20 17:17 Paul Varner
2012-05-16 22:31 Paul Varner
2012-04-11 18:50 Paul Varner
2012-04-11 17:42 Paul Varner
2012-03-20  4:04 Paul Varner
2012-03-06  5:36 Paul Varner
2012-02-28 21:44 Paul Varner
2012-02-20 23:25 Paul Varner
2012-02-20 23:25 Paul Varner
2012-02-16 17:37 Paul Varner
2011-11-28 15:46 Paul Varner
2011-10-12 16:39 Paul Varner
2011-09-07 12:40 Christian Ruppert
2011-08-24 17:30 Paul Varner
2011-07-27 19:02 Paul Varner
2011-07-13 16:01 Paul Varner
2011-07-13 15:41 Paul Varner
2011-07-12 21:45 Paul Varner
2011-05-29 10:59 Christian Ruppert
2011-05-25  1:02 Paul Varner
2011-05-23 21:28 Paul Varner
2011-05-12  2:55 Paul Varner
2011-05-11  2:06 Paul Varner
2011-05-11  0:43 Paul Varner
2011-04-24  0:59 Brian Dolbec
2011-02-25 16:50 Paul Varner
2011-02-25 16:50 Paul Varner
2011-02-25 16:50 Paul Varner

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=d48d1c9525f6632e9ba58202e028bb517b0a118c.fuzzyray@gentoo \
    --to=fuzzyray@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