Esempio n. 1
0
def verify(user,permissionsAccepter=None,checkForUpdatesExternally=False,subusers=[],prompt=False,useCache=False):
  """
   Ensure that:
     - Registry is consistent; warns the user about subusers that point to non-existant source images.
     - For each subuser there is an up-to-date image installed.
     - No-longer-needed temporary repositories are removed. All temporary repositories have at least one subuser who's image is built from one of the repository's image sources.
     - No-longer-needed installed images are removed.
  """
  user.getRegistry().log("Verifying subuser configuration.")
  user.getRegistry().log("Verifying registry consistency...")
  for _,subuser in user.getRegistry().getSubusers().items():
    try:
      subuser.getImageSource()
    except subuserlib.classes.subuser.NoImageSourceException:
      user.getRegistry().log("WARNING: "+subuser.getName()+" is no longer present in it's source repository. Support for this progam may have been dropped.")
      try:
        subusers.remove(subuser)
      except ValueError:
        pass
  user.getRegistry().log("Unregistering any non-existant installed images.")
  user.getInstalledImages().unregisterNonExistantImages()
  if subusers:
    user.getRegistry().setChanged(True)
    user.getRegistry().log("Approving permissions...",verbosityLevel=3)
    (failedSubusers,permissionParsingExceptions) = approvePermissions(user,subusers,permissionsAccepter)
    user.getRegistry().log("Permissions approved...",verbosityLevel=3)
    subusers = [x for x in subusers if x not in failedSubusers]
    for failedSubuser in failedSubusers:
      try:
        failedSubuser.getPermissions()
      except subuserlib.classes.subuser.SubuserHasNoPermissionsException:
        del user.getRegistry().getSubusers()[failedSubuser.getName()]
    subusers += ensureServiceSubusersAreSetup(user,subusers)
    installationTask = InstallationTask(user,subusersToBeUpdatedOrInstalled=subusers,checkForUpdatesExternally=checkForUpdatesExternally)
    outOfDateSubusers = installationTask.getOutOfDateSubusers()
    if outOfDateSubusers:
      user.getRegistry().log("New images for the following subusers need to be installed:")
      for subuser in outOfDateSubusers:
        user.getRegistry().log(subuser.getName())
      if (not prompt) or (prompt and (not input("Would you like to install those images now? [Y/n]") == "n")):
        installationTask.updateOutOfDateSubusers(useCache=useCache)
    for exception in permissionParsingExceptions:
      user.getRegistry().log(str(exception))
    subusersWhosImagesFailedToBuild = installationTask.getSubusersWhosImagesFailedToBuild()
    if subusersWhosImagesFailedToBuild:
      user.getRegistry().log("Images for the following subusers failed to build:")
    for subuser in subusersWhosImagesFailedToBuild:
      user.getRegistry().log(subuser.getName())
    for subuser in subusers:
      try:
        subuser.getRunReadyImage().setup()
        subuser.setupHomeDir()
      except subuserlib.classes.subuserSubmodules.run.runtimeCache.NoRuntimeCacheForSubusersWhichDontHaveExistantImagesException:
        pass
  user.getInstalledImages().save()
  trimUnneededTempRepos(user)
  rebuildBinDir(user)
  cleanupRuntimeDirs(user)
  cleanUpRuntimeCache(user)
  cleanUpAfterImproperlyTerminatedServices(user)
Esempio n. 2
0
def remove(user,subusers):
  didSomething = False
  for subuser in subusers:
    user.getRegistry().logChange("Removing subuser "+str(subuser.getName()))
    try:
      subuserHome = subuser.getHomeDirOnHost()
      if subuserHome and os.path.exists(subuserHome):
        user.getRegistry().logChange(" If you wish to remove the subusers home directory, issule the command $ rm -r "+subuserHome)
    except:
      pass
    user.getRegistry().logChange(" If you wish to remove the subusers image, issue the command $ subuser remove-old-images")
    for serviceSubuserName in subuser.getServiceSubuserNames():
      try:
        serviceSubuser = user.getRegistry().getSubusers()[serviceSubuserName]
        serviceSubuser.removePermissions()
        del user.getRegistry().getSubusers()[serviceSubuserName]
      except KeyError:
        pass
    # Remove service locks
    try:
      shutil.rmtree(os.path.join(user.getConfig()["lock-dir"],"services",subuser.getName()))
    except OSError:
      pass
    # Remove permission files
    subuser.removePermissions()
    del user.getRegistry().getSubusers()[subuser.getName()]
    didSomething = True
  if didSomething:
    subuserlib.verify.verify(user)
    user.getRegistry().commit()
