Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 259318 | Differences between
and this patch

Collapse All | Expand All

(-)/usr/bin/euse (-29 / +342 lines)
Lines 13-18 Link Here
13
MAKE_GLOBALS_PATH=/etc/make.globals
13
MAKE_GLOBALS_PATH=/etc/make.globals
14
MAKE_PROFILE_PATH=/etc/make.profile
14
MAKE_PROFILE_PATH=/etc/make.profile
15
MAKE_CONF_BACKUP_PATH=/etc/make.conf.euse_backup
15
MAKE_CONF_BACKUP_PATH=/etc/make.conf.euse_backup
16
PACKAGE_USE_PATH=/etc/portage/package.use
16
17
17
[ -z "${MODE}" ] && MODE="showhelp"		# available operation modes: showhelp, showversion, showdesc, showflags, modify
18
[ -z "${MODE}" ] && MODE="showhelp"		# available operation modes: showhelp, showversion, showdesc, showflags, modify
18
19
Lines 32-44 Link Here
32
			-E | --enable)         MODE="modify"; ACTION="add";;
33
			-E | --enable)         MODE="modify"; ACTION="add";;
33
			-D | --disable)        MODE="modify"; ACTION="remove";;
34
			-D | --disable)        MODE="modify"; ACTION="remove";;
34
			-P | --prune)          MODE="modify"; ACTION="prune";;
35
			-P | --prune)          MODE="modify"; ACTION="prune";;
36
			-p | --package)	       MODE="modify"; shift; PACKAGE=${1};;
35
			-*)
37
			-*)
36
				echo "ERROR: unknown option ${1} specified."
38
				echo "ERROR: unknown option ${1} specified."
37
				echo
39
				echo
38
				MODE="showhelp"
40
				MODE="showhelp"
39
				;;
41
				;;
40
			"%active")
42
			"%active")
41
				get_useflags
43
				get_portageuseflags
42
				ARGUMENTS="${ARGUMENTS} ${ACTIVE_FLAGS[9]}"
44
				ARGUMENTS="${ARGUMENTS} ${ACTIVE_FLAGS[9]}"
43
				;;
45
				;;
44
			*)
46
			*)
Lines 55-60 Link Here
55
	exit 1
57
	exit 1
