ab18d0d8e378370ecc459e1b3ec8f5d72996296f lrnassar Wed Aug 28 13:54:21 2024 -0700 Fixing up the run function which began to fail when wget'ing the hgRender image. The arguments going into subprocess were getting mangled. No RM, image comparison cron issue. diff --git src/utils/qa/imageComp.py src/utils/qa/imageComp.py index f28963d..0eb2414 100755 --- src/utils/qa/imageComp.py +++ src/utils/qa/imageComp.py @@ -1,67 +1,75 @@ #!/usr/bin/python import subprocess, os, sys from PIL import Image, ImageChops from datetime import date import getpass # Notes # Currently this only supports a single session comparison # But the logic is there to support any number if the # Output and comparison functions are updated ### Functions -def run(*popenargs, **kwargs): - input = kwargs.pop("input", None) - check = kwargs.pop("handle", False) - - if input is not None: - if 'stdin' in kwargs: - raise ValueError('stdin and input arguments may not both be used.') - kwargs['stdin'] = subprocess.PIPE - - process = subprocess.Popen(*popenargs, **kwargs) +def run(command): + """Helper function to execute shell commands.""" try: - stdout, stderr = process.communicate(input) - except: - process.kill() - process.wait() - raise - retcode = process.poll() - if check and retcode: - raise subprocess.CalledProcessError( - retcode, process.args, output=stdout, stderr=stderr) + process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = process.communicate() + retcode = process.returncode return retcode, stdout, stderr + except Exception as e: + print("An error occurred while running the command: {}".format(e)) + return -1, None, None def createImageFromSessions(sessionData,saveDir,serverUrl): '''Function used to query all sessions on hgcentral''' processedSessionData = sessionData[1].split("\n")[:-1] imageFiles = [] for session in processedSessionData[2:]: userName = session.split('\t')[0] sessionName = session.split('\t')[1] run(["wget","--output-file=/dev/null", "--output-document="+saveDir+"/"+userName+"."+sessionName+"-"+str(date.today())+".png", serverUrl+"/cgi-bin/hgRenderTracks?hgS_doOtherUser=submit&hgS_otherUserName="+userName+"&hgS_otherUserSessionName="+sessionName]) imageFiles.append(userName+"."+sessionName+"-"+str(date.today())+".png") return(imageFiles) def createImageFromSession(userName, sessionName, saveDir, serverUrl): - '''Function for extacting only a single session''' - run(["wget","--output-file=/dev/null", "--output-document="+saveDir+"/"+userName+"."+sessionName+"-"+str(date.today())+".png", serverUrl+"/cgi-bin/hgRenderTracks?hgS_doOtherUser=submit&hgS_otherUserName="+userName+"&hgS_otherUserSessionName="+sessionName]) - imageFile = userName+"."+sessionName+"-"+str(date.today())+".png" - return(imageFile) + '''Function for extracting only a single session''' + output_file = "{}/{}.{}-{}.png".format(saveDir, userName, sessionName, date.today()) + url = "{}/cgi-bin/hgRenderTracks?hgS_doOtherUser=submit&hgS_otherUserName={}&hgS_otherUserSessionName={}".format( + serverUrl, userName, sessionName + ) + + command = [ + "wget", + "--output-file=/dev/null", # Suppresses wget's output to a file named /dev/null (discarded) + "--output-document=" + output_file, # Specify output document (the image) + url + ] + + #For debugging +# print("Command to be executed:", command) # Debug print statement + + # Execute the command + retcode, stdout, stderr = run(command) + + if retcode != 0: + print("Error downloading the image: {}".format(stderr)) + + return "{}.{}-{}.png".format(userName, sessionName, date.today()) def populateServerDir1checkExist(userName,sessionName,serverDir1,serverUrl1): '''Creates all the image files for server 1 sessions if they do not exist in directory''' if os.path.exists(serverDir1) and os.path.isdir(serverDir1): if not os.listdir(serverDir1): print("No server one images found, populating directory") createImageFromSession(userName,sessionName,serverDir1,serverUrl1) else: print("Archive images found") else: sys.exit("Sever one directory given does not exist") def populateServerDir1(userName,sessionName,serverDir1,serverUrl1): '''Creates all the image files for server 1 regardless of existence or not''' if os.path.exists(serverDir1) and os.path.isdir(serverDir1):