Esempio n. 3
0
def setEntrypointsExposed(user,subusers,exposed,permissionsAccepter):
  for subuser in subusers:
    if exposed:
      user.getRegistry().logChange("Exposing entrypoints for subuser "+subuser.getName()+" in the $PATH.")
    else:
      user.getRegistry().logChange("Removing entrypoints for subuser "+subuser.getName()+" from $PATH.")
    subuser.setEntrypointsExposed(exposed)
  subuserlib.verify.verify(user,subusers=subusers,permissionsAccepter=permissionsAccepter)
  user.getRegistry().commit()
Esempio n. 4
0
def setExecutableShortcutInstalled(user,subusers,installed):
  for subuser in subusers:
    if installed:
      user.getRegistry().logChange("Adding launcher for subuser "+subuser.getName()+" to $PATH.")
    else:
      user.getRegistry().logChange("Removing launcher for subuser "+subuser.getName()+" from $PATH.")
    subuser.setExecutableShortcutInstalled(installed)
  subuserlib.verify.verify(user)
  user.getRegistry().commit()
Esempio n. 5
0
def setExecutableShortcutInstalled(user, subusers, installed):
    for subuser in subusers:
        if installed:
            user.getRegistry().logChange("Adding launcher for subuser " +
                                         subuser.getName() + " to $PATH.")
        else:
            user.getRegistry().logChange("Removing launcher for subuser " +
                                         subuser.getName() + " from $PATH.")
        subuser.setExecutableShortcutInstalled(installed)
    subuserlib.verify.verify(user)
    user.getRegistry().commit()
Esempio n. 6
0
def setEntrypointsExposed(user, subusers, exposed, permissionsAccepter):
    for subuser in subusers:
        if exposed:
            user.getRegistry().logChange("Exposing entrypoints for subuser " +
                                         subuser.getName() + " in the $PATH.")
        else:
            user.getRegistry().logChange("Removing entrypoints for subuser " +
                                         subuser.getName() + " from $PATH.")
        subuser.setEntrypointsExposed(exposed)
    subuserlib.verify.verify(user,
                             subusers=subusers,
                             permissionsAccepter=permissionsAccepter)
    user.getRegistry().commit()
Esempio n. 7
0
def remove(user, subusers):
    didSomething = False
    for subuser in subusers:
        user.getRegistry().logChange("Removing subuser " +
                                     str(subuser.getName()))
        try:
            subuserHome = subuser.getHomeDirOnHost()
            if subuserHome and os.path.exists(subuserHome):
                user.getRegistry().logChange(
                    " If you wish to remove the subusers home directory, issule the command $ rm -r "
                    + subuserHome)
        except:
            pass
        user.getRegistry().logChange(
            " If you wish to remove the subusers image, issue the command $ subuser remove-old-images"
        )
        for serviceSubuserName in subuser.getServiceSubuserNames():
            try:
                serviceSubuser = user.getRegistry().getSubusers(
                )[serviceSubuserName]
                serviceSubuser.removePermissions()
                del user.getRegistry().getSubusers()[serviceSubuserName]
            except KeyError:
                pass
        # Remove service locks
        try:
            shutil.rmtree(
                os.path.join(user.getConfig()["lock-dir"], "services",
                             subuser.getName()))
        except OSError:
            pass
        # Remove permission files
        subuser.removePermissions()
        del user.getRegistry().getSubusers()[subuser.getName()]
        didSomething = True
    if didSomething:
        subuserlib.verify.verify(user)
        user.getRegistry().commit()