56
}
58
}
57
59
60
warn() {
61
	echo "WARNING: ${1}"
62
}
63
58
get_real_path() {
64
get_real_path() {
59
	set -P
65
	set -P
60
	cd "$1"
66
	cd "$1"
Lines 82-87 Link Here
82
	done
88
	done
83
#	[ ! -r "$(get_make_defaults)" ] && error "$(get_make_defaults) is not readable"
89
#	[ ! -r "$(get_make_defaults)" ] && error "$(get_make_defaults) is not readable"
84
	[ "${MODE}" == "modify" -a ! -w "${MAKE_CONF_PATH}" ] && error ""${MAKE_CONF_PATH}" is not writable"
90
	[ "${MODE}" == "modify" -a ! -w "${MAKE_CONF_PATH}" ] && error ""${MAKE_CONF_PATH}" is not writable"
91
	[ "${MODE}" == "modify" -a -s "${PACKAGE_USE_PATH}" -a ! -w "${PACKAGE_USE_PATH}" ] && error ""${PACKAGE_USE_PATH}" is not writable"
85
}
92
}
86
93
87
showhelp() {
94
showhelp() {
Lines 101-113 Link Here
101
         -E, --enable         - enable the given useflags
108
         -E, --enable         - enable the given useflags
102
         -D, --disable        - disable the given useflags
109
         -D, --disable        - disable the given useflags
103
         -P, --prune          - remove all references to the given flags from
110
         -P, --prune          - remove all references to the given flags from
104
                                make.conf to revert to default settings
111
                                make.conf and package.use to revert to default 
112
                                settings
113
         -p, --package        - used with -E, -D, to apply to a specific
114
                                package only
105
115
106
Notes: ${PROGRAM_NAME} currently only works for global flags defined
116
Notes: ${PROGRAM_NAME} currently only works for global flags defined
107
       in make.globals, make.defaults or make.conf, it doesn't handle
117
       in make.globals, make.defaults or make.conf, and local flags defined
108
       use.defaults, use.mask or package.use yet (see portage(5) for details on
118
       in package.use and individual package ebuilds, it doesn't handle
109
       these files). It also might have issues with cascaded profiles.
119
       use.defaults or use.mask yet (see portage(5) for details on these
110
       If multiple options are specified only the last one will be used.
120
       files). It also might have issues with cascaded profiles. If 
121
       multiple options are specified only the last one will be used.
111
HELP
122
HELP
112
}
123
}
113
124
Lines 147-159 Link Here
147
print ' '.join(r)" 
158
print ' '.join(r)" 
148
}
159
}
149
160
161
# Similar to reduce_incrementals except converts lines from package atoms
162
# in /etc/portage/package.use files to lines of "pkg {[-]flag}*"
163
reduce_package_use() {
164
    echo "${@}" | python -c "import sys,re
165
h={}; atom=re.compile(r'[<>]?=?([a-z][\w/-]+[a-z])(-[\dpr._*-]+)?', re.I); 
166
getflags=re.compile(r'(-?[\w*-]+)')
167
for x in sys.stdin.read().split('\n'):
168
	if not x: continue
169
	parts = x.lstrip().split(' ',1)
170
	if len(parts)==1: continue
171
	try:
172
		pkg = atom.match(parts[0]).group(1)
173
	except:
174
		continue
175
	flags = getflags.findall(parts[1])
176
	if not pkg in h: h[pkg]=[]
177
	r=h[pkg]
178
	for x in flags:
179
		if x[0] == '-' and x[1:] in r:
180
			r.remove(x[1:])
181
			r.append(x)
182
		elif x[0] != '-' and '-'+x in r:
183
			r.remove('-'+x)
184
			r.append(x)
185
		elif x == '-*':
186
			r = h[pkg] = ['-*']
187
		elif x not in r:
188
			r.append(x)
189
print '\n'.join([' %s %s ' % (pkg,' '.join(flgs)) for pkg,flgs in h.iteritems() if len(flgs)])"
190
}
191
150
# the following function creates a bash array ACTIVE_FLAGS that contains the
192
# the following function creates a bash array ACTIVE_FLAGS that contains the
151
# global use flags, indexed by origin: 0: environment, 1: make.conf, 
193
# global use flags, indexed by origin: 0: environment, 1: make.conf, 
152
# 2: make.defaults, 3: make.globals
194
# 2: make.defaults, 3: make.globals, 4: package.use, 5: ebuild IUSE
153
get_useflags() {
195
get_useflags() {
154
	# only calculate once as calling emerge is painfully slow
196
	# only calculate once 
155
	[ -n "${USE_FLAGS_CALCULATED}" ] && return
197
	[ -n "${USE_FLAGS_CALCULATED}" ] && return
156
	
198
157
	# backup portdir so get_portdir() doesn't give false results later
199
	# backup portdir so get_portdir() doesn't give false results later
158
	portdir_backup="${PORTDIR}"
200
	portdir_backup="${PORTDIR}"
159
201
Lines 174-183 Link Here
174
	USE="${ACTIVE_FLAGS[0]}"
216
	USE="${ACTIVE_FLAGS[0]}"
175
	PORTDIR="${portdir_backup}"
217
	PORTDIR="${portdir_backup}"
176
218
219
	# Parse through /etc/portage/package.use
220
	if [[ -d ${PACKAGE_USE_PATH} ]]; then
221
		ACTIVE_FLAGS[4]="$( find ${PACKAGE_USE_PATH} -type f -exec cat {} \; \
222
			-exec echo \; | sed -re "s/#.*$//" )"
223
	elif [[ -e ${PACKAGE_USE_PATH} ]]; then
224
		ACTIVE_FLAGS[4]="$( cat ${PACKAGE_USE_PATH} | sed -re "s/#.*$//")"
225
	fi
226
	# Simplify ACTIVE_FLAGS[4] to be lines of pkg {[-]flag}*
227
	ACTIVE_FLAGS[4]="$(reduce_package_use "${ACTIVE_FLAGS[4]}")"
228
	#
229
	# ACTIVE_FLAGS[5] reserved for USE flags defined in ebuilds and
230
	# is generated/maintained in the get_useflaglist_ebuild() function
231
	#
232
233
	USE_FLAGS_CALCULATED=1
234
}
235
236
# Fetch USE flags reported active by Portage
237
get_portageuseflags() {
238
	# only calculate once as calling emerge is painfully slow
239
	[ -n "${_PORTAGE_USE_FLAGS_CALCULATED}" ] && return
177
	# get the currently active USE flags as seen by portage, this has to be after
240
	# get the currently active USE flags as seen by portage, this has to be after
178
	# restoring USE or portage won't see the original environment
241
	# restoring USE or portage won't see the original environment
179
	ACTIVE_FLAGS[9]="$(emerge --info | grep 'USE=' | cut -b 5- | sed -e 's:"::g')" #'
242
	ACTIVE_FLAGS[9]="$(emerge --info | grep 'USE=' | cut -b 5- | sed -e 's:"::g')" #'
180
	USE_FLAGS_CALCULATED=1
243
	_PORTAGE_USE_FLAGS_CALCULATED=1
181
}
244
}
182
245
183
# get the list of all known USE flags by reading use.desc and/or use.local.desc
246
# get the list of all known USE flags by reading use.desc and/or use.local.desc
Lines 194-199 Link Here
194
		egrep "^[^# :]+:[^ ]+ +-" "${descdir}/use.local.desc" | cut -d: -f 2 | cut -d\  -f 1
257
		egrep "^[^# :]+:[^ ]+ +-" "${descdir}/use.local.desc" | cut -d: -f 2 | cut -d\  -f 1
195
	fi
258
	fi
196
}
259
}
260
get_useflaglist_ebuild() {
261
	# $1 package atom (app-editor/vim)
262
	#
263
	local known=$(echo "${ACTIVE_FLAGS[5]}" | egrep ^${1} | sed -e s:^${1}\s::)
264
	if [[ ! -z $known ]]; then
265
		echo $known
266
		return
267
	fi
268
	# Fetch list of package ebuilds matching the query from equery.
269
	# 	Since determining the current version of a package requires
270
	#	scanning for available ones, inpecting the KEYWORDS variable
271
	#	and then checking in a heap of other places for exceptions,
272
	#   equery is a simple alternative
273
	if [[ "$MODE" != "showinstdesc" ]]; then
274
		local exclude_installed="--exclude-installed"
275
	fi
276
	# The last one in the list would be the one to be installed.
277
	local ebuild
278
	for T in $(equery -N list --portage-tree $exclude_installed \
279
			${1} | grep "${1}" | egrep -v "\[M.\]" | \
280
			cut -d\  -f 5 | sed -e s:^[^/]*/::); do
281
		ebuild=${T}
282
	done
283
	# Open the ebuild file and retrieve defined USE flags
284
	if [[ ! -e "$(get_portdir)/${1}/${ebuild}.ebuild" ]]; then
285
		return 1
286
	fi
287
	local flags="$(cat $(get_portdir)/${1}/${ebuild}.ebuild | \
288
		python -c "import re,sys; print re.compile(r'^IUSE=\"[^\"]*\"', re.M)\
289
			.search(sys.stdin.read()).group(0)")"
290
	ACTIVE_FLAGS[5]="$(echo -ne ${ACTIVE_FLAGS[5]}$'\n'${1} ${flags})"
291
	echo ${flags}
292
}
197
293
198
# get all make.defaults by traversing the cascaded profile directories
294
# get all make.defaults by traversing the cascaded profile directories
199
get_all_make_defaults() {
295
get_all_make_defaults() {
Lines 238-266 Link Here
238
# 3: echo value for positive (and as lowercase for negative) test result, 
334
# 3: echo value for positive (and as lowercase for negative) test result, 
239
# 4 (optional): echo value for "missing" test result, defaults to blank
335
# 4 (optional): echo value for "missing" test result, defaults to blank
240
get_flagstatus_helper() {
336
get_flagstatus_helper() {
241
	if echo " ${ACTIVE_FLAGS[${2}]} " | grep " ${1} " > /dev/null; then
337
	if [[ -z ${flags} ]]; then 
242
		echo -n "${3}"
338
		local flags=${ACTIVE_FLAGS[${2}]}
243
	elif echo " ${ACTIVE_FLAGS[${2}]} " | grep " -${1} " > /dev/null; then
339
	fi
244
		echo -n "$(echo ${3} | tr [[:upper:]] [[:lower:]])"
340
	if echo " $flags " | egrep " \+?${1} " > /dev/null; then
341
		echo -e -n "${3}"
342
		return 0
343
	elif echo " $flags " | grep " -${1} " > /dev/null; then
344
		echo -e -n "$(echo ${3} | tr [:upper:]+ [:lower:]-)"
345
		return 0
245
	else
346
	else
246
		echo -n "${4:- }"
347
		echo -n "${4:- }"
348
		return 1
247
	fi
349
	fi
248
}
350
}
351
get_flagstatus_helper_pkg() {
352
	if [[ -z ${flags} ]]; then
353
		local flags=$(echo " ${ACTIVE_FLAGS[${2}]} " | grep "${5} ");
354
	fi;
355
	if [[ -z ${5} || -z ${flags} ]]; then
356
		echo -e -n "${4:- }"
357
		return 1;
358
	fi
359
	get_flagstatus_helper "$@"
360
	return $?
361
}
362
get_flagstatus_helper_ebuild() {
363
	if [[ -z ${5} ]]; then 
364
		echo -e -n "${4:- }" 
365
		return 1 
366
	fi
367
	local flags=$( get_useflaglist_ebuild "${5}" )
368
	get_flagstatus_helper_pkg "$@"
369
	return $?
370
}
249
371
250
# prints a status string for the given flag, each column indicating the presence
372
# prints a status string for the given flag, each column indicating the presence
251
# for portage, in the environment, in make.conf, in make.defaults and in make.globals.
373
# for portage, in the environment, in make.conf, in make.defaults and in make.globals.
252
# full positive value would be "[+ECDG]", full negative value would be [-ecdg],
374
# full positive value would be "[+ECDGPB]", full negative value would be [-ecdgpb],
253
# full missing value would be "[-    ]" (portage only sees present or not present)
375
# full missing value would be "[-      ]" (portage only sees present or not present)
254
get_flagstatus() {
376
get_flagstatus() {
255
	get_useflags
377
	get_useflags
378
	[[ ! -z ${2} ]] && get_useflaglist_ebuild "${2}" > /dev/null
256
379
257
	echo -n '['
380
	local E=$(get_flagstatus_helper "${1}" 0 "E")
258
	get_flagstatus_helper "${1}" 9 "+" "-"
381
	local C=$(get_flagstatus_helper "${1}" 1 "C")
259
	get_flagstatus_helper "${1}" 0 "E"
382
	local D=$(get_flagstatus_helper "${1}" 2 "D")
260
	get_flagstatus_helper "${1}" 1 "C"
383
	local G=$(get_flagstatus_helper "${1}" 3 "G")
261
	get_flagstatus_helper "${1}" 2 "D"
384
	local P=$(get_flagstatus_helper_pkg "${1}" 4 "P" "" "${2}")
262
	get_flagstatus_helper "${1}" 3 "G"
385
	local B=$(get_flagstatus_helper_ebuild "${1}" 4 "B" "" "${2}")
263
	echo -n '] '
386
	#
387
	# Use flag precedence is defined (at least) at:
388
	# http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&chap=2
389
	for location in "E" "P" "C" "D" "G" "B"; do
390
		if [[ ${!location} == $location ]]; then
391
			local ACTIVE="+"
392
			break
393
		elif [[ ${!location} != " " ]]; then 
394
			local ACTIVE="-"
395
			break
396
		fi
397
	done
398
	echo -n "[${ACTIVE:--}$E$C$D$G$P$B] "
264
}
399
}
265
400
266
# faster replacement to `portageq portdir`
401
# faster replacement to `portageq portdir`
Lines 327-333 Link Here
327
					pkg="$(echo $line | cut -d\| -f 1)"
462
					pkg="$(echo $line | cut -d\| -f 1)"
328
					flag="$(echo $line | cut -d\| -f 2)"
463
					flag="$(echo $line | cut -d\| -f 2)"
329
					desc="$(echo $line | cut -d\| -f 3)"
464
					desc="$(echo $line | cut -d\| -f 3)"
330
					get_flagstatus "${flag}"
465
					get_flagstatus "${flag}" "${pkg}"
331
					printf "%s (%s):\n%s\n\n" "${flag}" "${pkg}" "${desc}"
466
					printf "%s (%s):\n%s\n\n" "${flag}" "${pkg}" "${desc}"
332
				done
467
				done
333
		fi
468
		fi
Lines 351-358 Link Here
351
	args=("${@:-*}")
486
	args=("${@:-*}")
352
487
353
	case "${SCOPE}" in
488
	case "${SCOPE}" in
354
		"global") echo "global use flags (searching: ${args})";;
489
		"global") echo "global use flags (searching: ${args[@]})";;
