mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
connection: Add BackgroundCommand.__init__(conn)
Add a constructor to BackgroundCommand so that the command knows the connection it's tied to.
This commit is contained in:
parent
7bdd6a0ade
commit
069d2322f1
@ -120,6 +120,10 @@ class BackgroundCommand(ABC):
|
|||||||
Instances of this class can be used as context managers, with the same
|
Instances of this class can be used as context managers, with the same
|
||||||
semantic as :class:`subprocess.Popen`.
|
semantic as :class:`subprocess.Popen`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def __init__(self, conn):
|
||||||
|
self.conn = conn
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def send_signal(self, sig):
|
def send_signal(self, sig):
|
||||||
"""
|
"""
|
||||||
@ -235,7 +239,8 @@ class PopenBackgroundCommand(BackgroundCommand):
|
|||||||
:class:`subprocess.Popen`-based background command.
|
:class:`subprocess.Popen`-based background command.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, popen):
|
def __init__(self, conn, popen):
|
||||||
|
super().__init__(conn=conn)
|
||||||
self.popen = popen
|
self.popen = popen
|
||||||
|
|
||||||
def send_signal(self, sig):
|
def send_signal(self, sig):
|
||||||
@ -291,9 +296,9 @@ class ParamikoBackgroundCommand(BackgroundCommand):
|
|||||||
:mod:`paramiko`-based background command.
|
:mod:`paramiko`-based background command.
|
||||||
"""
|
"""
|
||||||
def __init__(self, conn, chan, pid, as_root, cmd, stdin, stdout, stderr, redirect_thread):
|
def __init__(self, conn, chan, pid, as_root, cmd, stdin, stdout, stderr, redirect_thread):
|
||||||
|
super().__init__(conn=conn)
|
||||||
self.chan = chan
|
self.chan = chan
|
||||||
self.as_root = as_root
|
self.as_root = as_root
|
||||||
self.conn = conn
|
|
||||||
self._pid = pid
|
self._pid = pid
|
||||||
self._stdin = stdin
|
self._stdin = stdin
|
||||||
self._stdout = stdout
|
self._stdout = stdout
|
||||||
@ -454,7 +459,7 @@ class AdbBackgroundCommand(BackgroundCommand):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, conn, adb_popen, pid, as_root):
|
def __init__(self, conn, adb_popen, pid, as_root):
|
||||||
self.conn = conn
|
super().__init__(conn=conn)
|
||||||
self.as_root = as_root
|
self.as_root = as_root
|
||||||
self.adb_popen = adb_popen
|
self.adb_popen = adb_popen
|
||||||
self._pid = pid
|
self._pid = pid
|
||||||
|
@ -141,7 +141,7 @@ class LocalConnection(ConnectionBase):
|
|||||||
shell=True,
|
shell=True,
|
||||||
preexec_fn=preexec_fn,
|
preexec_fn=preexec_fn,
|
||||||
)
|
)
|
||||||
bg_cmd = PopenBackgroundCommand(popen)
|
bg_cmd = PopenBackgroundCommand(self, popen)
|
||||||
self._current_bg_cmds.add(bg_cmd)
|
self._current_bg_cmds.add(bg_cmd)
|
||||||
return bg_cmd
|
return bg_cmd
|
||||||
|
|
||||||
|
@ -334,7 +334,12 @@ class AdbConnection(ConnectionBase):
|
|||||||
adb_command(self.device, command, timeout=timeout, adb_server=self.adb_server)
|
adb_command(self.device, command, timeout=timeout, adb_server=self.adb_server)
|
||||||
else:
|
else:
|
||||||
with self.transfer_mgr.manage(sources, dest, action):
|
with self.transfer_mgr.manage(sources, dest, action):
|
||||||
bg_cmd = adb_command_background(self.device, command, adb_server=self.adb_server)
|
bg_cmd = adb_command_background(
|
||||||
|
device=self.device,
|
||||||
|
conn=self,
|
||||||
|
command=command,
|
||||||
|
adb_server=self.adb_server
|
||||||
|
)
|
||||||
self.transfer_mgr.set_transfer_and_wait(bg_cmd)
|
self.transfer_mgr.set_transfer_and_wait(bg_cmd)
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
@ -692,11 +697,11 @@ def adb_command(device, command, timeout=None, adb_server=None):
|
|||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
def adb_command_background(device, command, adb_server=None):
|
def adb_command_background(device, conn, command, adb_server=None):
|
||||||
full_command = get_adb_command(device, command, adb_server)
|
full_command = get_adb_command(device, command, adb_server)
|
||||||
logger.debug(full_command)
|
logger.debug(full_command)
|
||||||
proc = get_subprocess(full_command, shell=True)
|
popen = get_subprocess(full_command, shell=True)
|
||||||
cmd = PopenBackgroundCommand(proc)
|
cmd = PopenBackgroundCommand(conn=conn, popen=popen)
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user