From 32213cdb49a08bd0f2012baaefb031d0726dc4bf Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 18 Feb 2022 16:15:00 +0100 Subject: move dataref export to cli.py --- bin/analyze-archive.py | 10 +--------- bin/analyze-kconfig.py | 10 +--------- lib/cli.py | 12 ++++++++++++ 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/bin/analyze-archive.py b/bin/analyze-archive.py index f48afd8..7fb5719 100755 --- a/bin/analyze-archive.py +++ b/bin/analyze-archive.py @@ -1036,15 +1036,7 @@ if __name__ == "__main__": ) dref["constructor duration"] = (constructor_duration, r"\second") dref["regression duration"] = (fit_duration, r"\second") - with open(args.export_dref, "w") as f: - for k, v in sorted(dref.items()): - if type(v) is not tuple: - v = (v, None) - if v[1] is None: - prefix = r"\drefset{" - else: - prefix = r"\drefset" + f"[unit={v[1]}]" + "{" - print(f"{prefix}/{k}" + "}{" + str(v[0]) + "}", file=f) + dfatool.cli.export_dataref(args.export_dref, dref) if args.export_webconf: if not pta: diff --git a/bin/analyze-kconfig.py b/bin/analyze-kconfig.py index e8b946a..db6cf40 100755 --- a/bin/analyze-kconfig.py +++ b/bin/analyze-kconfig.py @@ -330,15 +330,7 @@ def main(): ) dref["constructor duration"] = (constructor_duration, r"\second") dref["regression duration"] = (fit_duration, r"\second") - with open(args.export_dref, "w") as f: - for k, v in sorted(dref.items()): - if type(v) is not tuple: - v = (v, None) - if v[1] is None: - prefix = r"\drefset{" - else: - prefix = r"\drefset" + f"[unit={v[1]}]" + "{" - print(f"{prefix}/{k}" + "}{" + str(v[0]) + "}", file=f) + dfatool.cli.export_dataref(args.export_dref, dref) if args.config: kconf = kconfiglib.Kconfig(args.kconfig_path) diff --git a/lib/cli.py b/lib/cli.py index 1ee1f33..3e7865b 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -143,6 +143,18 @@ def model_quality_table(header, result_lists, info_list): print(buf) +def export_dataref(dref_file, dref): + with open(dref_file, "w") as f: + for k, v in sorted(dref.items()): + if type(v) is not tuple: + v = (v, None) + if v[1] is None: + prefix = r"\drefset{" + else: + prefix = r"\drefset" + f"[unit={v[1]}]" + "{" + print(f"{prefix}/{k}" + "}{" + str(v[0]) + "}", file=f) + + def add_standard_arguments(parser): parser.add_argument( "--export-dref", -- cgit v1.2.3