示例#1
0
def isInstalledImageUpToDate(installedImage):
    """
  Returns True if the installed image(including all of its dependencies, is up to date.  False otherwise.
  """
    try:
        topImageSource = installedImage.getUser().getRegistry(
        ).getRepositories()[installedImage.getSourceRepoId()][
            installedImage.getImageSourceName()]
    except KeyError:  # Image source not found, therefore updating would be pointless.
        return True

    sourceLineage = getImageSourceLineage(topImageSource)
    installedImageLineage = subuserlib.installedImages.getImageLineage(
        installedImage.getUser(), installedImage.getImageId())
    """print("Installed lineage for image:" + installedImage.getImageSourceName())
  for installedImage in installedImageLineage:
    print("  "+installedImage.getImageSourceName()+"@"+installedImage.getSourceRepoId())
  print("Source lineage for image:" + installedImage.getImageSourceName())
  for imageSource in sourceLineage:
    print("  "+imageSource.getName()+"@"+imageSource.getRepository().getName())"""
    while len(sourceLineage) > 0:
        if not len(installedImageLineage) > 0:
            return False
        imageSource = sourceLineage.pop(0)
        installedImage = installedImageLineage.pop(0)
        sourcesMatch = installedImage.getImageSourceName(
        ) == imageSource.getName() and installedImage.getSourceRepoId(
        ) == imageSource.getRepository().getName()
        lastUpdateTimesMatch = installedImage.getLastUpdateTime(
        ) == imageSource.getPermissions(
        )["last-update-time"] or not imageSource.getPermissions(
        )["last-update-time"]
        if not (sourcesMatch and lastUpdateTimesMatch):
            if not sourcesMatch:
                installedImage.getUser().getRegistry().log(
                    "Depencies changed from " +
                    installedImage.getImageSourceName() + "@" +
                    installedImage.getSourceRepoId() +
                    ".  New depencency is: " + imageSource.getName() + "@" +
                    imageSource.getRepository().getName())
            elif not lastUpdateTimesMatch:
                installedImage.getUser().getRegistry().log(
                    "Installed image " + installedImage.getImageSourceName() +
                    "@" + installedImage.getSourceRepoId() +
                    " is out of date.\nInstalled version:\n " +
                    installedImage.getLastUpdateTime() +
                    "\nCurrent version:\n " +
                    str(imageSource.getPermissions()["last-update-time"]) +
                    "\n")
            return False
    return True
示例#2
0
def isInstalledImageUpToDate(installedImage):
  """
  Returns True if the installed image(including all of its dependencies, is up to date.  False otherwise.
  """
  topImageSource = installedImage.getUser().getRegistry().getRepositories()[installedImage.getSourceRepoId()][installedImage.getImageSourceName()]
  sourceLineage = getImageSourceLineage(topImageSource)
  installedImageLineage = subuserlib.installedImages.getImageLineage(installedImage.getUser(),installedImage.getImageId())
  """print("Installed lineage for image:" + installedImage.getImageSourceName())
  for installedImage in installedImageLineage:
    print("  "+installedImage.getImageSourceName()+"@"+installedImage.getSourceRepoId())
  print("Source lineage for image:" + installedImage.getImageSourceName())
  for imageSource in sourceLineage:
    print("  "+imageSource.getName()+"@"+imageSource.getRepository().getName())"""
  while len(sourceLineage) > 0:
    if not len(installedImageLineage)>0:
      return False
    imageSource = sourceLineage.pop(0)
    installedImage = installedImageLineage.pop(0)
    sourcesMatch = installedImage.getImageSourceName() == imageSource.getName() and installedImage.getSourceRepoId() == imageSource.getRepository().getName()
    lastUpdateTimesMatch = installedImage.getLastUpdateTime() == imageSource.getPermissions()["last-update-time"] or not imageSource.getPermissions()["last-update-time"]
    if not (sourcesMatch and lastUpdateTimesMatch):
      if not sourcesMatch:
        installedImage.getUser().getRegistry().log("Depencies changed from "+installedImage.getImageSourceName()+"@"+installedImage.getSourceRepoId()+".  New depencency is: "+imageSource.getName()+"@"+imageSource.getRepository().getName())
      elif not lastUpdateTimesMatch:
        installedImage.getUser().getRegistry().log("Installed image "+installedImage.getImageSourceName()+"@"+installedImage.getSourceRepoId()+" is out of date.\nInstalled version:\n "+installedImage.getLastUpdateTime()+"\nCurrent version:\n "+str(imageSource.getPermissions()["last-update-time"])+"\n")
      return False
  return True
示例#3
0
  def save(self):
    """ Save attributes of the installed images to disk. """
    # Build a dictionary of installed images.
    installedImagesDict = {}
    for _,installedImage in self.items():
      imageAttributes = {}
      imageAttributes["last-update-time"] = installedImage.getLastUpdateTime()
      imageAttributes["image-source"] = installedImage.getImageSourceName()
      imageAttributes["source-repo"] = installedImage.getSourceRepoId()
      installedImagesDict[installedImage.getImageId()] = imageAttributes

    # Write that dictionary to disk.
    installedImagesPath = self.getUser().getConfig().getInstalledImagesDotJsonPath()
    with open(installedImagesPath, 'w') as file_f:
      json.dump(installedImagesDict, file_f, indent=1, separators=(',', ': '))
示例#4
0
  def save(self):
    """ Save attributes of the installed images to disk. """
    # Build a dictionary of installed images.
    installedImagesDict = {}
    for _,installedImage in self.iteritems():
      imageAttributes = {}
      imageAttributes["last-update-time"] = installedImage.getLastUpdateTime()
      imageAttributes["image-source"] = installedImage.getImageSourceName()
      imageAttributes["source-repo"] = installedImage.getSourceRepoId()
      installedImagesDict[installedImage.getImageId()] = imageAttributes

    # Write that dictionary to disk.
    installedImagesPath = self.getUser().getConfig().getInstalledImagesDotJsonPath()
    with open(installedImagesPath, 'w') as file_f:
      json.dump(installedImagesDict, file_f, indent=1, separators=(',', ': '))
示例#5
0
文件: install.py 项目: ypid/subuser
def compareSourceLineageAndInstalledImageLineage(user, sourceLineage,
                                                 installedImageLineage):
    if not len(sourceLineage) == len(installedImageLineage):
        user.getRegistry().log("Number of dependencies changed from " +
                               str(len(installedImageLineage)) + " to " +
                               str(len(sourceLineage)))
        print("Image sources:")
        for imageSource in sourceLineage:
            print(imageSource.getName())
        print("Installed images:")
        for installedImage in installedImageLineage:
            print(installedImage.getImageSourceName())
        return False

    lineage = zip(sourceLineage, installedImageLineage)
    for imageSource, installedImage in lineage:
        imagesMatch = doImagesMatch(installedImage, imageSource)
        lastUpdateTimesMatch = doLastUpdateTimesMatch(installedImage,
                                                      imageSource)
        if not (imagesMatch and lastUpdateTimesMatch):
            if not imagesMatch:
                user.getRegistry().log("Dependency changed for image from " +
                                       installedImage.getImageSourceName() +
                                       "@" + installedImage.getSourceRepoId() +
                                       " to " + imageSource.getName() + "@" +
                                       imageSource.getRepository().getName())
            elif not lastUpdateTimesMatch:
                user.getRegistry().log(
                    "Installed image " + installedImage.getImageSourceName() +
                    "@" + installedImage.getSourceRepoId() +
                    " is out of date.\nInstalled version:\n " +
                    installedImage.getLastUpdateTime() +
                    "\nCurrent version:\n " +
                    str(imageSource.getPermissions()["last-update-time"]) +
                    "\n")
            return False
    return True
示例#6
0
文件: install.py 项目: ypid/subuser
def doLastUpdateTimesMatch(installedImage, imageSource):
    return installedImage.getLastUpdateTime() == imageSource.getPermissions(
    )["last-update-time"] or not imageSource.getPermissions(
    )["last-update-time"]
示例#7
0
文件: install.py 项目: Fak3/subuser
def compareSourceLineageAndInstalledImageLineage(user,sourceLineage,installedImageLineage):
  if not len(sourceLineage) == len(installedImageLineage):
    user.getRegistry().log("Number of dependencies changed from "+str(len(installedImageLineage))+" to "+str(len(sourceLineage)))
    print("Image sources:")
    for imageSource in sourceLineage:
      print(imageSource.getName())
    print("Installed images:")
    for installedImage in installedImageLineage:
      print(installedImage.getImageSourceName())
    return False

  lineage = zip(sourceLineage,installedImageLineage)
  for imageSource,installedImage in lineage:
    imagesMatch =  doImagesMatch(installedImage,imageSource)
    lastUpdateTimesMatch = doLastUpdateTimesMatch(installedImage,imageSource)
    if not (imagesMatch and lastUpdateTimesMatch):
      if not imagesMatch:
        user.getRegistry().log("Dependency changed for image from "+installedImage.getImageSourceName()+"@"+installedImage.getSourceRepoId()+" to "+imageSource.getName()+"@"+imageSource.getRepository().getName())
      elif not lastUpdateTimesMatch:
        user.getRegistry().log("Installed image "+installedImage.getImageSourceName()+"@"+installedImage.getSourceRepoId()+" is out of date.\nInstalled version:\n "+installedImage.getLastUpdateTime()+"\nCurrent version:\n "+str(imageSource.getPermissions()["last-update-time"])+"\n")
      return False
  return True
示例#8
0
文件: install.py 项目: Fak3/subuser
def doLastUpdateTimesMatch(installedImage,imageSource):
  return installedImage.getLastUpdateTime() == imageSource.getPermissions()["last-update-time"] or not imageSource.getPermissions()["last-update-time"]