From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8E1FE43E74; Tue, 16 Apr 2024 14:15:49 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 598D04029E; Tue, 16 Apr 2024 14:15:49 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id 7023A40262 for ; Tue, 16 Apr 2024 14:15:47 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 052DA339; Tue, 16 Apr 2024 05:16:15 -0700 (PDT) Received: from [10.1.28.60] (FVFG51LCQ05N.cambridge.arm.com [10.1.28.60]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 76C6A3F738; Tue, 16 Apr 2024 05:15:45 -0700 (PDT) Message-ID: <743fd932-1192-42ac-ab5b-27ac5b7e56ed@arm.com> Date: Tue, 16 Apr 2024 13:15:43 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/5] dts: skip first line of send_command output Content-Language: en-GB To: =?UTF-8?Q?Juraj_Linke=C5=A1?= Cc: dev@dpdk.org, Jeremy Spewock , Paul Szczepanek , Jack Bond-Preston References: <20240412111136.3470304-1-luca.vizzarro@arm.com> <20240412111136.3470304-3-luca.vizzarro@arm.com> From: Luca Vizzarro In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On 16/04/2024 09:48, Juraj Linkeš wrote: > Oh, the first commit message was confusing. It said leading prompt > which I understood to be the first prompt (the one with the command). > I see that this commit actually addresses what I thought the first > commit was trying to do. Yes, my bad! >> - def send_command(self, command: str, prompt: str | None = None) -> str: >> + def send_command( >> + self, command: str, prompt: str | None = None, skip_first_line: bool = False > > Do we generally want or don't want to include the first line? When do > we absolutely not want to include it? In the case of `show port info/stats {x}` if the provided port is invalid, then the first message starts with `Invalid port`. By providing an output that skips the command prompt, this is easily checked with output.startswith("Invalid port") as you may have noticed in the next commit. Otherwise it'd be a bit more complicated. Personally, I am not sure whether we care about the first line. With my limited knowledge I don't see a reason to include it (just as much as the trailing prompt). >> + ) -> str: >> """Send `command` and get all output before the expected ending string. >> >> Lines that expect input are not included in the stdout buffer, so they cannot >> @@ -121,6 +123,7 @@ def send_command(self, command: str, prompt: str | None = None) -> str: >> command: The command to send. >> prompt: After sending the command, `send_command` will be expecting this string. >> If :data:`None`, will use the class's default prompt. >> + skip_first_line: Skip the first line when capturing the output. >> >> Returns: >> All output in the buffer before expected string. >> @@ -132,6 +135,9 @@ def send_command(self, command: str, prompt: str | None = None) -> str: >> self._stdin.flush() >> out: str = "" >> for line in self._stdout: >> + if skip_first_line: >> + skip_first_line = False >> + continue > > Is there ever a reason to distinguish between the first line and the > line with the command on it? As above, not really sure. Would this always be a command prompt? The doubt arises only because I don't understand why we'd need the command prompt fed back. > >> if prompt in line and not line.rstrip().endswith( >> command.rstrip() >> ): # ignore line that sent command >> -- >> 2.34.1 >>