when executing. Avoids the problem of different Python versions, or distros
that do not use ``python`` but do ``python3``
"""
- out, err, code = check(conn, ['which', 'python'])
- error_msg = 'Unable to determine python executable, will use "%s"' % conn.interpreter
- if code:
- conn.logger.warning(error_msg)
- return conn.interpreter
- else:
- try:
- return out[0].strip()
- except IndexError:
- conn.logger.warning(error_msg)
- return conn.interpreter
+ # executables in order of preference:
+ executables = ['python3', 'python', 'python2.7']
+ for executable in executables:
+ conn.logger.debug('trying to determine remote python executable with %s' % executable)
+ out, err, code = check(conn, ['which', executable])
+ if code:
+ conn.logger.warning('skipping %s, was not found in path' % executable)
+ else:
+ try:
+ return out[0].strip()
+ except IndexError:
+ conn.logger.warning('could not parse stdout: %s' % out)
+
+ # if all fails, we just return whatever the main connection had
+ conn.logger.info('Falling back to using interpreter: %s' % conn.interpreter)
+ return conn.interpreter