# # Get CODA run status from RCDB database # from org.csstudio.opibuilder.scriptUtil import PVUtil from org.csstudio.opibuilder.scriptUtil import WidgetUtil from org.csstudio.opibuilder.scriptUtil import ConsoleUtil from org.csstudio.utility.pv import PVFactory import re import os import sys import os.path import time import subprocess import threading from java.lang import Thread, Runnable class StatusGettingTaskClass(Runnable): def __init__(self, pvList, wid ) : self.widget = wid self.pvs = pvList return def run(self): try: appFolder = os.environ['APP'] scriptFolder = appFolder + "/scripts/MISC/" runNumber = int( PVUtil.getDouble( self.pvs[0] ) ) # Define the command and its arguments as a list (safer) command_list = ["ls", "-l"] command_list = [ scriptFolder + "get_coda_run_status.py", "GlueX_2come" , str(runNumber) ] # Use Popen to manage the process, directing stdout to a pipe process = subprocess.Popen(command_list, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Use communicate() to send input (if needed) and read data from stdout and stderr stdout_data, stderr_data = process.communicate() # ConsoleUtil.writeInfo( "Output is " + stdout_data ) statusValue = int(stdout_data) if (statusValue == -1): self.widget.setPropertyValue( "text", "OK" ) elif (statusValue == 0): self.widget.setPropertyValue( "text", "JUNK" ) elif (statusValue == 1): self.widget.setPropertyValue( "text", "GOOD" ) else: self.widget.setPropertyValue( "text", "ERROR" ) except ValueError: self.widget.setPropertyValue( "text", "ERROR" ) except Exception, e: ConsoleUtil.writeInfo( "There was a problem : " + str(e)) raise e # finally: # ConsoleUtil.writeInfo( "Finally" ) return # Create an object that will set the status taskObject = StatusGettingTaskClass( pvs, widget ) # Create thread that will run the object to set the status statusThread = Thread( taskObject ) # Run the thread statusThread.start()