# Path: subuserlib/classes/user.py
# class LockedUser():
#   def __init__(self,name=None,homeDir=None):
#     self.lock = None
#     self.__user = User(name=name,homeDir=homeDir,_locked=True)
# 
#   def __enter__(self):
#     try:
#       self.__user.endUser.makedirs(self.__user.config["lock-dir"])
#     except OSError as exception:
#       if exception.errno != errno.EEXIST:
#         raise
#     try:
#       self.lock = subuserlib.lock.getLock(self.__user.endUser.get_file(os.path.join(self.__user.config["lock-dir"],"registry.lock"),'w'),timeout=1)
#       self.lock.__enter__()
#     except IOError as e:
#       if e.errno != errno.EINTR:
#         raise e
#       sys.exit("Another subuser process is currently running and has a lock on the registry. Please try again later.")
#     return self.__user
# 
#   def __exit__(self, type, value, traceback):
#     self.lock.__exit__()


import sys
import optparse
import subuserlib.commandLineArguments
import subuserlib.update
import subuserlib.profile
from subuserlib.classes.user import LockedUser

  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.")

# Path: subuserlib/classes/user.py
# class LockedUser():
#   def __init__(self,name=None,homeDir=None):
#     self.lock = None
#     self.__user = User(name=name,homeDir=homeDir,_locked=True)
# 
#   def __enter__(self):
#     try:
#       self.__user.endUser.makedirs(self.__user.config["lock-dir"])
#     except OSError as exception:
#       if exception.errno != errno.EEXIST:
#         raise
#     try:
#       self.lock = subuserlib.lock.getLock(self.__user.endUser.get_file(os.path.join(self.__user.config["lock-dir"],"registry.lock"),'w'),timeout=1)
#       self.lock.__enter__()
#     except IOError as e:
#       if e.errno != errno.EINTR:
#         raise e
#       sys.exit("Another subuser process is currently running and has a lock on the registry. Please try again later.")
#     return self.__user
# 
#   def __exit__(self, type, value, traceback):
#     self.lock.__exit__()


# Path: subuserlib/builtInCommands/update.py
import sys
import optparse
import subuserlib.commandLineArguments
import subuserlib.update
import subuserlib.profile
from subuserlib.classes.user import LockedUser


  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()