Handle more prefix/suffix cases in createmodule.{sh,py} (bug #1079341)
This commit is contained in:
parent
bdf13c6db7
commit
d0c9d44f87
@ -79,6 +79,7 @@ env2=getenv(". " + " ".join(args))
|
|||||||
chdir = None
|
chdir = None
|
||||||
appendpath = {}
|
appendpath = {}
|
||||||
prependpath = {}
|
prependpath = {}
|
||||||
|
unhandled = {}
|
||||||
setenv = {}
|
setenv = {}
|
||||||
unsetenv = []
|
unsetenv = []
|
||||||
pathnames = []
|
pathnames = []
|
||||||
@ -88,7 +89,7 @@ def normpaths(paths):
|
|||||||
newpaths = []
|
newpaths = []
|
||||||
for path in paths:
|
for path in paths:
|
||||||
normpath = os.path.normpath(path)
|
normpath = os.path.normpath(path)
|
||||||
if normpath not in newpaths:
|
if normpath not in newpaths and normpath != '.':
|
||||||
newpaths.append(os.path.normpath(path))
|
newpaths.append(os.path.normpath(path))
|
||||||
return newpaths
|
return newpaths
|
||||||
|
|
||||||
@ -109,19 +110,36 @@ for key in env1.keys():
|
|||||||
del env2[key]
|
del env2[key]
|
||||||
continue
|
continue
|
||||||
# Determine modifcations to beginning and end of the string
|
# Determine modifcations to beginning and end of the string
|
||||||
(prepend,append) = env2[key].split(env1[key])
|
try:
|
||||||
|
(prepend,append) = env2[key].split(env1[key])
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
if prepend:
|
if prepend:
|
||||||
prependpaths = prepend.strip(':').split(':')
|
presep = prepend[-1:]
|
||||||
|
prependpaths = prepend.strip(presep).split(presep)
|
||||||
# LICENSE variables often include paths outside install directory
|
# LICENSE variables often include paths outside install directory
|
||||||
if 'LICENSE' not in key:
|
if 'LICENSE' not in key:
|
||||||
pathnames += prependpaths
|
pathnames += prependpaths
|
||||||
prependpath[key] = ':'.join(normpaths(prependpaths))
|
if presep not in prependpath:
|
||||||
|
prependpath[presep] = {}
|
||||||
|
newpath = presep.join(normpaths(prependpaths))
|
||||||
|
if newpath:
|
||||||
|
prependpath[presep][key] = newpath
|
||||||
|
else:
|
||||||
|
unhandled[key] = env2[key]
|
||||||
if append:
|
if append:
|
||||||
appendpaths = append.strip(':').split(':')
|
appsep = append[0:1]
|
||||||
|
appendpaths = append.strip(appsep).split(appsep)
|
||||||
# LICENSE variables often include paths outside install directory
|
# LICENSE variables often include paths outside install directory
|
||||||
if 'LICENSE' not in key:
|
if 'LICENSE' not in key:
|
||||||
pathnames += appendpaths
|
pathnames += appendpaths
|
||||||
appendpath[key] = ':'.join(normpaths(appendpaths))
|
if appsep not in appendpath:
|
||||||
|
appendpath[appsep] = {}
|
||||||
|
newpath = appsep.join(normpaths(appendpaths))
|
||||||
|
if newpath:
|
||||||
|
appendpath[appsep][key] = newpath
|
||||||
|
else:
|
||||||
|
unhandled[key] = env2[key]
|
||||||
del env2[key]
|
del env2[key]
|
||||||
|
|
||||||
# We're left with new keys in env2
|
# We're left with new keys in env2
|
||||||
@ -133,13 +151,25 @@ for key in env2.keys():
|
|||||||
# LICENSE variables often include paths outside install directory
|
# LICENSE variables often include paths outside install directory
|
||||||
if key != 'MANPATH' and 'LICENSE' not in key:
|
if key != 'MANPATH' and 'LICENSE' not in key:
|
||||||
pathnames += prependpaths
|
pathnames += prependpaths
|
||||||
prependpath[key] = ':'.join(normpaths(prependpaths))
|
if ':' not in prependpath:
|
||||||
|
prependpath[':'] = {}
|
||||||
|
prependpath[':'][key] = ':'.join(normpaths(prependpaths))
|
||||||
continue
|
continue
|
||||||
# Set new variables
|
# Set new variables
|
||||||
setenv[key] = os.path.normpath(env2[key])
|
setenv[key] = os.path.normpath(env2[key])
|
||||||
if 'LICENSE' not in key:
|
if 'LICENSE' not in key:
|
||||||
pathnames.append(setenv[key])
|
pathnames.append(setenv[key])
|
||||||
|
|
||||||
|
# Report unhandled keys
|
||||||
|
for key in unhandled.keys():
|
||||||
|
print("Unhandled change of", key, file=sys.stderr)
|
||||||
|
print("Before <%s>" % env1[key], file=sys.stderr)
|
||||||
|
print("After <%s>" % unhandled[key], file=sys.stderr)
|
||||||
|
for sepkey in appendpath.keys():
|
||||||
|
appendpath[sepkey].pop(key, None)
|
||||||
|
for sepkey in prependpath.keys():
|
||||||
|
prependpath[sepkey].pop(key, None)
|
||||||
|
|
||||||
# Determine a prefix
|
# Determine a prefix
|
||||||
prefix=None
|
prefix=None
|
||||||
if options.prefix:
|
if options.prefix:
|
||||||
@ -173,13 +203,23 @@ def formatline(item, key, value=None):
|
|||||||
print(value)
|
print(value)
|
||||||
|
|
||||||
# Paths first, grouped by variable name
|
# Paths first, grouped by variable name
|
||||||
pathkeys = list(appendpath.keys()) + list(prependpath.keys())
|
for sepkey in prependpath.keys():
|
||||||
pathkeys.sort()
|
pathkeys = prependpath[sepkey].keys()
|
||||||
for key in pathkeys:
|
pathkeys.sort()
|
||||||
if key in prependpath:
|
for key in pathkeys:
|
||||||
formatline("prepend-path",key,prependpath[key])
|
if sepkey == ":":
|
||||||
if key in appendpath:
|
formatline("prepend-path",key,prependpath[sepkey][key])
|
||||||
formatline("append-path",key,appendpath[key])
|
else:
|
||||||
|
formatline("prepend-path --delim %s" % sepkey,key,prependpath[sepkey][key])
|
||||||
|
|
||||||
|
for sepkey in appendpath.keys():
|
||||||
|
pathkeys = appendpath[sepkey].keys()
|
||||||
|
pathkeys.sort()
|
||||||
|
for key in pathkeys:
|
||||||
|
if sepkey == ":":
|
||||||
|
formatline("append-path",key,appendpath[sepkey][key])
|
||||||
|
else:
|
||||||
|
formatline("append-path --delim %s" % sepkey,key,appendpath[sepkey][key])
|
||||||
|
|
||||||
# Setenv
|
# Setenv
|
||||||
setenvkeys = list(setenv.keys())
|
setenvkeys = list(setenv.keys())
|
||||||
|
@ -74,11 +74,13 @@ echo "#%Module 1.0"
|
|||||||
#Prefix
|
#Prefix
|
||||||
[ -n "$prefix" ] && echo -e "\nset prefix $prefix\n"
|
[ -n "$prefix" ] && echo -e "\nset prefix $prefix\n"
|
||||||
|
|
||||||
|
# dedup - remove duplicate entries from a list
|
||||||
#Subshell so we can sort the output
|
#Subshell so we can sort the output
|
||||||
(
|
(
|
||||||
dedup() {
|
dedup() {
|
||||||
list=`mktemp`
|
list=`mktemp`
|
||||||
echo $1 | sed -r -e 's,[^/]+/\.\./,,g' -e 's,[^/]+/\.\./,,g' -e 's/:/\n/g' |
|
[ -n "$2" ] && sep=$2 || sep=:
|
||||||
|
echo $1 | sed -r -e 's,[^/]+/\.\./,,g' -e 's,[^/]+/\.\./,,g' -e "s/\\$sep/\n/g" |
|
||||||
while read x
|
while read x
|
||||||
do
|
do
|
||||||
grep -Fx ${x} $list && continue
|
grep -Fx ${x} $list && continue
|
||||||
@ -89,7 +91,7 @@ dedup() {
|
|||||||
echo $x
|
echo $x
|
||||||
fi
|
fi
|
||||||
echo $x >> $list
|
echo $x >> $list
|
||||||
done | tr '\n' : | sed -e 's/:$//'
|
done | tr '\n' $sep | sed -e "s/\\$sep\$//"
|
||||||
rm $list
|
rm $list
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,25 +116,61 @@ do
|
|||||||
#Test for prepend
|
#Test for prepend
|
||||||
elif [ "${env2[$key]%${env1[$key]}}" != "${env2[$key]}" ]
|
elif [ "${env2[$key]%${env1[$key]}}" != "${env2[$key]}" ]
|
||||||
then
|
then
|
||||||
added=$(dedup ${env2[$key]%:${env1[$key]}})
|
added=${env2[$key]%${env1[$key]}}
|
||||||
echo -e "prepend-path\t$key\t${added}"
|
sep=${added: -1}
|
||||||
|
added=${added%$sep}
|
||||||
|
added=$(dedup $added $sep)
|
||||||
|
if [ $sep = : ]
|
||||||
|
then
|
||||||
|
echo -e "prepend-path\t$key\t${added}"
|
||||||
|
else
|
||||||
|
echo -e "prepend-path\t--delim $sep\t$key\t${added}"
|
||||||
|
fi
|
||||||
#Test for prepend plus : added at end (MANPATH)
|
#Test for prepend plus : added at end (MANPATH)
|
||||||
elif [ "${env2[$key]%${env1[$key]}:}" != "${env2[$key]}" ]
|
elif [ "${key: -4}" = PATH -a "${env2[$key]%${env1[$key]}:}" != "${env2[$key]}" ]
|
||||||
then
|
then
|
||||||
added=$(dedup ${env2[$key]%${env1[$key]}:})
|
added=$(dedup ${env2[$key]%${env1[$key]}:})
|
||||||
echo -e "prepend-path\t$key\t${added}"
|
echo -e "prepend-path\t$key\t${added}"
|
||||||
#Test for append
|
#Test for append
|
||||||
elif [ "${env2[$key]#${env1[$key]}}" != "${env2[$key]}" ]
|
elif [ "${env2[$key]#${env1[$key]}}" != "${env2[$key]}" ]
|
||||||
then
|
then
|
||||||
added=$(dedup ${env2[$key]#:${env1[$key]}})
|
added=${env2[$key]#${env1[$key]}}
|
||||||
echo -e "append-path\t$key\t${added}"
|
sep=${added:0:1}
|
||||||
|
added=${added#$sep}
|
||||||
|
added=$(dedup $added $sep)
|
||||||
|
if [ $sep = : ]
|
||||||
|
then
|
||||||
|
echo -e "append-path\t$key\t${added}"
|
||||||
|
else
|
||||||
|
echo -e "append-path\t--delim $sep\t$key\t${added}"
|
||||||
|
fi
|
||||||
#Test for prepend plus append
|
#Test for prepend plus append
|
||||||
elif [ "${env2[$key]%${env1[$key]}:*}" != "${env2[$key]}" ]
|
elif [ "${env2[$key]%${env1[$key]}*}" != "${env2[$key]}" ]
|
||||||
then
|
then
|
||||||
added=$(dedup ${env2[$key]%:${env1[$key]}*})
|
prepended=${env2[$key]%${env1[$key]}*}
|
||||||
echo -e "prepend-path\t$key\t${added}"
|
presep=${prepended: -1}
|
||||||
added=$(dedup ${env2[$key]#*${env1[$key]}:})
|
prepended=${prepended%$presep}
|
||||||
echo -e "append-path\t$key\t${added}"
|
prepended=$(dedup $prepended $presep)
|
||||||
|
appended=${env2[$key]#*${env1[$key]}}
|
||||||
|
appsep=${appended:0:1}
|
||||||
|
appended=${appended#$appsep}
|
||||||
|
appended=$(dedup $appended $appsep)
|
||||||
|
if [ $presep != $appsep -o -z "$prepended" -o -z "$appended" ]
|
||||||
|
then
|
||||||
|
#Unhandled
|
||||||
|
echo "Unhandled change of $key" 1>&2
|
||||||
|
echo "Before <${env1[$key]}>" 1>&2
|
||||||
|
echo "After <${env2[$key]}>" 1>&2
|
||||||
|
else
|
||||||
|
if [ $presep = : ]
|
||||||
|
then
|
||||||
|
echo -e "prepend-path\t$key\t${prepended}"
|
||||||
|
echo -e "append-path\t$key\t${appended}"
|
||||||
|
else
|
||||||
|
echo -e "prepend-path\t--delim $presep\t$key\t${prepended}"
|
||||||
|
echo -e "append-path\t--delim $appsep\t$key\t${appended}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
#Unhandled
|
#Unhandled
|
||||||
echo "Unhandled change of $key" 1>&2
|
echo "Unhandled change of $key" 1>&2
|
||||||
@ -140,7 +178,7 @@ do
|
|||||||
echo "After <${env2[$key]}>" 1>&2
|
echo "After <${env2[$key]}>" 1>&2
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
#Delete keys we've handled
|
#Delete keys we have handled
|
||||||
unset env1[$key]
|
unset env1[$key]
|
||||||
unset env2[$key]
|
unset env2[$key]
|
||||||
done
|
done
|
||||||
|
@ -142,6 +142,7 @@ fi
|
|||||||
%changelog
|
%changelog
|
||||||
* Mon Mar 2 2015 Orion Poplwski <orion@cora.nwra.com> - 3.2.10-14
|
* Mon Mar 2 2015 Orion Poplwski <orion@cora.nwra.com> - 3.2.10-14
|
||||||
- Fix createmodule.sh to handle exported functions (bug #1197321)
|
- Fix createmodule.sh to handle exported functions (bug #1197321)
|
||||||
|
- Handle more prefix/suffix cases in createmodule.{sh,py} (bug #1079341)
|
||||||
|
|
||||||
* Wed Jan 28 2015 Orion Poplwski <orion@cora.nwra.com> - 3.2.10-13
|
* Wed Jan 28 2015 Orion Poplwski <orion@cora.nwra.com> - 3.2.10-13
|
||||||
- Add patch for python 3 support, use python3 for createmodule.py on F22
|
- Add patch for python 3 support, use python3 for createmodule.py on F22
|
||||||
|
8
testscript.sh
Normal file
8
testscript.sh
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#!bin/bash
|
||||||
|
export TESTVAR2=origvalue/suffix
|
||||||
|
export TESTVAR3=prefix/origvalue
|
||||||
|
export TESTVAR4=prefix:origvalue:suffix
|
||||||
|
export TESTVAR5=prefix/origvalue/suffix
|
||||||
|
### The following is not so crucial, but still:
|
||||||
|
export TESTVAR8=prefix/origvalue:
|
||||||
|
export TESTVAR9=prefix:origvalue:
|
Loading…
Reference in New Issue
Block a user