diff --git a/src/usr/lib/rsetup/cli/u-boot-menu.sh b/src/usr/lib/rsetup/cli/u-boot-menu.sh index 99ae6721..3bf68a7b 100644 --- a/src/usr/lib/rsetup/cli/u-boot-menu.sh +++ b/src/usr/lib/rsetup/cli/u-boot-menu.sh @@ -13,7 +13,7 @@ check_overlay_conflict_init() { check_overlay_conflict() { local name resources res i mapfile -t resources < <(parse_dtbo "exclusive" "$1") - mapfile -t name < <(parse_dtbo "-e" "file" "title" "$1") + mapfile -t name < <(parse_dtbo "--default-value" "file" "title" "$1") for res in "${resources[@]}" do diff --git a/src/usr/lib/rsetup/mod/parse_dtbo b/src/usr/lib/rsetup/mod/parse_dtbo index 468f47ea..fec8f695 100755 --- a/src/usr/lib/rsetup/mod/parse_dtbo +++ b/src/usr/lib/rsetup/mod/parse_dtbo @@ -1,11 +1,10 @@ #!/usr/bin/env python3 # -*- coding: UTF-8 -*- -from sys import argv, stdin, stderr import yaml, re, os, argparse def status(file): - if ".disabled" in os.path.splitext(file)[-1]: + if ".disabled" == os.path.splitext(file)[-1]: print("OFF") else: print("ON") @@ -13,47 +12,24 @@ def status(file): def basename(file): print(re.match(r'(.+\.dtbo)',os.path.basename(file)).group(1)) -def short_print(metadata): - print(metadata[args.keyword][0].replace("\0", "\n")) - -def short_error_print(file): - if args.e == "file": - basename(file) - else: - print(args.e) - -def long_print(metadata, file): - short_print(metadata) - status(file) - basename(file) - -def long_error_print(file): - if args.e == "file":basename(file) - else: - print(args.e) - status(file) - basename(file) - parser = argparse.ArgumentParser(description='Parse dtbo metadata data') -parser.add_argument('-F', action='store_true', default=False, help='Control print DTBO title,enable status and DTBO filename') -parser.add_argument('-e', metavar='string', default="null", help='error default string') -parser.add_argument('keyword', metavar='string', help='Keyword') +parser.add_argument('--show-overlays', action='store_true', default=False, help='Control print DTBO title,enable status and DTBO filename') +parser.add_argument('--default-value', metavar='string', default="null", help='error default string') +parser.add_argument('field', metavar='string', help='Metadata field') parser.add_argument('filename', nargs='+', metavar='filename', help='DTBO filename list') - args = parser.parse_args() yaml.CLoader.add_constructor('!u8', yaml.constructor.FullConstructor.construct_yaml_seq) -if args.F: - for file in args.filename: - try: - metadata=yaml.load(os.popen("dtc -I dtb -O dts " + file + " 2>/dev/null | dtc -I dts -O yaml 2>/dev/null").read(), Loader=yaml.CLoader)[0]["metadata"] - long_print(metadata, file) - except Exception as e: - long_error_print(file) -else: - for file in args.filename: - try: - metadata=yaml.load(os.popen("dtc -I dtb -O dts " + file + " 2>/dev/null | dtc -I dts -O yaml 2>/dev/null").read(), Loader=yaml.CLoader)[0]["metadata"] - short_print(metadata) - except Exception as e: - short_error_print(file) + +for file in args.filename: + try: + metadata = yaml.load(os.popen("dtc -I dtb -O dts " + file + " 2>/dev/null | dtc -I dts -O yaml 2>/dev/null").read(), Loader=yaml.CLoader)[0]["metadata"] + print(metadata[args.field][0].replace("\0", "\n")) + except Exception: + if args.default_value == "file": + basename(file) + else: + print(args.default_value) + if args.show_overlays: + status(file) + basename(file) diff --git a/src/usr/lib/rsetup/tui/overlay/overlay.sh b/src/usr/lib/rsetup/tui/overlay/overlay.sh index 846bf9c7..4d4d3ae6 100644 --- a/src/usr/lib/rsetup/tui/overlay/overlay.sh +++ b/src/usr/lib/rsetup/tui/overlay/overlay.sh @@ -81,7 +81,7 @@ __overlay_show() { # Bash doesn support IFS=$'\0' # Use array to emulate this local items=() - mapfile -t items < <(parse_dtbo "-F" "title" "${dtbos[@]}") + mapfile -t items < <(parse_dtbo "--show-overlays" "title" "${dtbos[@]}") while (( ${#items[@]} >= 3 )) do checklist_add "${items[0]/$'\n'}" "${items[1]/$'\n'}" "${items[2]/$'\n'}" @@ -116,7 +116,7 @@ __overlay_validate() { fi local title package - mapfile -t title < <(parse_dtbo "-e" "file" "title" "$U_BOOT_FDT_OVERLAYS_DIR/$item"*) + mapfile -t title < <(parse_dtbo "--default-value" "file" "title" "$U_BOOT_FDT_OVERLAYS_DIR/$item"*) mapfile -t package < <(parse_dtbo "package" "$U_BOOT_FDT_OVERLAYS_DIR/$item"*) if [[ "${package[0]}" != "null" ]] then