def askToInstallProgram(programName): """ Asks the user if they want to install the given program. If they say yes, install it, if they decline exit.""" if not availablePrograms.available(programName): print(programName+" does not exist.") exit() if raw_input(programName+" is not installed. Do you want to install it now [y/n]?") == "y": utils.subprocessCheckedCall(["subuser","install",programName]) else: exit()
def askToInstallProgram(programName): """ Asks the user if they want to install the given program. If they say yes, install it, if they decline exit.""" if not availablePrograms.available(programName): print(programName + " does not exist.") exit() if raw_input( programName + " is not installed. Do you want to install it now [y/n]?") == "y": utils.subprocessCheckedCall(["subuser", "install", programName]) else: exit()
def installFromBaseImage(programName): makeBaseImageScriptPath = paths.getMakeBaseImageScriptPath(programName) #Report to user while True: sys.stdout.write("""\nATTENTION!!! You have asked to install the <{0}>. Doing so requires that the following shell script be run on your computer. SHELL SCRIPT PATH: <{1}> - Do quit [q] or press ENTER - Do you want to view the full contents of this shell script [v]? - Do you want to continue? (Type "run" to run the shell script) [v/run/q]: """.format(programName, paths.getMakeBaseImageScriptPath(programName))) sys.stdout.flush() try: userInput = sys.stdin.readline().strip() if not userInput: sys.exit("\nOperation aborted. Exiting.") else: break except KeyboardInterrupt: sys.exit("\nOperation aborted. Exiting.") if userInput == "v": with open(makeBaseImageScriptPath, 'r') as file_f: print('\n===================== SCRIPT CODE =====================\n') print(file_f.read()) print('\n===================== END SCRIPT CODE =====================\n') while True: sys.stdout.write("""SHELL SCRIPT PATH: <{0}> - Do quit [q] or press ENTER - Do you want to continue? (Type "run" to run the shell script) [run/q]: """.format(makeBaseImageScriptPath)) sys.stdout.flush() try: userInput = sys.stdin.readline().strip() if userInput != "run": sys.exit("\nOperation aborted. Exiting.") else: break except KeyboardInterrupt: sys.exit("\nOperation aborted. Exiting.") if userInput == "run": #Do the installation via SHELL SCRIPT st = os.stat(makeBaseImageScriptPath) os.chmod(makeBaseImageScriptPath, stat.S_IMODE(st.st_mode) | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) utils.subprocessCheckedCall([makeBaseImageScriptPath])
def runDockerAndExitIfItFails(args): """ Run docker with the given command line arguments. If the command returns a non-zero exit code, exit with an error message. """ checkIfDockerIsSetupProperly() utils.subprocessCheckedCall(["docker"]+args)