From 96fe1275edaa38f3a117db037c6964bd936717dd Mon Sep 17 00:00:00 2001
From: Karim Ahmed <karim.ahmed@xfel.eu>
Date: Fri, 9 Aug 2019 11:16:32 +0200
Subject: [PATCH] get oldest file's timestamp

---
 cal_tools/cal_tools/tools.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/cal_tools/cal_tools/tools.py b/cal_tools/cal_tools/tools.py
index 363dd51c8..4212ee96f 100644
--- a/cal_tools/cal_tools/tools.py
+++ b/cal_tools/cal_tools/tools.py
@@ -425,7 +425,7 @@ def get_notebook_name():
         return environ.get("CAL_NOTEBOOK_NAME", "Unknown Notebook")
 
 
-def get_dir_creation_date(directory, run):
+def get_dir_creation_date(directory, run, tsdir=False):
     """
     Return modification time of [directory]/[run]04
 
@@ -433,8 +433,14 @@ def get_dir_creation_date(directory, run):
     :param run: run number
     :return: (datetime) modification time
     """
-    creation_time = stat("{}/r{:04d}".format(directory, run)).st_mtime
-    creation_time = datetime.datetime.fromtimestamp(creation_time)
+    if tsdir:
+        creation_time = stat("{}/r{:04d}".format(directory, run)).st_mtime
+    else:
+        rfiles = glob("{}/r{:04d}/*.h5".format(directory, run))
+        rfiles.sort(key=path.getmtime)
+        creation_time = stat(rfiles[0]).st_mtime
+
+    creation_time = datetime.datetime.fromtimestamp(creation_time)     
     return creation_time
 
 
-- 
GitLab