355
		 "local") echo "local use flags (searching: ${args})";;
490
		 "local") echo "local use flags (searching: ${args[@]})";;
356
		       *) SCOPE="global" showinstdesc "${args[@]}"
491
		       *) SCOPE="global" showinstdesc "${args[@]}"
357
		          echo
492
		          echo
358
		          SCOPE="local" showinstdesc "${args[@]}"
493
		          SCOPE="local" showinstdesc "${args[@]}"
Lines 366-372 Link Here
366
		args="$(get_useflaglist | sort -u)"
501
		args="$(get_useflaglist | sort -u)"
367
	fi
502
	fi
368
	
503
	
369
	set "${args[@]}"
504
	set ${args[@]}
370
	
505
	
371
	while [ -n "${1}" ]; do
506
	while [ -n "${1}" ]; do
372
		case "${SCOPE}" in
507
		case "${SCOPE}" in
Lines 394-403 Link Here
394
					# print name only if package is installed
529
					# print name only if package is installed
395
					# NOTE: If we implement bug #114086 's enhancement we can just use the
530
					# NOTE: If we implement bug #114086 's enhancement we can just use the
396
					#       exit status of equery instead of a subshell and pipe to wc -l
531
					#       exit status of equery instead of a subshell and pipe to wc -l
397
					if [ $(equery -q -C list -i -e "${pkg}" | wc -l) -gt 0 ]; then
