# the FIGETBSZ ioctl (number 2).
binary_data = ioctl(file_obj, 2, struct.pack('I', 0))
return struct.unpack('I', binary_data)[0]
+
+def program_is_available(name):
+ """
+ This is a helper function which check if the external program 'name' is
+ available in the system.
+ """
+
+ import os
+
+ for path in os.environ["PATH"].split(os.pathsep):
+ program = os.path.join(path.strip('"'), name)
+ if os.path.isfile(program) and os.access(program, os.X_OK):
+ return True
+
+ return False
import errno
import urlparse
import logging
+import subprocess
+import BmapHelpers
# Disable the following pylint errors and recommendations:
# * Instance of X has no member Y (E1101), because it produces
support password-based authentication.
"""
- import subprocess
-
username = parsed_url.username
password = parsed_url.password
path = parsed_url.path
hostname = username + "@" + hostname
# Make sure the ssh client program is installed
- try:
- subprocess.Popen("ssh", stderr=subprocess.PIPE,
- stdout=subprocess.PIPE).wait()
- except OSError as err:
- if err.errno == os.errno.ENOENT:
- raise Error("\"sshpass\" program not found, but it is "
- "required for downloading over SSH")
+ if not BmapHelpers.program_is_available("ssh"):
+ raise Error("the \"ssh\" program is not available but it is "
+ "required for downloading over the ssh protocol")
# Prepare the commands that we are going to run
if password:
hostname]
# Make sure the sshpass program is installed
- try:
- subprocess.Popen("sshpass", stderr=subprocess.PIPE,
- stdout=subprocess.PIPE).wait()
- except OSError as err:
- if err.errno == os.errno.ENOENT:
- raise Error("\"sshpass\" program not found, but it is "
- "required for password SSH authentication")
+ if not BmapHelpers.program_is_available("ssh"):
+ raise Error("the \"sshpass\" program is not available but it "
+ "is required for password-based SSH authentication")
else:
popen_args = ["ssh",
"-o StrictHostKeyChecking=no",