From: Jeremy Spewock <jspewock@iol.unh.edu>
To: "Juraj Linkeš" <juraj.linkes@pantheon.tech>
Cc: thomas@monjalon.net, Honnappa.Nagarahalli@arm.com,
probb@iol.unh.edu, paul.szczepanek@arm.com,
Luca.Vizzarro@arm.com, dev@dpdk.org
Subject: Re: [PATCH v1] dts: strip whitespaces from stdout and stderr
Date: Mon, 12 Feb 2024 11:49:05 -0500 [thread overview]
Message-ID: <CAAA20UQ6PnVCapMDOyRE8D3u+OE+3bv87VZRxVHfELdjOqeyHA@mail.gmail.com> (raw)
In-Reply-To: <20240207121641.22739-1-juraj.linkes@pantheon.tech>
On Wed, Feb 7, 2024 at 7:16 AM Juraj Linkeš <juraj.linkes@pantheon.tech> wrote:
>
> There could be a newline at the end of stdout or stderr of a remotely
> executed command. These cause issues when used later, such as when
> joining paths from such commands - a newline in the middle of a path is
> not valid.
>
> Fixes: ad80f550dbc5 ("dts: add SSH command verification")
> Signed-off-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
> ---
> .../remote_session/remote_session.py | 24 +++++++++++++++----
> 1 file changed, 20 insertions(+), 4 deletions(-)
>
> diff --git a/dts/framework/remote_session/remote_session.py b/dts/framework/remote_session/remote_session.py
> index 2059f9a981..6bea1a2306 100644
> --- a/dts/framework/remote_session/remote_session.py
> +++ b/dts/framework/remote_session/remote_session.py
> @@ -10,8 +10,8 @@
> """
>
>
> -import dataclasses
> from abc import ABC, abstractmethod
> +from dataclasses import InitVar, dataclass, field
> from pathlib import PurePath
>
> from framework.config import NodeConfiguration
> @@ -20,7 +20,7 @@
> from framework.settings import SETTINGS
>
>
> -@dataclasses.dataclass(slots=True, frozen=True)
> +@dataclass(slots=True, frozen=True)
> class CommandResult:
> """The result of remote execution of a command.
>
> @@ -34,9 +34,25 @@ class CommandResult:
>
> name: str
> command: str
> - stdout: str
> - stderr: str
> + init_stdout: InitVar[str]
> + init_stderr: InitVar[str]
> return_code: int
> + stdout: str = field(init=False)
> + stderr: str = field(init=False)
> +
> + def __post_init__(self, init_stdout, init_stderr):
Are the typehints skipped deliberately here because it's redundant? We
might want to include them anyway just for better typehint coverage.
> + """Strip the whitespaces from stdout and stderr.
> +
> + The generated __init__ method uses object.__setattr__() when the dataclass is frozen,
> + so that's what we use here as well.
> +
> + In order to get access to dataclass fields in the __post_init__ method,
> + we have to type them as InitVars. These InitVars are included in the __init__ method's
> + signature, so we have to exclude the actual stdout and stderr fields
> + from the __init__ method's signature, so that we have the proper number of arguments.
> + """
> + object.__setattr__(self, "stdout", init_stdout.strip())
> + object.__setattr__(self, "stderr", init_stderr.strip())
>
> def __str__(self) -> str:
> """Format the command outputs."""
> --
> 2.34.1
>
next prev parent reply other threads:[~2024-02-12 16:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-07 12:16 Juraj Linkeš
2024-02-12 16:49 ` Jeremy Spewock [this message]
2024-02-13 11:06 ` Juraj Linkeš
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAAA20UQ6PnVCapMDOyRE8D3u+OE+3bv87VZRxVHfELdjOqeyHA@mail.gmail.com \
--to=jspewock@iol.unh.edu \
--cc=Honnappa.Nagarahalli@arm.com \
--cc=Luca.Vizzarro@arm.com \
--cc=dev@dpdk.org \
--cc=juraj.linkes@pantheon.tech \
--cc=paul.szczepanek@arm.com \
--cc=probb@iol.unh.edu \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).