Skip to content
Snippets Groups Projects

Detect pythonw scripts

Merged Paul McCarthy requested to merge rf/pythonw into master
3 files
+ 54
15
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -85,27 +85,29 @@ for script in $targets; do
# Figure out whether this is a python
# executable or some other type of
# executable. We search for these strings
# in source file headers to ID them as
# python scripts. We need to check both
# match "#!/usr/bin/env python" and
# "#!<fsldir>/bin/python...", because
# conda might generate one or the other
# in different scenarios.
id1=$(head -c 1024 "$sourceScript" | grep "#!/usr/bin/env python")
id2=$(head -c 1024 "$sourceScript" | grep "#!${FSLDIR%/}/bin/python")
# executable.
id=$(head -c 1024 "$sourceScript" | grep -e '^#!.*pythonw\?$')
# Non-python executable - use a
# pass-through script
if [ -z "$id1" ] && [ -z "$id2" ]; then
# Non-python executable - use
# a pass-through script
if [ -z "$id" ]; then
echo "#!/usr/bin/env bash" > "$targetScript"
echo "$FSLDIR/bin/$script "'"$@"' >> "$targetScript"
else
# Python executable - run it via
# $FSLDIR/bin/python in isolated mode
echo "#!/usr/bin/env bash" > "$targetScript"
echo "$FSLDIR/bin/python -I $sourceScript "'"$@"' >> "$targetScript"
# $FSLDIR/bin/python[w] in isolated
# mode. Under macOS, GUI apps are
# invoked with pythonw, so we need
# to preserve the interpreter.
if [[ "$id" == *"pythonw" ]]; then
interp="pythonw"
else
interp="python"
fi
echo "#!/usr/bin/env bash" > "$targetScript"
echo "${FSLDIR}/bin/${interp} -I $sourceScript "'"$@"' >> "$targetScript"
fi
# Preserve file permissions
Loading