Package TEES :: Package Tools :: Module Tool
[hide private]

Source Code for Module TEES.Tools.Tool

  1  import sys, os 
  2  sys.path.append(os.path.dirname(os.path.abspath(__file__))+"/..") 
  3  import Utils.Menu 
  4  import Utils.Settings as Settings 
  5   
6 -def finalizeInstall(programs, testCommand={}, programDir=None, settings={}, updateLocalSettings=False):
7 if checkPrograms(programs, testCommand, programDir): 8 setVariable = updateLocalSettings 9 else: 10 print >> sys.stderr, "All programs may not have been installed correctly" 11 print >> sys.stderr, "Do not use the following settings if not sure:" 12 setVariable = False 13 for key in sorted(settings.keys()): 14 Settings.setLocal(key, settings[key], setVariable)
15
16 -def checkReturnCode(code):
17 if code != 0: 18 print >> sys.stderr, "*** Non-zero return code", str(code) + ", program may not be working." 19 return False 20 else: 21 print >> sys.stderr, "*** Return code", str(code) + ", program appears to be working." 22 return True
23
24 -def checkPrograms(programs, testCommand={}, programDir=None, combineResults=True):
25 if testCommand == None: 26 testCommand = {} 27 if programDir != None: 28 cwd = os.getcwd() 29 os.chdir(programDir) 30 status = {} 31 for program in programs: 32 print >> sys.stderr, "*** Testing", program, "..." 33 command = program + " -v" 34 if program in testCommand: 35 command = testCommand[program] 36 status[program] = checkReturnCode(os.system(command)) 37 if programDir != None: 38 os.chdir(cwd) 39 if combineResults: 40 return not False in status.values() 41 else: 42 return status
43
44 -def testPrograms(dependentProgramName, programs, testCommand={}):
45 print >> sys.stderr, "Testing programs", programs 46 # check program status 47 status = checkPrograms(programs, testCommand, combineResults=False) 48 # if there is a problem, show a menu 49 if False in status.values(): 50 menu = Utils.Menu.Menu("Missing programs", "", 51 [Utils.Menu.Option("r", "Retry and check again program status"), 52 Utils.Menu.Option("c", "Continue"), 53 Utils.Menu.Option("q", "Quit", isDefault=True, handler=sys.exit, handlerArgs=[1])], 54 addToSystem=False, initializer=initProgramTestMenu) 55 menu.status = status # no need to check on the first show of the menu 56 while menu.prevChoice == None or menu.prevChoice == "r": 57 menu.programName = dependentProgramName 58 menu.programs = programs 59 menu.testCommand = testCommand 60 menu.show() 61 menu.status = None
62
63 -def initProgramTestMenu(menu, prevMenu):
64 # Check program status if this hasn't been done yet 65 if menu.status == None: 66 menu.status = checkPrograms(menu.programs, menu.testCommand, combineResults=False) 67 # Explain situation 68 if False in menu.status.values(): 69 if menu.system.auto: 70 menu.setDefault("q") # avoid getting in a loop 71 else: 72 menu.setDefault("r") 73 menu.text = """ 74 Some programs required for installing MAIN_PROGRAM may not be present. 75 The current status of required programs is: 76 77 """ 78 else: # ready to continue 79 menu.setDefault("c") 80 menu.text = """ 81 All programs required for installing MAIN_PROGRAM are present. 82 The current status of required programs is: 83 84 """ 85 # Show program status 86 for program in menu.programs: 87 menu.text += program 88 if menu.status[program]: 89 menu.text += ":OK " 90 else: 91 menu.text += ":ERROR " 92 # Recommend option 93 if False in menu.status.values(): 94 menu.text += """ 95 96 These programs are most likely available through your operating system's 97 package manager. You can leave this configuration program open, while you 98 install the missing components. Afterwards, check the status again (r). 99 100 You can also continue installing directly (c), but then it may not be 101 possible to install MAIN_PROGRAM. 102 """ 103 else: 104 menu.text += """ 105 106 Please continue installation by choosing (c). 107 """ 108 menu.text = menu.text.replace("MAIN_PROGRAM", menu.programName)
109