ExecContext: Fix output handling #9
3 changed files with 18 additions and 9 deletions
|
|
@ -78,7 +78,7 @@ class Distro(abc.ABC):
|
|||
),
|
||||
)
|
||||
raise
|
||||
uname = result.stdout_str.lower()
|
||||
uname = result.stdout_str.strip().lower()
|
||||
ret = f'ID={uname}\nVERSION_CODENAME=unknown'
|
||||
return ret
|
||||
|
||||
|
|
|
|||
|
|
@ -516,13 +516,14 @@ class ExecContext(Base):
|
|||
cmd: list[str]
|
||||
cmd_input: Input = InputMode.NonInteractive
|
||||
|
||||
tmp_file: str | None = None
|
||||
if wd is not None:
|
||||
path = wd + '/' + path
|
||||
cmds: list[RemoteCmd] = []
|
||||
stdout = (await __run(['mktemp', path + '.XXXXXX'])).stdout_str
|
||||
if stdout is None:
|
||||
raise Exception(f'Failed to create tmp-directory on {self.root}')
|
||||
out = stdout.strip() if atomic else path
|
||||
out = path
|
||||
if atomic:
|
||||
out = (await __run(['mktemp', path + '.XXXXXX'])).stdout_str.strip()
|
||||
tmp_file = out
|
||||
cmds.append(RemoteCmd(
|
||||
cmd = ['tee', out],
|
||||
cmd_input = content,
|
||||
|
|
@ -551,9 +552,12 @@ class ExecContext(Base):
|
|||
try:
|
||||
for cmd in cmds:
|
||||
log(DEBUG, f'{self.log_name}: Running {pretty_cmd(cmd.cmd, wd)}')
|
||||
ret = await __run(cmd.cmd)
|
||||
ret = await __run(cmd.cmd, cmd_input = cmd.cmd_input)
|
||||
tmp_file = None # Has been successfully moved at this point
|
||||
return ret
|
||||
finally:
|
||||
if tmp_file is not None:
|
||||
await self.erase(tmp_file)
|
||||
await self.close()
|
||||
except Exception as e:
|
||||
msg = f'Failed to get {path} from {self.root} ({str(e)})'
|
||||
|
|
@ -588,7 +592,7 @@ class ExecContext(Base):
|
|||
raise Exception(
|
||||
f'Failed to create temporary file on {self.root}: {result.summary}'
|
||||
)
|
||||
return result.stdout_str
|
||||
return result.stdout_str.strip()
|
||||
|
||||
async def _stat(self, path: str, follow_symlinks: bool) -> StatResult:
|
||||
|
||||
|
|
|
|||
|
|
@ -44,9 +44,14 @@ class Result:
|
|||
if self.__stdout is None:
|
||||
ret = ''
|
||||
else:
|
||||
ret = self.stdout_str[:20]
|
||||
max_len = 40
|
||||
try:
|
||||
ret = self.stdout_str[:max_len]
|
||||
except UnicodeDecodeError:
|
||||
chunk = self.__stdout[:max_len]
|
||||
ret = ''.join(chr(b) if 32 <= b <= 126 else '.' for b in chunk)
|
||||
if quote:
|
||||
ret = '"{ret}"'
|
||||
ret = f'"{ret}"'
|
||||
return ret
|
||||
|
||||
def __repr__(self) -> str:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue