From 5f01cc70d3a65a4d904a2040343ca5bfdfbaaff3 Mon Sep 17 00:00:00 2001 From: aszlig Date: Mon, 28 Jul 2014 04:18:21 +0200 Subject: [PATCH] python-wrapper: Fix fixup for wrapped argv[0]. Fixes issues introduced by 24ef871e6a1c858af3f9984a5b526c83b24520ed. The problem here is that "import sys; sys.argv[0] = ..." is just appended after the first "#!", which in turn breaks things such as encoding specifications. A second problem - although not very common - is when there's another #! within the script. This should take care of both cases. Signed-off-by: aszlig --- pkgs/development/python-modules/generic/wrap.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/development/python-modules/generic/wrap.sh b/pkgs/development/python-modules/generic/wrap.sh index dda9f4877f6..f81adf0bae9 100644 --- a/pkgs/development/python-modules/generic/wrap.sh +++ b/pkgs/development/python-modules/generic/wrap.sh @@ -26,7 +26,9 @@ wrapPythonProgramsIn() { # dont wrap EGG-INFO scripts since they are called from python if echo "$i" | grep -v EGG-INFO/scripts; then echo "wrapping \`$i'..." - sed -i "$i" -e "/^#\!/a import sys; sys.argv[0] = '$(basename $i)'" + sed -i "$i" -e '1,/#!/ { /^#\!/,/^[^#]/ { + /^[^#]/i import sys; sys.argv[0] = '"'$(basename "$i")'"' + }}' wrapProgram "$i" \ --prefix PYTHONPATH ":" $program_PYTHONPATH \ --prefix PATH ":" $program_PATH