1
0
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:
Douglas Raillard 2023-04-06 21:02:17 +01:00 committed by Marc Bonnici
parent 7bdd6a0ade
commit 069d2322f1
3 changed files with 18 additions and 8 deletions

View File

@ -120,6 +120,10 @@ class BackgroundCommand(ABC):
Instances of this class can be used as context managers, with the same
semantic as :class:`subprocess.Popen`.
"""
def __init__(self, conn):
self.conn = conn
@abstractmethod
def send_signal(self, sig):
"""
@ -235,7 +239,8 @@ class PopenBackgroundCommand(BackgroundCommand):
:class:`subprocess.Popen`-based background command.
"""
def __init__(self, popen):
def __init__(self, conn, popen):
super().__init__(conn=conn)
self.popen = popen
def send_signal(self, sig):
@ -291,9 +296,9 @@ class ParamikoBackgroundCommand(BackgroundCommand):
:mod:`paramiko`-based background command.
"""
def __init__(self, conn, chan, pid, as_root, cmd, stdin, stdout, stderr, redirect_thread):
super().__init__(conn=conn)
self.chan = chan
self.as_root = as_root
self.conn = conn
self._pid = pid
self._stdin = stdin
self._stdout = stdout
@ -454,7 +459,7 @@ class AdbBackgroundCommand(BackgroundCommand):
"""
def __init__(self, conn, adb_popen, pid, as_root):
self.conn = conn
super().__init__(conn=conn)
self.as_root = as_root
self.adb_popen = adb_popen
self._pid = pid

View File

@ -141,7 +141,7 @@ class LocalConnection(ConnectionBase):
shell=True,
preexec_fn=preexec_fn,
)
bg_cmd = PopenBackgroundCommand(popen)
bg_cmd = PopenBackgroundCommand(self, popen)
self._current_bg_cmds.add(bg_cmd)
return bg_cmd

View File

@ -334,7 +334,12 @@ class AdbConnection(ConnectionBase):
adb_command(self.device, command, timeout=timeout, adb_server=self.adb_server)
else:
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)
# pylint: disable=unused-argument
@ -692,11 +697,11 @@ def adb_command(device, command, timeout=None, adb_server=None):
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)
logger.debug(full_command)
proc = get_subprocess(full_command, shell=True)
cmd = PopenBackgroundCommand(proc)
popen = get_subprocess(full_command, shell=True)
cmd = PopenBackgroundCommand(conn=conn, popen=popen)
return cmd