# 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.resolve
import subuserlib.repository
import subuserlib.commandLineArguments
import subuserlib.profile
from subuserlib.classes.user import LockedUser
# -*- coding: utf-8 -*-
#external imports
#internal imports

def parseCliArgs(sysargs):
  usage = "usage: subuser repository [options] [add|remove] NAME <URL>"
  description = """Add or remove a new named repository.

- EXAMPLE
    Add a new repository named foo with the URI https://www.example.com/repo.git.

    $ subuser repository add foo https://www.example.com/repo.git
    $ #You can also add a local repository:
    $ subuser repository add local-foo file:///home/timothy/my-local-repo/

- EXAMPLE
    Remove the repository named foo.

    $subuser repository remove foo

  """
  parser=optparse.OptionParser(usage=usage,description=description,formatter=subuserlib.commandLineArguments.HelpFormatterThatDoesntReformatDescription())
  return parser.parse_args(args=sysargs)

@subuserlib.profile.do_cprofile
def runCommand(sysargs):
  """
  Manage named subuser repositories.
  """
  options,args = parseCliArgs(sysargs)

# 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/repository.py
import sys
import optparse
import subuserlib.resolve
import subuserlib.repository
import subuserlib.commandLineArguments
import subuserlib.profile
from subuserlib.classes.user import LockedUser

# -*- coding: utf-8 -*-
#external imports
#internal imports

def parseCliArgs(sysargs):
  usage = "usage: subuser repository [options] [add|remove] NAME <URL>"
  description = """Add or remove a new named repository.

- EXAMPLE
    Add a new repository named foo with the URI https://www.example.com/repo.git.

    $ subuser repository add foo https://www.example.com/repo.git
    $ #You can also add a local repository:
    $ subuser repository add local-foo file:///home/timothy/my-local-repo/

- EXAMPLE
    Remove the repository named foo.

    $subuser repository remove foo

  """
  parser=optparse.OptionParser(usage=usage,description=description,formatter=subuserlib.commandLineArguments.HelpFormatterThatDoesntReformatDescription())
  return parser.parse_args(args=sysargs)

@subuserlib.profile.do_cprofile
def runCommand(sysargs):
  """
  Manage named subuser repositories.
  """
  options,args = parseCliArgs(sysargs)

  lockedUser = LockedUser()