예제 #1
0
def installProgram(programName, useCache):
  """
  Build the docker image associated with a program and create a tiny executable to add that image to your path.
  """
  print("Installing {0} ...".format(programName))

  dockerImageDir = os.path.join(paths.getProgramSrcDir(programName), "docker-image")
  _DockerfilePath = os.path.join(dockerImageDir, 'Dockerfile')
  # Check if we use a 'Dockerfile' or a 'MakeBaseImage.sh'
  if os.path.isfile(paths.getMakeBaseImageScriptPath(programName)):
    installFromBaseImage(programName, cacheArg)
  elif os.path.isfile(_DockerfilePath):
    if useCache:
      cacheArg = "--no-cache=false"
    else:
      cacheArg = "--no-cache=true"
    docker.runDockerAndExitIfItFails(["build","-rm",cacheArg,"--tag=subuser-"+programName+"",dockerImageDir])
  else:
    sys.exit("No buildfile found: need one of: 'Dockerfile' or 'MakeBaseImage.sh'. PATH: {0}".format(dockerImageDir))

  _permissions = permissions.getPermissions(programName)

  # Create a small executable that just calls the real executable in the docker image.
  if 'executable' in _permissions:
    installExecutable(programName)

  try:
    lastUpdateTime = _permissions["last-update-time"]
  except KeyError:
    lastUpdateTime = installTime.currentTimeString()

  imageID = dockerImages.getImageID("subuser-{0}".format(programName))
  registry.registerProgram(programName, lastUpdateTime, imageID)
예제 #2
0
def getRegistry():
  """ Return a dictionary of the program registry: installed-programs.json
  registered items:
    - last-update-time
    - image-id
    Still Maintaining backwards compat with format: "programName" : "last-update-time",
  """
  programRegistry = {}
  programRegistryPath = paths.getProgramRegistryPath()
  if os.path.exists(programRegistryPath):
    with open(programRegistryPath, 'r') as file_f:
      programRegistry = json.load(file_f)

  #Maintaining backwards compat: to be soon removed
  if len(programRegistry) > 0:
    firstProgramName = programRegistry.keys()[0]
    if not isinstance(programRegistry[firstProgramName], dict):
      programNewRegistry = {}
      for programName, lastUpdateTime in programRegistry.iteritems():
        programNewRegistry[programName] = {}
        programNewRegistry[programName]['last-update-time'] = lastUpdateTime
        programNewRegistry[programName]['image-id'] = dockerImages.getImageID("subuser-"+programName)
      programRegistry = programNewRegistry
      #save the new one here once and for all
      setInstalledPrograms(programRegistry)
  return programRegistry
예제 #3
0
def installProgram(programName, useCache):
  """
  Build the docker image associated with a program and create a tiny executable to add that image to your path.
  """
  print("Installing "+programName+" ...")
  programSrcDir = paths.getProgramSrcDir(programName)
  _DockerfilePath = paths.getDockerfilePath(programSrcDir)
  # Check if we use a 'Dockerfile' or a 'BuildImage.sh'
  if os.path.isfile(paths.getBuildImageScriptPath(programSrcDir)):
    installFromBaseImage(programName,programSrcDir)
  elif os.path.isfile(_DockerfilePath):
    installFromDockerfile(programName,programSrcDir,useCache)
  else:
    sys.exit("No buildfile found: There needs to be a 'Dockerfile' or a 'BuildImage.sh' in the docker-image directory.")

  _permissions = permissions.getPermissions(programName)

  # Create a small executable that just calls the real executable in the docker image.
  if 'executable' in _permissions:
    installExecutable(programName)

  try:
    lastUpdateTime = _permissions["last-update-time"]
  except KeyError:
    lastUpdateTime = installTime.currentTimeString()

  imageID = dockerImages.getImageID("subuser-"+programName)
  registry.registerProgram(programName, lastUpdateTime, imageID)
예제 #4
0
파일: registry.py 프로젝트: rnauber/subuser
def getRegistry():
    """ Return a dictionary of the program registry: installed-programs.json
  registered attributes:
    - last-update-time
    - image-id
    - installed-from

See docs/installed-programs-dot-json-file-format.md

  """
    programRegistry = {}
    programRegistryPath = paths.getProgramRegistryPath()
    if os.path.exists(programRegistryPath):
        with open(programRegistryPath, 'r') as file_f:
            programRegistry = json.load(file_f)

    #Maintaining backwards compat: to be soon removed
    if len(programRegistry) > 0:
        firstProgramName = programRegistry.keys()[0]
        if not isinstance(programRegistry[firstProgramName], dict):
            newProgramRegistry = {}
            for programName, lastUpdateTime in programRegistry.iteritems():
                newProgramRegistry[programName] = {}
                newProgramRegistry[programName][
                    'last-update-time'] = lastUpdateTime
                newProgramRegistry[programName][
                    'image-id'] = dockerImages.getImageID("subuser-" +
                                                          programName)
            programRegistry = newProgramRegistry
            #save the new one here once and for all
            setInstalledPrograms(programRegistry)
    return programRegistry