3480a5c52ee775f2e58e0e15fbfd63877117b6f6
gperez2
  Tue Jan 10 14:36:57 2023 -0800
Code review change for the try/except block to create a directory, refs #30461

diff --git src/utils/qa/searchedTermsCron.py src/utils/qa/searchedTermsCron.py
index a8704d2..fac1ee1 100755
--- src/utils/qa/searchedTermsCron.py
+++ src/utils/qa/searchedTermsCron.py
@@ -26,33 +26,33 @@
 
 def bash(cmd):
     """Input bash cmd and return stdout"""
     rawOutput = subprocess.run(cmd,check=True, shell=True, stdout=subprocess.PIPE, universal_newlines=True)
     return(rawOutput.stdout.split('\n')[0:-1])
 
 #Get the last 5 error logs from the RR/euro
 latestLogs=bash("ls /hive/data/inside/wwwstats/RR/2022/hgw1")
 latestLogs_euro=bash("ls /hive/data/inside/wwwstats/euroNode/2022/")
 latestLogs = latestLogs[len(latestLogs)-5:]
 latestLogs_euro=latestLogs_euro[len(latestLogs_euro)-5:]
 
 #Make a directory for the month (Y-M) 
 try:
    os.makedirs("/hive/users/qateam/searchedTermsCronArchive/"+datetime.now().strftime("%Y-%m"))
-except subprocess.CalledProcessError:
+except OSError:
         print("mkdir: cannot create directory /hive/users/qateam/searchedTermsCronArchive/"+datetime.now().strftime("%Y-%m")+": File exists")
-        quit()
+        sys.exit(1)
 
 #Nodes to check for error logs
 nodes = ['RR', 'asiaNode', 'euroNode']
 machines = ['hgw1','hgw2'] #Add hgw machines to check
 
 #For loop that goes through the RR/euro/asia error logs, trims down the hgSearch line, and writes to a file
 for node in nodes:
     with open('/hive/users/qateam/searchedTermsCronArchive/'+datetime.now().strftime("%Y-%m")+'/hgSearchTrimLogs', 'a') as f:
         if node == 'RR':
             for machine in machines:
                 for log in latestLogs:#Copy the 5 latest error logs for each of the rr machines
                     hgSearch=bash("zcat /hive/data/inside/wwwstats/"+node+"/2022/"+machine+"/"+log+"  | grep 'hgSearch' | tr '?' '\t' | cut -f 2 | grep 'search' | uniq")
                     for i in hgSearch:
                         f.write(i+'\n')
         elif node == 'euroNode':