00001 #!/usr/local/bin/python 00002 # 00003 # Copyright 2002 00004 # by 00005 # The Board of Trustees of the 00006 # Leland Stanford Junior University. 00007 # All rights reserved. 00008 # 00009 00010 __facility__ = "Online" 00011 __abstract__ = "Test for suite summary" 00012 __author__ = "S. Tuvi <stuvi@SLAC.Stanford.edu> SLAC - GLAST LAT I&T/Online" 00013 __date__ = "11/21/2002" 00014 __version__ = "$Revision: 1.1 $" 00015 __credits__ = "SLAC" 00016 00017 import LATTE.copyright_SLAC 00018 00019 import threading 00020 import logging as log 00021 from LATTE.runcontrol.rcTransitions import rcTransitions 00022 from LATTE.runcontrol.ArgumentImpl import ArgumentImpl 00023 from LATTE.runcontrol.rcComplStatus import rcCompletionStatus 00024 import time 00025 00026 from support.SimpleGasuExample import * 00027 from support.MiniGLTExample import * 00028 00029 # This class puts up a GUI for inputting a value of some sort. It is used by 00030 # the userApplication example to get the number of self triggers to take. 00031 class userArgument(ArgumentImpl): 00032 "GUI for getting the user to input some sort of value." 00033 def __init__(self, parent = None, name = None, modal = 0, fl = 0): 00034 ArgumentImpl.__init__(self, parent, name, modal, fl) 00035 self.__value = 0 00036 self.setCaption("Hello world!") 00037 00038 def OKButtonClicked(self): 00039 self.__value = int(self.ArgumentList.text().latin1()) 00040 self.close() 00041 00042 def CancelButtonClicked(self): 00043 self.__value = None 00044 self.close() 00045 00046 def getValue(self, caption): 00047 self.setCaption(caption) 00048 self.show() 00049 self.exec_loop() 00050 return self.__value 00051 00052 class userArgText(object): 00053 "Text user interface for getting the user to input some sort of value" 00054 def __init__(self): 00055 pass 00056 00057 def getValue(self, caption): 00058 return int(raw_input("%s: " % (caption))) 00059 00060 00061 # Example application implementation. 00062 # Note that the name of the class must be userApplication. 00063 # Look at rcTransitions for names of other transition methods that can be used. 00064 class userApplication(rcTransitions): 00065 "Implmentation class for a user application" 00066 def __init__(self, rc, userId, debug): 00067 rcTransitions.__init__(self, rc, userId, debug) 00068 log.debug("userApplication.__init__()") 00069 self.__cmdSynchSem = threading.Semaphore(0) 00070 00071 def getName(self): 00072 return __name__ 00073 00074 def setup(self): 00075 log.debug("userApplication.setup()") 00076 00077 # A state transition can be rejected by not returning None 00078 return None 00079 00080 def startRun(self): 00081 log.debug("userApplication.startRun()") 00082 00083 # A state transition can be rejected by not returning None 00084 return None 00085 00086 def stopRun(self): 00087 log.debug("userApplication.stopRun()") 00088 00089 cStatus = self.getSessionVar("completionStatus") 00090 log.info("Setting suite summary completion status to : %s" 00091 % rcCompletionStatus().getCompletionStatusStr(cStatus)) 00092 self.setCompletionStatus(cStatus) 00093 00094 # The STOP_RUN transition can not be rejected 00095 00096 def resume(self): 00097 log.debug("userApplication.resume()") 00098 00099 # Issue self trigger to make up for the one that was lost during PAUSE 00100 self.trigger().solicit() 00101 00102 return None 00103 00104 def stop(self): 00105 log.debug("userApplication.stop()") 00106 return self.stopRun() 00107 00108 def commandSynch(self): 00109 "Method called by the command synchronization task" 00110 00111 # Get out of waiting when in batch or standalone mode 00112 self.sync() 00113 00114 # execute the GUI functions for stopRun, just in case 00115 if not self.isRunFromSuite(): 00116 if self.rc is not None: 00117 self.rc.doStop() 00118 00119 def wait(self): 00120 self.__cmdSynchSem.acquire() 00121 00122 def sync(self): 00123 if __name__ == "__main__" or self.isRunFromSuite(): 00124 self.__cmdSynchSem.release() 00125 00126 00127 # Standalone mode: 00128 if __name__ == "__main__": 00129 log.basicConfig() 00130 log.getLogger("").setLevel(log.DEBUG) 00131 ua = userApplication(None, 321, 0) 00132 ua.rcSetup('../repos/simpleTemSchema.xml') # Use env var later: kludge for now 00133 ua.rcStartRun() 00134 ua.wait() 00135 ua.rcStopRun() 00136 ua.rcTeardown()