532
					if [ $(equery -q -C list -i "${pkg}" | wc -l) -gt 0 ]; then
398
						foundone=1
533
						foundone=1
399
						IFS="$OIFS"
534
						IFS="$OIFS"
400
						get_flagstatus "${flag}"
535
						get_flagstatus "${flag}" "${pkg}"
401
						IFS=': '
536
						IFS=': '
402
						printf "%s (%s):\n%s\n\n" "${flag}" "${pkg}" "${desc#- }"
537
						printf "%s (%s):\n%s\n\n" "${flag}" "${pkg}" "${desc#- }"
403
					fi
538
					fi
Lines 428-438 Link Here
428
	set ${args}
563
	set ${args}
429
	
564
	
430
	while [ -n "${1}" ]; do
565
	while [ -n "${1}" ]; do
566
		get_portageuseflags
431
		if echo " ${ACTIVE_FLAGS[9]} " | grep " ${1} " > /dev/null; then
567
		if echo " ${ACTIVE_FLAGS[9]} " | grep " ${1} " > /dev/null; then
432
			printf "%-20s" ${1}
568
			printf "%-20s" ${1}
433
			get_flagstatus ${1}
569
			get_flagstatus ${1}
434
			echo
570
			echo
435
		fi
571
		fi
572
		if echo " ${ACTIVE_FLAGS[4]} " | egrep -e " -?${1} " > /dev/null; then
573
			for pkg in $( echo "${ACTIVE_FLAGS[4]}" | \
574
					egrep " -?${1} " | cut -d " " -f 2); do
575
				printf "%-20s" ${1}
576
				SCOPE="local" get_flagstatus ${1} "${pkg}"
577
				printf "(%s)\n" ${pkg}
578
			done;
579
		fi
436
		shift
580
		shift
437
	done
581
	done
438
}
582
}
Lines 446-454 Link Here
446
	NEW_MAKE_CONF_USE="${NEW_MAKE_CONF_USE// ${1} / }"
590
	NEW_MAKE_CONF_USE="${NEW_MAKE_CONF_USE// ${1} / }"
