Commit 64ed7d81 authored by Jakub Kicinski's avatar Jakub Kicinski

selftests: drv-net: reimplement the config parser

The shell lexer is not helping much, do very basic parsing
manually.
Reviewed-by: default avatarWillem de Bruijn <willemb@google.com>
Link: https://lore.kernel.org/r/20240425222341.309778-3-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent f8ac9b0f
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
import os import os
import shlex
from pathlib import Path from pathlib import Path
from lib.py import KsftSkipEx from lib.py import KsftSkipEx
from lib.py import cmd, ip from lib.py import cmd, ip
...@@ -16,17 +15,20 @@ def _load_env_file(src_path): ...@@ -16,17 +15,20 @@ def _load_env_file(src_path):
if not (src_dir / "net.config").exists(): if not (src_dir / "net.config").exists():
return env return env
lexer = shlex.shlex(open((src_dir / "net.config").as_posix(), 'r').read()) with open((src_dir / "net.config").as_posix(), 'r') as fp:
k = None for line in fp.readlines():
for token in lexer: full_file = line
if k is None: # Strip comments
k = token pos = line.find("#")
env[k] = "" if pos >= 0:
elif token == "=": line = line[:pos]
pass line = line.strip()
else: if not line:
env[k] = token continue
k = None pair = line.split('=', maxsplit=1)
if len(pair) != 2:
raise Exception("Can't parse configuration line:", full_file)
env[pair[0]] = pair[1]
return env return env
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment