From 6918f5ecc942b3279ef41bcc31349b3454f21757 Mon Sep 17 00:00:00 2001 From: CodeChenL <2540735020@qq.com> Date: Mon, 8 Jan 2024 18:38:10 +0800 Subject: [PATCH] Replacing function parse_dtbo and function dtbo_is_compatible with python scripts --- src/usr/lib/rsetup/cli/u-boot-menu.sh | 13 ----- .../{dtbo_compatible => dtbo_is_compatible} | 5 +- src/usr/lib/rsetup/mod/parse_dtbo | 57 +++++++++++++++++++ src/usr/lib/rsetup/mod/parse_dtbo_metadata | 46 --------------- src/usr/lib/rsetup/tui/main.sh | 2 + 5 files changed, 63 insertions(+), 60 deletions(-) rename src/usr/lib/rsetup/mod/{dtbo_compatible => dtbo_is_compatible} (87%) create mode 100755 src/usr/lib/rsetup/mod/parse_dtbo delete mode 100755 src/usr/lib/rsetup/mod/parse_dtbo_metadata diff --git a/src/usr/lib/rsetup/cli/u-boot-menu.sh b/src/usr/lib/rsetup/cli/u-boot-menu.sh index 167f1b84..10dd9723 100644 --- a/src/usr/lib/rsetup/cli/u-boot-menu.sh +++ b/src/usr/lib/rsetup/cli/u-boot-menu.sh @@ -3,9 +3,6 @@ # shellcheck source=src/usr/lib/rsetup/mod/overlay.sh source "/usr/lib/rsetup/mod/overlay.sh" -PARSE_DTBO_METADATA="/usr/lib/rsetup/mod/parse_dtbo_metadata" -DTBO_IS_COMPATIBLE="/usr/lib/rsetup/mod/dtbo_compatible" - ALLOWED_RCONFIG_FUNC+=("load_u-boot_setting") check_overlay_conflict_init() { @@ -135,13 +132,3 @@ rebuild_overlays() { mv "$old_overlays" "${old_overlays}_old" mv "$new_overlays" "$old_overlays" } - -parse_dtbo() { - local keyword="$1" default="$2" Full="$3" - shift 3 - "$PARSE_DTBO_METADATA" -c "$keyword" -e "$default" "$Full" -f "$@" -} - -dtbo_is_compatible() { - "$DTBO_IS_COMPATIBLE" "$@" -} diff --git a/src/usr/lib/rsetup/mod/dtbo_compatible b/src/usr/lib/rsetup/mod/dtbo_is_compatible similarity index 87% rename from src/usr/lib/rsetup/mod/dtbo_compatible rename to src/usr/lib/rsetup/mod/dtbo_is_compatible index 661b74e1..eb6084c5 100755 --- a/src/usr/lib/rsetup/mod/dtbo_compatible +++ b/src/usr/lib/rsetup/mod/dtbo_is_compatible @@ -23,5 +23,8 @@ yaml.CLoader.add_constructor('!u8', yaml.constructor.FullConstructor.construct_y for file in files: 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"] - if is_compatible(file,metadata,compatible): + try: + if is_compatible(file, metadata, compatible): + print(file) + except KeyError: print(file) diff --git a/src/usr/lib/rsetup/mod/parse_dtbo b/src/usr/lib/rsetup/mod/parse_dtbo new file mode 100755 index 00000000..57450218 --- /dev/null +++ b/src/usr/lib/rsetup/mod/parse_dtbo @@ -0,0 +1,57 @@ +#!/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]: + print("OFF") + else: + print("ON") +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('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) diff --git a/src/usr/lib/rsetup/mod/parse_dtbo_metadata b/src/usr/lib/rsetup/mod/parse_dtbo_metadata deleted file mode 100755 index 6ede3ea9..00000000 --- a/src/usr/lib/rsetup/mod/parse_dtbo_metadata +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: UTF-8 -*- - -from sys import argv, stdin, stderr -import yaml, re, os, argparse - -parser = argparse.ArgumentParser(description='Simulate script command with custom options.') -parser.add_argument('-F', action='store_true', default=False, help='Print full info') -parser.add_argument('-S', action='store_true', default=False, help='Print short info') -parser.add_argument('-f', nargs='+', metavar='filename', help='DTBO Filenamelist') -parser.add_argument('-e', metavar='string', default="null", help='error default string') -parser.add_argument('-c', metavar='string', default="title", help='Keyword') - -args = parser.parse_args() - -yaml.CLoader.add_constructor('!u8', yaml.constructor.FullConstructor.construct_yaml_seq) -if args.F: - for file in args.f: - 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.c][0].replace("\0", "\n")) - if ".disabled" in file: - print("OFF") - else: - print("ON") - print(re.match(r'(.+\.dtbo)',os.path.basename(file)).group(1)) - except Exception as e: - if args.e == "file": - print(re.match(r'(.+\.dtbo)',os.path.basename(file)).group(1)) - else: - print(args.e) - if ".disabled" in file: - print("OFF") - else: - print("ON") - print(re.match(r'(.+\.dtbo)',os.path.basename(file)).group(1)) -elif args.S: - for file in args.f: - 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.c][0].replace("\0", "\n")) - except Exception as e: - if args.e == "file": - print(re.match(r'(.+\.dtbo)',os.path.basename(file)).group(1)) - else: - print(args.e) diff --git a/src/usr/lib/rsetup/tui/main.sh b/src/usr/lib/rsetup/tui/main.sh index ab112a27..81e8c875 100644 --- a/src/usr/lib/rsetup/tui/main.sh +++ b/src/usr/lib/rsetup/tui/main.sh @@ -11,6 +11,8 @@ source "/usr/lib/rsetup/tui/system/system.sh" source "/usr/lib/rsetup/tui/task/task.sh" source "/usr/lib/rsetup/tui/user/user.sh" +export PATH="$PATH:/usr/lib/rsetup/mod" + if $DEBUG then source "/usr/lib/rsetup/tui/test/test.sh"