Esempio n. 8
0
def verify(user,
           permissionsAccepter=None,
           checkForUpdatesExternally=False,
           subuserNames=[],
           prompt=False):
    """
   Ensure that:
     - Registry is consistent; warns the user about subusers that point to non-existant source images.
     - For each subuser there is an up-to-date image installed.
     - No-longer-needed temporary repositories are removed. All temporary repositories have at least one subuser who's image is built from one of the repository's image sources.
     - No-longer-needed installed images are removed.
  """
    user.getRegistry().log("Verifying subuser configuration.")
    user.getRegistry().log("Verifying registry consistency...")
    for _, subuser in user.getRegistry().getSubusers().items():
        try:
            subuser.getImageSource()
        except subuserlib.classes.subuser.NoImageSourceException:
            user.getRegistry().log(
                "WARNING: " + subuser.getName() +
                " is no longer present in it's source repository. Support for this progam may have been dropped."
            )
            try:
                subuserNames.remove(subuser.getName())
            except ValueError:
                pass
    user.getRegistry().log("Unregistering any non-existant installed images.")
    user.getInstalledImages().unregisterNonExistantImages()
    if subuserNames:
        user.getRegistry().setChanged(True)
        (failedSubuserNames, permissionParsingExceptions) = approvePermissions(
            user, subuserNames, permissionsAccepter)
        subuserNames = [x for x in subuserNames if x not in failedSubuserNames]
        subuserNames += ensureServiceSubusersAreSetup(user, subuserNames)
        subusers = [
            user.getRegistry().getSubusers()[subuserName]
            for subuserName in subuserNames
        ]
        installationTask = InstallationTask(
            user,
            subusersToBeUpdatedOrInstalled=subusers,
            checkForUpdatesExternally=checkForUpdatesExternally)
        outOfDateSubusers = installationTask.getOutOfDateSubusers()
        if outOfDateSubusers:
            user.getRegistry().log(
                "New images for the following subusers need to be installed:")
            for subuser in outOfDateSubusers:
                user.getRegistry().log(subuser.getName())
            if (not prompt) or (prompt and (not raw_input(
                    "Would you like to install those images now? [Y/n]")
                                            == "n")):
                installationTask.updateOutOfDateSubusers()
        for exception in permissionParsingExceptions:
            user.getRegistry().log(str(exception))
        subusersWhosImagesFailedToBuild = installationTask.getSubusersWhosImagesFailedToBuild(
        )
        if subusersWhosImagesFailedToBuild:
            user.getRegistry().log(
                "Images for the following subusers failed to build:")
        for subuser in subusersWhosImagesFailedToBuild:
            user.getRegistry().log(subuser.getName())
        for subuser in subusers:
            try:
                subuser.getRunReadyImage().setup()
                subuser.setupHomeDir()
            except subuserlib.classes.subuserSubmodules.run.runtimeCache.NoRuntimeCacheForSubusersWhichDontHaveExistantImagesException:
                pass
    user.getInstalledImages().save()
    trimUnneededTempRepos(user)
    rebuildBinDir(user)
    cleanupRuntimeDirs(user)
    cleanUpRuntimeCache(user)
    cleanUpAfterImproperlyTerminatedServices(user)
Esempio n. 9
0
def approvePermissions(user,subusers,permissionsAccepter):
  subusersWhosPermissionsFailedToParse = []
  exceptions = []
  for subuser in subusers:
    if subuser.locked():
      continue
    try:
      userApproved = subuser.getPermissions()
    except subuserlib.classes.subuser.SubuserHasNoPermissionsException:
      userApproved = None
    try:
      oldDefaults = subuser.getPermissionsTemplate()
      newDefaults = subuser.getImageSource().getPermissions()
      permissionsAccepter.accept(subuser=subuser,oldDefaults=oldDefaults,newDefaults=newDefaults,userApproved=userApproved)
      subuser.getPermissionsTemplate().update(subuser.getImageSource().getPermissions())
      subuser.getPermissionsTemplate().save()
    except SyntaxError as e:
      subusersWhosPermissionsFailedToParse.append(subuser)
      exceptions.append(e)
    except subuserlib.classes.subuser.NoImageSourceException:
      subusersWhosPermissionsFailedToParse.append(subuser)
      user.getRegistry().log("Warning: The image source for subuser %s is no longer available."%subuser.getName())
  return (subusersWhosPermissionsFailedToParse,exceptions)