diff --git a/sbysrc/sby.py b/sbysrc/sby.py index 997e134..0deefc1 100644 --- a/sbysrc/sby.py +++ b/sbysrc/sby.py @@ -63,6 +63,7 @@ status_show = args.status status_reset = args.status_reset status_live_csv = args.livecsv status_show_csv = args.statuscsv +status_latest = args.status_latest if status_show or status_reset or status_show_csv: target = workdir_prefix or workdir or sbyfile @@ -94,10 +95,10 @@ if status_show or status_reset or status_show_csv: sys.exit(1) if status_show: - status_db.print_status_summary() + status_db.print_status_summary(status_latest) if status_show_csv: - status_db.print_status_summary_csv(tasknames) + status_db.print_status_summary_csv(tasknames, status_latest) status_db.db.close() @@ -105,6 +106,8 @@ if status_show or status_reset or status_show_csv: print(f"WARNING: --livecsv flag found but not used.") sys.exit(0) +elif status_latest: + print(f"WARNING: --latest flag found but not used.") if sbyfile is not None: diff --git a/sbysrc/sby_cmdline.py b/sbysrc/sby_cmdline.py index 9b3e107..f99c439 100644 --- a/sbysrc/sby_cmdline.py +++ b/sbysrc/sby_cmdline.py @@ -77,6 +77,8 @@ def parser_func(release_version='unknown SBY version'): help="summarize the contents of the status database") parser.add_argument("--statuscsv", action="store_true", dest="statuscsv", help="print the most recent status for each property in csv format") + parser.add_argument("--latest", action="store_true", dest="status_latest", + help="only check statuses from the most recent run of a task") parser.add_argument("--statusreset", action="store_true", dest="status_reset", help="reset the contents of the status database") diff --git a/sbysrc/sby_status.py b/sbysrc/sby_status.py index a6fff5f..26352ec 100644 --- a/sbysrc/sby_status.py +++ b/sbysrc/sby_status.py @@ -347,13 +347,16 @@ class SbyStatusDb: self._reset() self.db.execute("PRAGMA foreign_keys=ON") - def print_status_summary(self): + def print_status_summary(self, latest: bool): tasks, task_properties, task_property_statuses = self.all_status_data() + latest_task_ids = filter_latest_task_ids(tasks) properties = defaultdict(set) uniquify_paths = defaultdict(dict) def add_status(task_property, status): + if latest and task_property["task"] not in latest_task_ids: + return display_name = task_property["name"] if display_name[-1].startswith("$"): @@ -400,7 +403,7 @@ class SbyStatusDb: def all_status_data_joined(self): rows = self.db.execute( """ - SELECT task.name as 'task_name', task.mode, task.workdir, task.created, task_property.kind, + SELECT task.id as 'task_id', task.name as 'task_name', task.mode, task.workdir, task.created, task_property.kind, task_property.src as 'location', task_property.name, task_property.hdlname, task_property_status.status, task_property_status.data, task_property_status.created as 'status_created', task_property_status.id, task_trace.path, task_trace.kind as trace_kind @@ -413,9 +416,10 @@ class SbyStatusDb: return {row["id"]: parse_status_data_row(row) for row in rows} - def print_status_summary_csv(self, tasknames): + def print_status_summary_csv(self, tasknames: list[str], latest: bool): # get all statuses all_properties = self.all_status_data_joined() + latest_task_ids = filter_latest_task_ids(self.all_tasks()) # print csv header csvheader = format_status_data_csvline(None) @@ -426,6 +430,8 @@ class SbyStatusDb: for row, prop_status in all_properties.items(): if tasknames and prop_status['task_name'] not in tasknames: continue + if latest and prop_status['task_id'] not in latest_task_ids: + continue status = prop_status['status'] this_depth = prop_status['data'].get('step') this_kind = prop_status['trace_kind'] @@ -517,3 +523,9 @@ def format_status_data_csvline(row: dict|None) -> str: depth, ] return ','.join("" if v is None else str(v) for v in csv_line) + +def filter_latest_task_ids(all_tasks: dict[int, dict[str]]): + latest: dict[str, int] = {} + for task_id, task_dict in all_tasks.items(): + latest[task_dict["workdir"]] = task_id + return list(latest.values()) diff --git a/tests/statusdb/timeout.sh b/tests/statusdb/timeout.sh index ac06f3d..2d70133 100644 --- a/tests/statusdb/timeout.sh +++ b/tests/statusdb/timeout.sh @@ -3,7 +3,7 @@ set -e python3 $SBY_MAIN -f $SBY_FILE $TASK STATUS_CSV=${WORKDIR}/status.csv -python3 $SBY_MAIN -f $SBY_FILE $TASK --statuscsv | tee $STATUS_CSV +python3 $SBY_MAIN -f $SBY_FILE $TASK --statuscsv --latest | tee $STATUS_CSV if [[ $TASK =~ "_cover" ]]; then wc -l $STATUS_CSV | grep -q '6'