From 0586d02ff37d807545c77f6960e1997166c95f8d Mon Sep 17 00:00:00 2001
From: Hass AbouZeid <hass.abouzeid@cern.ch>
Date: Thu, 15 Jun 2017 12:17:14 +0000
Subject: [PATCH] Merge branch '21.0-fixRunTier0Bug' into '21.0'

Fix issue in RunTier0Tests when looking for most recent nightly

See merge request !2673

Former-commit-id: daf2bdd08a29062c26bf1f7ca224615b6f21fbb8
---
 Tools/PROCTools/python/RunTier0Tests.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/Tools/PROCTools/python/RunTier0Tests.py b/Tools/PROCTools/python/RunTier0Tests.py
index d950780fe5d..ede89eef287 100755
--- a/Tools/PROCTools/python/RunTier0Tests.py
+++ b/Tools/PROCTools/python/RunTier0Tests.py
@@ -11,6 +11,7 @@ import threading
 import time
 import uuid
 import logging
+import glob
 
 ### Setup global logging
 logging.basicConfig(level=logging.INFO,
@@ -86,9 +87,9 @@ def GetReleaseSetup():
     release_head=os.environ['Athena_VERSION']
     platform=os.environ['Athena_PLATFORM']
     project=os.environ['AtlasProject']
-    builds_dir='/cvmfs/atlas-nightlies.cern.ch/repo/sw/'+release_base+'/*/'+project+'/'+release_head
-
-    latest_nightly  = subprocess.Popen(['/bin/bash', '-c',"ls -ltr "+builds_dir+" | grep "+release_head], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0].split('/')[-3]
+    builds_dir_searchStr='/cvmfs/atlas-nightlies.cern.ch/repo/sw/'+release_base+'/[!latest_]*/'+project+'/'+release_head
+    # finds all directories matching above search pattern, and sorts by modification time
+    latest_nightly = sorted(glob.glob(builds_dir_searchStr), key=os.path.getmtime)[-1].split('/')[-3]
 
     if current_nightly != latest_nightly:
         logging.info("Please be aware that you are not testing your tags in the latest available nightly, which is "+latest_nightly )
-- 
GitLab