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 (96 lines) | stat: -rwxr-xr-x 4,307 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#external imports
import sys
import optparse
#internal imports
import subuserlib.commandLineArguments
from subuserlib.classes.user import LockedUser
import subuserlib.update
import subuserlib.profile
from subuserlib.classes.permissionsAccepters.acceptPermissionsAtCLI import AcceptPermissionsAtCLI

#####################################################################################

def parseCliArgs(realArgs):
  usage = "usage: subuser update [options]"
  description = """Update subuser images.

  all
      Updates all subuser images which have been marked as out of date.

  EXAMPLE:
    $ subuser update all

  subusers
      Updates the specified subusers

  EXAMPLE:
    $ subuser update subusers iceweasel git

  lock-subuser-to SUBUSER GIT-COMMIT
      Don't want a subuser to be updated?  No problem, lock it to a given version with this update sub-command.  Use subuser update log to see a list of possible hashes.

  unlock-subuser SUBUSER
      Unlock the subuser and ensure that it is up-to-date.

"""
  parser=optparse.OptionParser(usage=usage,description=description,formatter=subuserlib.commandLineArguments.HelpFormatterThatDoesntReformatDescription())
  parser.add_option("--accept",dest="accept",action="store_true",default=False,help="Accept permissions without asking.")
  parser.add_option("--prompt",dest="prompt",action="store_true",default=False,help="Prompt before installing new images.")
  parser.add_option("--use-cache",dest="useCache",action="store_true",default=False,help="Use the layer cache when building images.")
  return parser.parse_args(args=realArgs)

#################################################################################################

@subuserlib.profile.do_cprofile
def runCommand(realArgs):
  """
  Update your subuser installation.
  """
  options,args = parseCliArgs(realArgs)
  if len(args) < 1:
    sys.exit("No arguments given. Please use subuser update -h for help.")
  lockedUser = LockedUser()
  with lockedUser as user:
    user.registry.commit_message = " ".join(["subuser","update"]+realArgs)
    permissionsAccepter = AcceptPermissionsAtCLI(user,alwaysAccept = options.accept)
    if ["all"] == args:
      subuserlib.update.all(user,permissionsAccepter=permissionsAccepter,prompt=options.prompt,useCache=options.useCache)
    elif "subusers" == args[0]:
      subuserNamesToUpdate = args[1:]
      subusersToUpdate = []
      for subuserName in subuserNamesToUpdate:
        try:
          subusersToUpdate.append(user.registry.subusers[subuserName])
        except KeyError:
          sys.exit("Subuser "+subuserName+" does not exist. Use --help for help.")
      if subusersToUpdate:
        subuserlib.update.subusers(user,subusers=subusersToUpdate,permissionsAccepter=permissionsAccepter,prompt=options.prompt,useCache=options.useCache)
      else:
        sys.exit("You did not specify any subusers to be updated. Use --help for help. Exiting...")
    elif "lock-subuser-to" == args[0]:
      try:
        subuserName = args[1]
        commit = args[2]
      except IndexError:
        sys.exit("Wrong number of arguments.  Expected a subuser name and a commit.  Try running\nsubuser update --help\n for more info.")
      try:
        subuser = user.registry.subusers[subuserName]
      except KeyError:
        sys.exit("Subuser "+subuserName+" does not exist and therefore cannot be locked. Use --help for help.")
      subuserlib.update.lockSubuser(user,subuser=subuser,commit=commit)
    elif "unlock-subuser" == args[0]:
      try:
        subuserName = args[1]
      except IndexError:
        sys.exit("Wrong number of arguments.  Expected a subuser's name. Try running\nsubuser update --help\nfor more information.")
      try:
        subuser = user.registry.subusers[subuserName]
      except KeyError:
        sys.exit("Subuser "+subuserName+" does not exist. Cannot lock. Use --help for help.")
      subuserlib.update.unlockSubuser(user,subuser=subuser,permissionsAccepter=permissionsAccepter,prompt=options.prompt)
    elif len(args) == 1:
      sys.exit(" ".join(args) + " is not a valid update subcommand. Please use subuser update -h for help.")
    else:
      sys.exit(" ".join(args) + " is not a valid update subcommand. Please use subuser update -h for help.")