The latest version of this document can be found at www.broad.ology.org.uk/amiga/proaction/00_Starting_ProAction.html
1: #!python 2: # 3: ################################################################ 4: # 5: # Anatomy of a ProAction Application. 6: # 7: # 00_Starting_ProAction.py 8: # 9: # Detecting and starting the GUI Server as required 10: # 11: ################################################################ 12: # 13: # 14: 15: import sys 16: import os 17: import arexx 18: 19: 20: # 21: # ErrorExit() throws up an RequestChoice notification to indicate 22: # a critical error. 23: # 24: 25: def ErrorExit(msg): 26: # Build our command as a string. 27: # We can use sys.argv[0] for the script name to make thsi more reusable. 28: command = "RequestChoice TYPE "ERROR" "" + sys.argv[0] + "" "" + msg + "" "OK" >NIL:" 29: # Call the command via the os.system() 30: os.system(command) 31: exit() 32: 33: # 34: # The support GetPorts() returns a list of public MsgPorts 35: # as a string 36: # 37: 38: 39: def GetPorts(): 40: # Depending on the version of python we may have a useful 41: # function that retuns just what we need, so we use the try 42: # except syntax to test. 43: 44: try: 45: ports = os.getports() 46: ports = " ".join(ports) 47: except AttributeError: 48: # The getports function wasn't present so we call the REXX 49: # equivalent. 50: (rc,rc2,ports) = arexx.dorexx("REXX","return show('P')") 51: if rc != 0: 52: # We couldn't even call REXX somwthing serioiusly up here 53: # Bail out with a requester. 54: ErrorExit("Couldn't Find ARexx!") 55: return ports 56: 57: 58: # Now we need to check that ProAction is present an available to us, 59: # So first get a list of active ports 60: 61: ports = GetPorts() 62: 63: # Then check for ProActions port which will be "PROACTION". 64: # Port names are case sensitive. 65: 66: if -1 == ports.find("PROACTION"): 67: # No ProAction start it 68: os.system("RUN >"T:proactionpid" *>NIL: APPDIR:PROACTION") 69: os.system("C:WaitForPort PROACTION") 70: # Now check again 71: ports = GetPorts() 72: if -1 == ports.find("PROACTION"): 73: # Still not there :-( 74: ErrorExit("Unable to start or find ProAction GUIServer") 75: 76: 77: # Okay we should be good to go now 78: