Hi Jack,
Having to invoke Python everytime I want to read a variable in the shell
script sounds very
"heavy weight" to me, especially when we want to use a lot of variables
in the shell script.
What about the following solution?
1) Define the values in Python
2) Create a Makefile target to extract all the predefined values
from the python file and put them into into a file that can be included
by shell scripts
that need to use those values.
3) Deliver both the Python definition file, and this generated file in a
package.
This way, we can still have values defined in 1 central location,
but we don't need to invoke Python multiple times from a shell script.
Thanks,
--Karen
On 05/16/11 13:45, Jack Schwartz wrote:
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
_______________________________________________
caiman-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/caiman-discuss