Skip to content

Commit eaeb70e

Browse files
lrgirdwolgirdwood
authored andcommitted
tools: satisfy remaining pylint rules in sof-compr-tool and sof-tplgreader
- tools/sof-compr-tool.py: split BufferConfig out of StreamConfig to keep instance attributes within pylint limits (R0902). - tools/sof-tplgreader.py: extract _build_arg_parser and _print_pipeline_output helpers from main() to reduce branches (R0912). Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 62d7ce6 commit eaeb70e

2 files changed

Lines changed: 51 additions & 56 deletions

File tree

‎tools/sof-compr-tool.py‎

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,16 @@ class SndComprTstamp(ctypes.Structure):
274274
]
275275

276276

277+
@dataclass
278+
class BufferConfig:
279+
"""Buffer and wrapper setup options."""
280+
281+
frag_size: int = 0
282+
frags: int = 0
283+
bespoke: str = "auto"
284+
is_capture: bool = False
285+
286+
277287
@dataclass
278288
class StreamConfig:
279289
"""Resolved compress stream setup parameters."""
@@ -284,10 +294,7 @@ class StreamConfig:
284294
channels: int
285295
bitrate: int
286296
fmt_id: int
287-
frag_size: int = 0
288-
frags: int = 0
289-
bespoke: str = "auto"
290-
is_capture: bool = False
297+
buf: BufferConfig
291298
# pylint: enable=too-few-public-methods
292299

293300

@@ -367,8 +374,8 @@ def build_params(caps, cfg, use_bespoke=False):
367374
"""Construct SndComprParams bounded by reported caps."""
368375
params = SndComprParams()
369376

370-
req_frag = cfg.frag_size if cfg.frag_size > 0 else (2048 if cfg.is_capture else 8192)
371-
req_frags = cfg.frags if cfg.frags > 0 else 4
377+
req_frag = cfg.buf.frag_size if cfg.buf.frag_size > 0 else (2048 if cfg.buf.is_capture else 8192)
378+
req_frags = cfg.buf.frags if cfg.buf.frags > 0 else 4
372379

373380
min_frag = caps.min_fragment_size or 1024
374381
max_frag = caps.max_fragment_size or 65536
@@ -393,7 +400,7 @@ def build_params(caps, cfg, use_bespoke=False):
393400
codec.format = cfg.fmt_id if cfg.codec_id == SND_AUDIOCODEC_PCM else 0
394401
codec.pcm_format = cfg.fmt_id
395402

396-
if not use_bespoke and not cfg.is_capture and cfg.codec_id == SND_AUDIOCODEC_OPUS_RAW:
403+
if not use_bespoke and not cfg.buf.is_capture and cfg.codec_id == SND_AUDIOCODEC_OPUS_RAW:
397404
opus_d = codec.options.opus_d
398405
opus_d.version = 1
399406
opus_d.num_channels = cfg.channels
@@ -410,9 +417,9 @@ def build_params(caps, cfg, use_bespoke=False):
410417

411418
def set_params_with_fallback(fd, caps, cfg):
412419
"""Call SNDRV_COMPRESS_SET_PARAMS with optional BESPOKE fallback."""
413-
if cfg.bespoke == "always":
420+
if cfg.buf.bespoke == "always":
414421
modes = [True]
415-
elif cfg.bespoke == "never":
422+
elif cfg.buf.bespoke == "never":
416423
modes = [False]
417424
else:
418425
modes = [False, True] if cfg.codec_id > SND_AUDIOCODEC_BESPOKE else [False]
@@ -497,10 +504,12 @@ def _stream_config_from_args(args, is_capture):
497504
channels=args.channels,
498505
bitrate=bitrate,
499506
fmt_id=resolve_pcm_format(args.fmt),
500-
frag_size=args.frag_size,
501-
frags=args.frags,
502-
bespoke=args.bespoke,
503-
is_capture=is_capture,
507+
buf=BufferConfig(
508+
frag_size=args.frag_size,
509+
frags=args.frags,
510+
bespoke=args.bespoke,
511+
is_capture=is_capture,
512+
),
504513
)
505514

506515

‎tools/sof-tplgreader.py‎

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def parse_and_set_block_keyword(block_str, tplgreader):
298298
tplgreader.setBlock(block_list)
299299

300300

301-
def main():
301+
def _build_arg_parser():
302302
parser = argparse.ArgumentParser(
303303
description='Filters and prints PCMs found in a .tplg file',
304304
add_help=True, formatter_class=argparse.RawTextHelpFormatter)
@@ -347,62 +347,48 @@ def main():
347347
parser.add_argument('-t', '--tplgroot', type=str, help="load file from tplg-root folder")
348348
parser.add_argument('-o', '--sort', action='store_true', help="sort pipeline by id for the same tplg")
349349
parser.add_argument('--version', action='version', version='%(prog)s 1.0')
350+
return parser
351+
350352

351-
ret_args = vars(parser.parse_args())
353+
def _print_pipeline_output(ret_args, pipeline_lst):
354+
if ret_args['export'] is True:
355+
sys.exit(export_pipeline(pipeline_lst))
356+
if ret_args['count'] is True:
357+
msg = len(pipeline_lst) if ret_args['value'] else "Pipeline Count: %d" % len(pipeline_lst)
358+
print(msg)
359+
return
360+
if ret_args['index'] is not None and ret_args['index'] < len(pipeline_lst):
361+
print(format_pipeline(pipeline_lst[ret_args['index']], ret_args['value']))
362+
return
363+
for entry in pipeline_lst:
364+
print(format_pipeline(entry, ret_args['value']))
352365

366+
367+
def main():
368+
ret_args = vars(_build_arg_parser().parse_args())
353369
tplgreader = clsTPLGReader()
354-
dump_lst = []
355-
pipeline_lst = []
356-
tplg_root = ""
357370

358-
# parse and set filter keyword
359-
if ret_args['filter'] is not None and len(ret_args['filter']) > 0:
360-
filter_dict = parse_filter(ret_args['filter'])
361-
tplgreader.setFilter(filter_dict)
371+
if ret_args['filter']:
372+
tplgreader.setFilter(parse_filter(ret_args['filter']))
362373

363-
# If run general test case on WOV pipeline or ECHO REFERENCE capture pipeline, there will be error
364-
# due to no feed data, and they should be blocked in general test case.
365374
default_block_keyword = 'kpbm:any;kpb:any;type:capture & echo;compress:1;'
366-
# if no filter or block item is specified, the "block_none" here will help to
367-
# block nothing
368-
block_str = "block_none"
369-
# user specified block items from command line
370375
cmd_block_str = ret_args['block'].strip() if ret_args['block'] is not None else ''
371-
372376
if ret_args["filter"] is not None and not re.search('echo|kpb|compress', ret_args["filter"]):
373377
block_str = default_block_keyword + cmd_block_str
374378
else:
375-
block_str = cmd_block_str if cmd_block_str != '' else block_str
376-
379+
block_str = cmd_block_str or "block_none"
377380
parse_and_set_block_keyword(block_str, tplgreader)
378381

379-
if ret_args['dump'] is not None and len(ret_args['dump']) > 0:
380-
dump_lst = ret_args['dump']
382+
if ret_args['dump']:
383+
tplgreader.setField(ret_args['dump'])
381384

382-
if len(dump_lst) > 0:
383-
tplgreader.setField(dump_lst)
384-
385-
if ret_args['tplgroot'] is not None and len(ret_args['tplgroot']) > 0:
386-
tplg_root = ret_args['tplgroot']
387-
388-
for f in ret_args['filename'].split(','):
389-
if len(tplg_root) > 0:
390-
f = tplg_root + "/" + f
391-
pipeline_lst += func_getPipeline(tplgreader, f, ret_args['sofcard'], ret_args['sort'])[:]
392-
393-
if ret_args['export'] is True:
394-
sys.exit(export_pipeline(pipeline_lst))
385+
tplg_root = ret_args['tplgroot'] or ""
386+
pipeline_lst = []
387+
for fname in ret_args['filename'].split(','):
388+
path = f"{tplg_root}/{fname}" if tplg_root else fname
389+
pipeline_lst += func_getPipeline(tplgreader, path, ret_args['sofcard'], ret_args['sort'])[:]
395390

396-
if ret_args['count'] is True:
397-
if ret_args['value'] is True:
398-
print(len(pipeline_lst))
399-
else:
400-
print("Pipeline Count: %d" % (len(pipeline_lst)))
401-
elif ret_args['index'] is not None and ret_args['index'] < len(pipeline_lst):
402-
print(format_pipeline(pipeline_lst[ret_args['index']], ret_args['value']))
403-
else:
404-
for entry in pipeline_lst:
405-
print(format_pipeline(entry, ret_args['value']))
391+
_print_pipeline_output(ret_args, pipeline_lst)
406392

407393

408394
if __name__ == "__main__":

0 commit comments

Comments
 (0)