447
}
591
}
448
592
593
# Simple utility to remove empty files from package.use
594
clean_package_use() {
595
if [[ -d ${PACKAGE_USE_PATH} ]]; then
596
	for f in $(find ${PACKAGE_USE_PATH} -size 0); do
597
		echo "Removing empty file ""${f}"""
598
		rm ${f}
599
	done;
600
fi
601
}
602
603
# Utility to remove a use flag from a file in package.use[/]
604
# Args: (1) File, (2) Use flag
605
scrub_use_flag() {
606
	local atom_re="^[<>]?=?([a-z][\da-z/-]+[a-z])(-[0-9pr._*-]+)?"
607
	local filename=${1}
608
	# Ignore leading - on flag
609
	local flag=${2#*-}
610
	local pkg=$(echo "${PACKAGE}" | sed -re "s/${atom_re}/\1/")
611
	local pkg_re="[<>]?=?${pkg}(-[\dpr._*-]+)?"
612
613
	while read line; do
614
		# Skip (preserve) comments on their own lines
615
		if [[ -z $(echo "${line}" | sed -re "s/^ *#.*$//") ]]; then
616
			echo "${line}"
617
		# Detect if requested package is defined on this line
618
		elif [[ -n ${PACKAGE} ]]; then
619
			if [[ -n $(echo ${line} | egrep -E "[^#]*${pkg_re}") ]]; then	
620
				# If this is the only (remaining) use flag defined
621
                # for this package, then remove the whole line
622
                if [[ -z $(echo ${line} | \
623
						egrep -E "[^#]*${pkg_re}\s*-?${flag}\s*$") ]]; then
624
					# Remove flag from this line
625
					echo "${line}" | sed -re "s/-?\b${flag}\b//"
626
				fi
627
			else
628
				# Passthru
629
				echo "${line}"
630
			fi
631
		# If line only has this use flag, let it be removed 
632
		# (used if PACKAGE is not defined -- from pruning)
633
		elif [[ -z $(echo ${line} | \
634
				grep -re "[^#]*${atom_re}.*-?${flag}") ]]; then
635
			# Remove flag from this line
636
			echo "${line}" | sed -re "s/-?\b${flag}\b//"
637
		else
638
			# Passthru
639
			echo "${line}"
640
		fi;
641
	done < <(cat "${filename}") > "${filename}";
642
}
643
644
modify_package() {
645
	get_useflags
646
647
	local atom_re="^[<>]?=?([a-z][\da-z/-]+[a-z])(-[0-9pr._*-]+)?"
648
	local pkg=$(echo "${PACKAGE}" | sed -re "s/${atom_re}/\1/")
649
	local pkg_re="[<>]?=?${pkg}(-[\dpr._*-]+)?"
650
651
	while [[ -n ${1} ]]; do
652
	local flag=${1}
653
	#
654
	# --- Sanity checks
655
	# (1) make sure ${pkg} exists in portdir
656
	if [[ ! -d "$(get_portdir)/${pkg}" ]]; then
657
		error "Package ""${pkg}"" does not exist"
658
	#
659
	# (2) make sure ${flag} is defined in get_useflaglist
660
	elif [[ ! -n $(echo " $(get_useflaglist) " | grep "${flag}") ]]; then
661
		warn "USE flag ""${flag}"" does not exist"
662
		# Don't bail just because of this, just warn
663
	fi;
664
	# If flag is enabled in portage USE flags (emerge --info), 
665
	# then "remove"ing the flag should be replaced with adding
666
	# the negative flag instead
667
	if [[ "${ACTION}" == "remove" && \
668
			$( get_flagstatus ${flag} ${pkg} | grep "+" ) ]]; then
669
		flag="-${flag}"
670
		ACTION="add"
671
	# If flag is currently disabled for the package requested 
672
	# to be enabled in, then "remove" the negative
673
	elif [[ "${ACTION}" == "add" &&
674
			-n $( echo " ${ACTIVE_FLAGS[4]} " | egrep -e " ${PACKAGE}.*-${flag}\b" ) ]]; then
675
		flag="-${flag}"
676
		ACTION="remove"
677
	fi;
678
	case "${ACTION}" in
679
		"add")
680
			local filename
681
			if [[ -d ${PACKAGE_USE_PATH} ]]; then
682
				# Use naming convention of package.use/package
683
				filename="${PACKAGE_USE_PATH}/${pkg#*/}"
684
				if [[ ! -s "${filename}" ]]; then
685
					# Create new file to contain flag
686
					echo "${PACKAGE} ${flag}" > "${filename}"
687
					echo "Adding ""${PACKAGE}:${flag}"" use flag to new file ""${filename}"""
688
					return
689
				fi;
690
			else	
691
				# Add to package.use file instead
692
				filename=${PACKAGE_USE_PATH}
693
				# Create as necessary
694
				touch "${filename}"
695
			fi;
696
			# Walk through the file and add the flag manually
697
			echo "Adding ""${PACKAGE}:${flag}"" use flag in ""${filename}"""
698
            local added=0
699
			while read line; do
700
				if [[ -n $(echo "${line}" | egrep -e "^[^#]*${pkg_re}") ]]; then
701
					echo "$(reduce_package_use "${line} ${flag}" | cut -d " " -f 2-)"
702
					added=1
703
				else
704
					# Passthru
705
					echo "${line}"
706
				fi;
707
			done < <(cat "${filename}") > ${filename}
708
			if [[ ${added} == 0 ]]; then
709
				echo "${PACKAGE} ${flag}" >> "${filename}"
710
			fi
711
			;;
712
		"remove")
713
			local filename
714
			if [[ -d ${PACKAGE_USE_PATH} ]]; then
715
				# Scan for file containing named package and use flag
716
				filename=$( egrep -rle "${pkg_re}.*[^-]${flag}( |$)" "${PACKAGE_USE_PATH}")
717
				if [[ -z "${filename}" ]]; then
718
					error ""${flag}" is not defined for package "${PACKAGE}""
719
					return
720
				fi;
721
			else
722
				# Remove from package.use instead
723
				filename=${PACKAGE_USE_PATH}
724
				# Create as necessary
725
				touch "${filename}"
726
			fi;
727
			# Scrub use flag from matched files
728
			for f in ${filename}; do
729
				# Remove current flags in file
730
				echo "Removing ""${PACKAGE}:${flag}"" use flag in ""${f}"""
731
				scrub_use_flag ${f} ${flag}
732
			done;
733
			# Remove empty files
734
			clean_package_use
735
			;;
736
	esac;
737
	shift;
738
	done;
739
}
740
449
# USE flag modification function. Mainly a loop with calls to add_flag and 
741
# USE flag modification function. Mainly a loop with calls to add_flag and 
450
# remove_flag to create a new USE string which is then inserted into make.conf.
742
# remove_flag to create a new USE string which is then inserted into make.conf.
451
modify() {
743
modify() {
744
	if [[ -n ${PACKAGE} ]]; then
745
		modify_package ${*}
746
		return;
747
	fi;
748
452
	if [ -z "${*}" ]; then
749
	if [ -z "${*}" ]; then
453
		if [ "${ACTION}" != "prune" ]; then
750
		if [ "${ACTION}" != "prune" ]; then
454
			echo "WARNING: no USE flags listed for modification, do you really"
751
			echo "WARNING: no USE flags listed for modification, do you really"
Lines 488-493 Link Here
488
			elif echo " ${NEW_MAKE_CONF_USE} " | grep " -${1} " > /dev/null; then
785
			elif echo " ${NEW_MAKE_CONF_USE} " | grep " -${1} " > /dev/null; then
489
				remove_flag "-${1}"
786
				remove_flag "-${1}"
490
			fi
787
			fi
788
			# Locate use flag in package.use
789
			local filename
790
			if [[ -d ${PACKAGE_USE_PATH} ]]; then
791
				filename=$( egrep -rle "-?\b${1}\b" "${PACKAGE_USE_PATH}")
792
			else
793
				# Scrub from package.use file
794
				filename=${PACKAGE_USE_PATH}
795
			fi
796
			# Scrub use flag from matched files
797
			for f in ${filename}; do
798
				# Remove current flags in file
799
				echo "Disabling ""${1}"" use flag in ""${f}"""
800
				scrub_use_flag ${f} ${1} 
801
			done;
802
			# Remove empty files from package.use
803
			clean_package_use
491
			shift
804
			shift
492
		fi
805
		fi
493
	done
806
	done

Return to bug 259318