Skip to content

Commit 10796f5

Browse files
committed
tplgtool2.py: support filesystem globbing and multiple arguments
Warning: this is a backwards-incompatible change! The previous behavior is now available ONLY when using `--tplgroot`. Up to now the user interface made the unusual choice to implement globbing internally instead of relying on the operating system. Maybe for compatibility with ancient .BAT scripts? So before this commit, internal globbing had to be quoted like this to escape the shell globbing, otherwise it would reject too many arguments: ./tplgtool2.py 'sof-*.tplg' # old, now INVALID usage This commit adds support for multiple arguments and such quoting is not necessary anymore. HOWEVER, for backwards-compatibility the old behavior is preserved when using `--tplgroot`: ./tplgtool2.py --tplgroot . 'sof-*.tplg' # UNCHANGED behavior See new --help message for more details. Also add a number of `assert` to fix usability issue #969 and error handling when relying on the older behavior. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent 2e1573c commit 10796f5

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

tools/tplgtool2.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,11 +1160,13 @@ def parse_cmdline():
11601160
description='A Topology Reader totally Written in Python.')
11611161

11621162
parser.add_argument('--version', action='version', version='%(prog)s 1.0')
1163-
parser.add_argument('-t', '--tplgroot', type=str, help="load tplg file from tplg_root folder")
1163+
parser.add_argument('-t', '--tplgroot', type=str, help="""Load topology files matching \
1164+
a patterns argument from the tplg_root folder.
1165+
Enables internal globbing mode: the single positional argument is not a file but a comma-separated list of patterns.""")
11641166
parser.add_argument('-d', '--dump', type=str, help='dump specified topology information, '
11651167
'if multiple information types are wanted, use "," to separate them, eg, `-d pcm,graph`')
1166-
parser.add_argument('filename', type=str, help='topology file name pattern(s), ' \
1167-
'if multiple topology file names are specified, please use "," to separate them')
1168+
parser.add_argument('filenames', nargs='+', type=str, help="""topology filenames or single pattern argument depending on
1169+
--tplgroot, see below. To pass multiple patterns use "," to separate them.""")
11681170
# The below options are used to control generated graph
11691171
parser.add_argument('-D', '--directory', type=str, default=".", help="output directory for generated graph")
11701172
parser.add_argument('-F', '--format', type=str, default="png", help="output format for generated graph, check "
@@ -1214,7 +1216,6 @@ def get_tplg_paths(tplgroot: typing.Union[str, None], patterns: str) -> "list[Pa
12141216
return [tplgpath
12151217
for pattern in arg_split(patterns)
12161218
for tplgpath in do_glob(rootpath, pattern)
1217-
if tplgpath.suffix == '.tplg'
12181219
]
12191220

12201221
def main():
@@ -1223,13 +1224,23 @@ def main():
12231224

12241225
cmd_args = parse_cmdline()
12251226
dump_types = supported_dump if cmd_args.dump is None else arg_split(cmd_args.dump)
1226-
for file in get_tplg_paths(cmd_args.tplgroot, cmd_args.filename):
1227-
tplg = GroupedTplg(tplgFormat.parse_file(file))
1227+
1228+
if cmd_args.tplgroot:
1229+
assert len(cmd_args.filenames) == 1, \
1230+
f"Too many arguments when using --tplgroot, try quoting? {cmd_args.filenames}"
1231+
patterns = cmd_args.filenames[0]
1232+
files = get_tplg_paths(cmd_args.tplgroot, patterns)
1233+
assert len(files) > 0, f"{patterns} did not match anything in '{cmd_args.tplgroot}'"
1234+
else:
1235+
files = [ Path(f) for f in cmd_args.filenames ]
1236+
1237+
for f in files:
1238+
tplg = GroupedTplg(tplgFormat.parse_file(f))
12281239
if 'pcm' in dump_types:
12291240
tplg.print_pcm_info()
12301241
if 'graph' in dump_types:
12311242
graph = TplgGraph(tplg)
12321243
graph.show_core = cmd_args.show_core
1233-
graph.draw(file.stem, outdir=cmd_args.directory, file_format=cmd_args.format, live_view=cmd_args.live_view)
1244+
graph.draw(f.stem, outdir=cmd_args.directory, file_format=cmd_args.format, live_view=cmd_args.live_view)
12341245

12351246
main()

0 commit comments

Comments
 (0)