|
2 | 2 | # Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. |
3 | 3 | # SPDX-License-Identifier: BSD-3-Clause |
4 | 4 | # |
5 | | -# Print the filename attribute of a <program> element by label from a |
6 | | -# rawprogram XML file generated by qcom-ptool. |
| 5 | +# Parse a rawprogram XML file generated by qcom-ptool. Search for first |
| 6 | +# <program> element with provided label. Print its filename attribute, |
| 7 | +# stripped of a leading "../" if present. |
| 8 | +# |
| 9 | +# Returns "none" if no such element found. |
7 | 10 | # |
8 | 11 | # Usage: get-rawprogram-filename.py <label> <rawprogram0.xml> |
9 | 12 | # |
|
16 | 19 |
|
17 | 20 | if len(sys.argv) != 3: |
18 | 21 | print(f"Usage: {sys.argv[0]} <label> <rawprogram0.xml>", file=sys.stderr) |
| 22 | + sys.exit(1) |
| 23 | + |
| 24 | +label, xml_file = sys.argv[1], sys.argv[2] |
| 25 | + |
| 26 | +root = ET.parse(xml_file).getroot() |
| 27 | +e = root.find(f".//program[@label='{label}']") |
| 28 | +if e is None: |
19 | 29 | print("none") |
20 | | -else: |
21 | | - label, xml_file = sys.argv[1], sys.argv[2] |
| 30 | + sys.exit(0) |
22 | 31 |
|
23 | | - root = ET.parse(xml_file).getroot() |
24 | | - e = root.find(f".//program[@label='{label}']") |
25 | | - if e is None: |
26 | | - print("none") |
27 | | - else: |
28 | | - filename = e.get("filename") |
29 | | - # Strip any leading ../ path components |
30 | | - while filename.startswith("../"): |
31 | | - filename = filename[3:] |
32 | | - print(filename) |
| 32 | +filename = e.get("filename") |
| 33 | +# Strip any leading ../ path components |
| 34 | +while filename.startswith("../"): |
| 35 | + filename = filename[3:] |
| 36 | +print(filename) |
0 commit comments