mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
ssh: Fix tools detection
Fix inadequate use of module-level __getattr__ (it is not used by the global variable lookup path). Instead, detect all tools lazily in the same fashion as with _AndroidEnv()
This commit is contained in:
parent
c347861db4
commit
56746fdb33
@ -67,18 +67,18 @@ from devlib.connection import (ConnectionBase, ParamikoBackgroundCommand, PopenB
|
|||||||
DEFAULT_SSH_SUDO_COMMAND = "sudo -k -p ' ' -S -- sh -c {}"
|
DEFAULT_SSH_SUDO_COMMAND = "sudo -k -p ' ' -S -- sh -c {}"
|
||||||
|
|
||||||
|
|
||||||
# Lazy init of some globals
|
class _SSHEnv:
|
||||||
def __getattr__(attr):
|
@functools.lru_cache(maxsize=None)
|
||||||
if attr in {'ssh', 'scp', 'sshpass'}:
|
def get_path(self, tool):
|
||||||
path = which(attr)
|
if tool in {'ssh', 'scp', 'sshpass'}:
|
||||||
if path:
|
path = which(tool)
|
||||||
globals()[attr] = path
|
if path:
|
||||||
return path
|
return path
|
||||||
|
else:
|
||||||
|
raise HostError(f'OpenSSH must be installed on the host: could not find {tool} command')
|
||||||
else:
|
else:
|
||||||
raise HostError(f'OpenSSH must be installed on the host: could not find {attr} command')
|
raise AttributeError(f"Tool '{tool}' is not supported")
|
||||||
else:
|
_SSH_ENV = _SSHEnv()
|
||||||
raise AttributeError(f"Module '{__name__}' has no attribute '{attr}'")
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('ssh')
|
logger = logging.getLogger('ssh')
|
||||||
gem5_logger = logging.getLogger('gem5-connection')
|
gem5_logger = logging.getLogger('gem5-connection')
|
||||||
@ -848,7 +848,7 @@ class TelnetConnection(SshConnectionBase):
|
|||||||
options = " ".join(["-o {}={}".format(key, val)
|
options = " ".join(["-o {}={}".format(key, val)
|
||||||
for key, val in self.options.items()])
|
for key, val in self.options.items()])
|
||||||
paths = ' '.join(map(quote, paths))
|
paths = ' '.join(map(quote, paths))
|
||||||
command = '{} {} -r {} {} {}'.format(scp,
|
command = '{} {} -r {} {} {}'.format(_SSH_ENV.get_path('scp'),
|
||||||
options,
|
options,
|
||||||
keyfile_string,
|
keyfile_string,
|
||||||
port_string,
|
port_string,
|
||||||
@ -916,7 +916,7 @@ class TelnetConnection(SshConnectionBase):
|
|||||||
command = self.sudo_cmd.format(command)
|
command = self.sudo_cmd.format(command)
|
||||||
options = " ".join([ "-o {}={}".format(key,val)
|
options = " ".join([ "-o {}={}".format(key,val)
|
||||||
for key,val in self.options.items()])
|
for key,val in self.options.items()])
|
||||||
command = '{} {} {} {} {}@{} {}'.format(ssh,
|
command = '{} {} {} {} {}@{} {}'.format(_SSH_ENV.get_path('ssh'),
|
||||||
options,
|
options,
|
||||||
keyfile_string,
|
keyfile_string,
|
||||||
port_string,
|
port_string,
|
||||||
@ -1606,6 +1606,7 @@ class AndroidGem5Connection(Gem5Connection):
|
|||||||
|
|
||||||
|
|
||||||
def _give_password(password, command):
|
def _give_password(password, command):
|
||||||
|
sshpass = _SSH_ENV.get_path('sshpass')
|
||||||
if sshpass:
|
if sshpass:
|
||||||
pass_template = "{} -p {} "
|
pass_template = "{} -p {} "
|
||||||
pass_string = pass_template.format(quote(sshpass), quote(password))
|
pass_string = pass_template.format(quote(sshpass), quote(password))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user