@@ -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
408394if __name__ == "__main__" :
0 commit comments