Commit 19c23cce authored by Lachlan's avatar Lachlan

Update token file processing with filename time logic.

parent 8658badb
......@@ -28,6 +28,8 @@ import ntpath
import tempfile
import glob
import shutil
import operator
import datetime
from distutils.file_util import copy_file
......@@ -86,13 +88,13 @@ def update_run_token(token_file, results_files):
# Check if results exist and get the last generated one
if os.path.isdir(results_files):
list_of_files = []
file_times = {}
for file in os.listdir(results_files):
if file.endswith('.json'):
list_of_files.append(os.path.join(results_files, file))
if list_of_files:
latest_file = max(list_of_files, key=os.path.getmtime)
file_times[os.path.join(results_files, file)] = datetime.datetime.strptime(os.path.basename(file), 'results-%Y-%m-%d-%H:%M:%S.json'))
if file_times:
latest_file = max(file_times.items(), key=operator.itemgetter(1))[0]
archive_result = ntpath.basename(latest_file)
else:'No results files found from: ', results_files)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment