Commit e42a7dcf authored by Xavier Thompson's avatar Xavier Thompson

slapgrid: Fix instance python executable inspection

The path of the instance's python executable is inferred from the
shebang of ~/software_release/bin/buildout.

But when the path is too long, buildout generates a workaround
shebang using /bin/sh to exec the actual python executable.
parent 7e61728e
...@@ -33,6 +33,7 @@ import hashlib ...@@ -33,6 +33,7 @@ import hashlib
import os import os
import pkg_resources import pkg_resources
import pwd import pwd
import shlex
import stat import stat
import sys import sys
import threading import threading
...@@ -177,10 +178,18 @@ def getPythonExecutableFromSoftwarePath(software_path): ...@@ -177,10 +178,18 @@ def getPythonExecutableFromSoftwarePath(software_path):
try: try:
with open(os.path.join(software_path, 'bin', 'buildout')) as f: with open(os.path.join(software_path, 'bin', 'buildout')) as f:
shebang = f.readline() shebang = f.readline()
line = f.readline()
except (IOError, OSError): except (IOError, OSError):
return return
if shebang.startswith('#!'): if shebang.startswith('#!'):
return shebang[2:].split(None, 1)[0] executable = shebang[2:].split(None, 1)[0]
if executable.startswith('/bin/sh'):
# workaround for workaround for shebang length limitation:
# https://lab.nexedi.com/nexedi/slapos.buildout/blob/00d423bd76aa53a02aeaa7c593138b7396ffee1a/src/zc/buildout/easy_install.py#L172
args = shlex.split(line)
if len(args) >= 2 and args[0] == 'exec':
return args[1]
return executable
def getCleanEnvironment(logger, home_path='/tmp'): def getCleanEnvironment(logger, home_path='/tmp'):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment