File: update.py

package info (click to toggle)
subuser 0.6.2-3
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 4,208 kB
  • sloc: python: 5,201; sh: 380; makefile: 73
file content (67 lines) | stat: -rwxr-xr-x 2,854 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-

"""
High level operations used for updating, rolling back, locking ect.
"""

#external imports
import sys
#internal imports
import subuserlib.verify

#####################################################################################
def all(user,permissionsAccepter,prompt=False,useCache=False):
  """
  This command updates(if needed) all of the installed subuser images.
  """
  user.registry.log("Updating...")
  for _,repository in user.registry.repositories.items():
    repository.updateSources()
  subusers = user.registry.subusers.getSortedList()
  subuserlib.verify.verify(user,checkForUpdatesExternally=True,useCache=useCache,subusers=subusers,permissionsAccepter=permissionsAccepter,prompt=prompt)
  user.registry.commit()

def subusers(user,subusers,permissionsAccepter,prompt=False,useCache=False):
  """
  This command updates the specified subusers' images.
  """
  user.registry.log("Updating...")
  for _,repository in user.registry.repositories.items():
    repository.updateSources()
  subuserlib.verify.verify(user,subusers=subusers,useCache=useCache,checkForUpdatesExternally=True,permissionsAccepter=permissionsAccepter,prompt=prompt)
  user.registry.commit()

def lockSubuser(user,subuser,commit):
  """
  Lock the subuser to the image and permissions that it had at a given registry commit.
  """
  from subuserlib.classes.user import User
  from subuserlib.classes.registry import Registry
  oldUser = User(name=user.name,homeDir=user.homeDir)
  oldUser.registry = Registry(oldUser,gitReadHash=commit,ignoreVersionLocks=True,initialized=True)
  if not oldUser.registry.gitRepository.doesCommitExist(commit):
    sys.exit("Commit "+commit+" does not exist. Cannot lock to commit.")
  try:
    oldSubuser = oldUser.registry.subusers[subuser.name]
  except KeyError:
    sys.exit("Subuser, "+subuser.name+" did not exist yet at commit "+commit+". Cannot lock to commit.")
  subuser.imageId = oldSubuser.imageId
  oldSubuser.permissions.save(_have_lock=True)
  oldSubuser.getPermissionsTemplate().save(_have_lock=True)
  user.registry.logChange("Locking subuser "+subuser.name+" to commit: "+commit)
  user.registry.logChange("New image id is "+subuser.imageId)
  subuser.locked = True
  subuserlib.verify.verify(user)
  user.registry.commit()

def unlockSubuser(user,subuser,permissionsAccepter,prompt):
  """
  Unlock the subuser, leaving it to have an up to date image.  Delete user set permissions if unlockPermissions is True.
  """
  if subuser.locked:
    user.registry.logChange("Unlocking subuser "+subuser.name)
    subuser.locked = False
    subuserlib.verify.verify(user,subusers=[subuser],checkForUpdatesExternally=True,permissionsAccepter=permissionsAccepter,prompt=prompt)
    user.registry.commit()
  else:
    user.registry.log("Subuser "+subuser.name + " is not locked. Doing nothing.")