[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6629b5291e1a7_1bd6b0294a5@willemb.c.googlers.com.notmuch>
Date: Wed, 24 Apr 2024 21:43:05 -0400
From: Willem de Bruijn <willemdebruijn.kernel@...il.com>
To: Jakub Kicinski <kuba@...nel.org>,
davem@...emloft.net
Cc: netdev@...r.kernel.org,
edumazet@...gle.com,
pabeni@...hat.com,
linux-kselftest@...r.kernel.org,
willemdebruijn.kernel@...il.com,
Jakub Kicinski <kuba@...nel.org>
Subject: Re: [PATCH net-next 3/4] selftests: drv-net: reimplement the config
parser
Jakub Kicinski wrote:
> The shell lexer is not helping much, do very basic parsing
> manually.
>
> Signed-off-by: Jakub Kicinski <kuba@...nel.org>
> ---
> .../selftests/drivers/net/lib/py/env.py | 26 ++++++++++---------
> 1 file changed, 14 insertions(+), 12 deletions(-)
>
> diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py
> index a3db1bb1afeb..a6a5a5f9c6db 100644
> --- a/tools/testing/selftests/drivers/net/lib/py/env.py
> +++ b/tools/testing/selftests/drivers/net/lib/py/env.py
> @@ -1,7 +1,6 @@
> # SPDX-License-Identifier: GPL-2.0
>
> import os
> -import shlex
> from pathlib import Path
> from lib.py import KsftSkipEx
> from lib.py import cmd, ip
> @@ -16,17 +15,20 @@ from .remote import Remote
> if not (src_dir / "net.config").exists():
> return env
>
> - lexer = shlex.shlex(open((src_dir / "net.config").as_posix(), 'r').read())
> - k = None
> - for token in lexer:
> - if k is None:
> - k = token
> - env[k] = ""
> - elif token == "=":
> - pass
> - else:
> - env[k] = token
> - k = None
> + with open((src_dir / "net.config").as_posix(), 'r') as fp:
> + for line in fp.readlines():
> + full_file = line
> + # Strip comments
> + pos = line.find("#")
> + if pos >= 0:
> + line = line[:pos]
> + line = line.strip()
> + if not line:
> + continue
> + pos = line.find("=")
> + if pos <= 0:
> + raise Exception("Can't parse configuration line:", full_file)
> + env[line[:pos]] = line[pos+1:]
Or line.split. But bikeshedding python is a deep rabbit hole :)
Powered by blists - more mailing lists