#**************************************************************************
#|| SiMa.ai CONFIDENTIAL ||
#|| Unpublished Copyright (c) 2024 SiMa.ai, All Rights Reserved. ||
#**************************************************************************
# NOTICE: All information contained herein is, and remains the property of
# SiMa.ai. The intellectual and technical concepts contained herein are
# proprietary to SiMa and may be covered by U.S. and Foreign Patents,
# patents in process, and are protected by trade secret or copyright law.
#
# Dissemination of this information or reproduction of this material is
# strictly forbidden unless prior written permission is obtained from
# SiMa.ai. Access to the source code contained herein is hereby forbidden
# to anyone except current SiMa.ai employees, managers or contractors who
# have executed Confidentiality and Non-disclosure agreements explicitly
# covering such access.
#
# The copyright notice above does not evidence any actual or intended
# publication or disclosure of this source code, which includes information
# that is confidential and/or proprietary, and is a trade secret, of SiMa.ai.
#
# ANY REPRODUCTION, MODIFICATION, DISTRIBUTION, PUBLIC PERFORMANCE, OR PUBLIC
# DISPLAY OF OR THROUGH USE OF THIS SOURCE CODE WITHOUT THE EXPRESS WRITTEN
# CONSENT OF SiMa.ai IS STRICTLY PROHIBITED, AND IN VIOLATION OF APPLICABLE
# LAWS AND INTERNATIONAL TREATIES. THE RECEIPT OR POSSESSION OF THIS SOURCE
# CODE AND/OR RELATED INFORMATION DOES NOT CONVEY OR IMPLY ANY RIGHTS TO
# REPRODUCE, DISCLOSE OR DISTRIBUTE ITS CONTENTS, OR TO MANUFACTURE, USE, OR
# SELL ANYTHING THAT IT MAY DESCRIBE, IN WHOLE OR IN PART.
#
#**************************************************************************
import os
import datetime
from pathlib import Path
[docs]
def find_latest_file_string(root_path: str, tag_str: str='.onnx') -> str:
''' Recursively find the most recent 'tag_str' file in the specified path and
parse it.
This function is used to find the most recent output files of a subcommand
in order to post-process the outputs.
'''
most_recent_dt = None
most_recent_file = None
for f_dir, f_subdirs, f_names in os.walk(root_path):
for f in [fx for fx in f_names if tag_str in fx]:
visit_file = os.path.join(f_dir, f)
m_time = os.path.getmtime(visit_file)
# convert timestamp into DateTime object
dt_m = datetime.datetime.fromtimestamp(m_time)
if not most_recent_dt:
most_recent_dt = dt_m
most_recent_file = visit_file
else:
if dt_m > most_recent_dt:
most_recent_dt = dt_m
most_recent_file = visit_file
return most_recent_file