Hi everyone.
A few weeks ago I suggested removing definitions which were duplicated
between python and shell files. One organized way of doing this is to
put definitions into a Python file and have shell scripts run python in
a commandline mode to extract them. Python files, of course, can just
import the definitions. I prototyped this as follows:
--- usr/src/lib/install_common/common_defs.ksh --------------
# Can be added to installadm-common.sh
#!/bin/ksh
# getdef: Get a definition from a python file.
#
# Args:
# definition name
# Returns:
# definition value
#
function getdef
{
in_arg="import common_defs as defs; print defs.${1}"
out_arg=$(/usr/bin/python -c "$in_arg" 2>/dev/null)
if [[ $? -ne 0 ]]; then
return 1
fi
print $out_arg
return 0
}
--- usr/src/lib/install_common/common_defs.py -------------
#!/bin/python2.6
# File full of definitions to share...
LOGFILE="/system/volatile/install_log"
MANIFEST="/system/volatile/manifest.xml"
--- begin shell.ksh -----------------------------------------
#!/bin/ksh
# A shell script that needs a shared (Python) definition.
. commondefs.ksh
LOGFILE=`getdef "LOGFILE"`
if [[ $? -ne 0 ]] ; then
echo "Error getting LOGFILE definition"
else
echo "Logfile is $LOGFILE"
fi
-------------------------------------------------------------
Does this sound like something worthwhile? If so, I'll take the
initiative to ferret out duplicates and implement the above.
Are there suggestions to improve implementation? Please let me know.
A few caveats: I suggest excluding error messages from these common
defs, as if they are not accessible, a misleading error message could be
displayed instead of the real cause.
I didn't consider C since we are getting away from using it. I can look
into a joint python/shell/C effort if needed.
Thanks,
Jack
_______________________________________________
caiman-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/caiman-discuss