Exemplo n.º 1
0
def installFromBaseImage(programName,programSrcDir):
  """
Build a docker base image using a script and then install that base image.
  """
  buildImageScriptPath = paths.getBuildImageScriptPath(programSrcDir)
  print("""\nATTENTION!

  Installing <"""+programName+"""> requires that the following shell script be run on your computer: <"""+buildImageScriptPath+"""> If you do not trust this shell script do not run it as it may be faulty or malicious!

  - 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)
  - To quit, press [q].

  [v/run/Q]: """)
  try:
    userInput = sys.stdin.readline().strip()
  except KeyboardInterrupt:
    sys.exit("\nOperation aborted.  Exiting.")

  if userInput == "v":
    print('\n===================== SCRIPT CODE =====================\n')
    with open(buildImageScriptPath, 'r') as file_f:
      print(file_f.read())
    print('\n===================== END SCRIPT CODE =====================\n')
    return installFromBaseImage(programName,programSrcDir)
  
  if userInput == "run":
    #Do the installation via SCRIPT
    st = os.stat(buildImageScriptPath)
    os.chmod(buildImageScriptPath, stat.S_IMODE(st.st_mode) | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
    subprocessExtras.subprocessCheckedCall([buildImageScriptPath])
    return

  sys.exit("Will not run install script.  Nothing to do.  Exiting.")
Exemplo n.º 2
0
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):
    sys.exit(programName+" does not exist.")
  if raw_input(programName+" is not installed. Do you want to install it now [y/n]?") == "y":
    subprocessExtras.subprocessCheckedCall(["subuser","install",programName])
  else:
    sys.exit()
Exemplo n.º 3
0
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):
        sys.exit(programName + " does not exist.")
    if raw_input(
            programName +
            " is not installed. Do you want to install it now [y/n]?") == "y":
        subprocessExtras.subprocessCheckedCall(
            ["subuser", "install", programName])
    else:
        sys.exit()
Exemplo n.º 4
0
def installFromBaseImage(programName):
  buildImageScriptPath = paths.getBuildImageScriptPath(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.getBuildImageScriptPath(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(buildImageScriptPath, '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(buildImageScriptPath))
      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(buildImageScriptPath)
    os.chmod(buildImageScriptPath, stat.S_IMODE(st.st_mode) | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
    subprocessExtras.subprocessCheckedCall([buildImageScriptPath])
Exemplo n.º 5
0
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()
  subprocessExtras.subprocessCheckedCall(["docker"]+args)
Exemplo n.º 6
0
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. """
    subprocessExtras.subprocessCheckedCall([getDockerExecutable()] + args)
Exemplo n.º 7
0
def runDockerAndExitIfItFails(args,cwd=None):
  """ Run docker with the given command line arguments.  If the command returns a non-zero exit code, exit with an error message. """
  subprocessExtras.subprocessCheckedCall([getAndVerifyDockerExecutable()]+args,cwd=cwd)
Exemplo n.º 8
0
def runGit(args, cwd=None):
    """ Run git with the given command line arguments. """
    return subprocessExtras.subprocessCheckedCall(["git"] + args, cwd=cwd)
Exemplo n.º 9
0
def runGit(args,cwd=None):
  """ Run git with the given command line arguments. """
  return subprocessExtras.subprocessCheckedCall(["git"]+args,cwd=cwd)