00001 #!/usr/local/bin/python 00002 # 00003 # Copyright 2005 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__ = "Application for testing rejecting of transitions" 00012 __author__ = "R. Claus <Claus@SLAC.Stanford.edu> SLAC - GLAST LAT I&T/Online" 00013 __date__ = "February 1, 2005" # Created 00014 __version__ = "$Revision: 1.1 $" 00015 __release__ = "$Name: R04-12-00 $" 00016 __credits__ = "SLAC" 00017 00018 import LATTE.copyright_SLAC 00019 00020 from qt import qApp 00021 00022 import threading 00023 import logging as log 00024 00025 from LATTE.runcontrol.rcTransitions import rcTransitions 00026 from LATTE.runcontrol.ArgumentImpl import ArgumentImpl 00027 00028 from support.SimpleGasuExample import * 00029 from support.MiniGLTExample import * 00030 00031 00032 # This class puts up a GUI for inputting a value of some sort. It is used by 00033 # the userApplication example to get the number of self triggers to take. 00034 class userArgument(ArgumentImpl): 00035 "GUI for getting the user to input some sort of value." 00036 def __init__(self, parent = None, name = None, modal = 0, fl = 0): 00037 ArgumentImpl.__init__(self, parent, name, modal, fl) 00038 self.__value = 0 00039 self.setCaption("Enter value:") 00040 00041 def CancelButtonClicked(self): 00042 self.__value = None 00043 self.close() 00044 00045 00046 class userArgText(object): 00047 "Text user interface for getting the user to input some sort of value" 00048 def __init__(self): 00049 pass 00050 00051 def getValue(self, caption, value = None): 00052 if value is None: 00053 ans = raw_input("%s: " % (caption)) 00054 if ans == '': return None 00055 return int(ans) 00056 else: 00057 ans = raw_input("%s[%s]: " % (caption, str(value))) 00058 if ans == '': return value 00059 return int(ans) 00060 00061 00062 # Null application implementation. 00063 class userApplication(rcTransitions): 00064 "Implmentation class for Null application" 00065 def __init__(self, rc, userId, debug): 00066 rcTransitions.__init__(self, rc, userId, debug) 00067 self.__state = 1 00068 self.__doneOnce = False 00069 00070 def getName(self): 00071 return __name__ 00072 00073 def setup(self): 00074 log.debug("userApplication.setup()") 00075 00076 self.__doneOnce = False 00077 00078 if self.rc is None: 00079 self.__arg = userArgText() 00080 else: 00081 self.__arg = self.rc.createGUI(userArgument, self.rc, self.getName(), 1) 00082 00083 caption = "Select when to reject the transition:\n 1 = Setup\n 2 = StartRun\n 3 = StopRun\n 4 = Teardown\n 5 = Pause\n 6 = Resume\n 7 = Stop\n\n" 00084 if self.rc is None: 00085 self.__state = self.__arg.getValue(caption, self.__state) 00086 else: 00087 self.__state = self.rc.execGUImethod(self.__arg.getValue, caption, self.__state) 00088 00089 if not self.__doneOnce and self.__state == 1: 00090 self.__doneOnce = True 00091 print 00092 print "Rejecting the SETUP transition - Should end up in RESET state" 00093 print 00094 return self.__state 00095 00096 # Two choices for the trigger, GEM and MiniGLT 00097 if self.lat.existsGEM(): 00098 self.trigger( SimpleGasuExample() ) 00099 else: 00100 self.trigger( MiniGLTExample() ) 00101 00102 # A state transition can be rejected by not returning None 00103 return None 00104 00105 def startRun(self): 00106 log.debug("userApplication.startRun()") 00107 00108 if not self.__doneOnce and self.__state == 2: 00109 self.__doneOnce = True 00110 print 00111 print "Rejecting the START_RUN transition - Should end up in STOPPED state" 00112 print 00113 return self.__state 00114 00115 # A state transition can be rejected by not returning None 00116 return None 00117 00118 def stopRun(self): 00119 log.debug("userApplication.stopRun()") 00120 00121 # Set the test completion status value 00122 self.setCompletionStatus(self.COMPL_STATUS_PASSED) 00123 00124 if not self.__doneOnce and self.__state == 3: 00125 self.__doneOnce = True 00126 print 00127 print "Can't reject the STOP_RUN transition - Should end up in STOPPED state" 00128 print 00129 return self.__state 00130 00131 # The STOP_RUN transition can not be rejected 00132 00133 def teardown(self): 00134 log.debug("userApplication.teardown()") 00135 00136 if not self.__doneOnce and self.__state == 4: 00137 self.__doneOnce = True 00138 print 00139 print "Rejecting the TEARDOWN transition - Should end up in STOPPED state" 00140 print 00141 return self.__state 00142 00143 def pause(self): 00144 log.debug("userApplication.pause()") 00145 00146 if not self.__doneOnce and self.__state == 5: 00147 self.__doneOnce = True 00148 print 00149 print "Rejecting the PAUSE transition - Should end up in RUNNING state" 00150 print 00151 return self.__state 00152 00153 def resume(self): 00154 log.debug("userApplication.resume()") 00155 00156 if not self.__doneOnce and self.__state == 6: 00157 self.__doneOnce = True 00158 print 00159 print "Rejecting the RESUME transition - Should end up in PAUSED state" 00160 print 00161 return self.__state 00162 00163 # Issue self trigger to make up for the one that was lost during PAUSE 00164 self.trigger().solicit() 00165 00166 def stop(self): 00167 log.debug("userApplication.stop()") 00168 00169 if not self.__doneOnce and self.__state == 7: 00170 self.__doneOnce = True 00171 print 00172 print "Can't reject the STOP transition - Should end up in STOPPED state" 00173 print 00174 return self.__state 00175 00176 return self.stopRun() 00177 00178 00179 # Standalone mode: 00180 if __name__ == "__main__": 00181 import os 00182 import logging as log 00183 log.basicConfig() 00184 log.getLogger("").setLevel(log.DEBUG) 00185 ua = userApplication(None, 321, 0) 00186 prefs = {'datasave': 1, 'datadir':os.path.join(os.environ['ONLINE_ROOT'],'temp')} 00187 ua.setPrefs(prefs) 00188 ua.rcSetup(os.path.join(os.environ['ONLINE_ROOT'], 'repos/simpleTemSchema.xml')) 00189 ua.rcStartRun() 00190 ua.rcStopRun() 00191 ua.rcTeardown() 00192 00193 # History: 00194 # $Log: transitionRejectTest.py,v $ 00195 # Revision 1.1 2005/02/02 00:39:28 claus 00196 # Test rejecting of state transition requests. 00197 # 00198 # Revision 1.1 2004/08/23 21:04:24 claus 00199 # Test exception handling. 00200 # 00201 #