# Path: lib/Wrappers/ArgumentParser.py
# class ArgumentParser:
#     DEFAULT_VERSION = 'last stable'
# 
#     def __init__(self, *args, argument_parser=None, version_provider=None, **kwargs):
#         self.parser = argument_parser or argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
#                                                                  *args,
#                                                                  **kwargs)
#         self._common_args()
# 
#     def add_argument(self, *args, **kwargs):
#         self.parser.add_argument(*args, **kwargs)
# 
#     def parse_args(self, args):
#         arguments = self.parser.parse_args(args)
#         if 'version' in arguments and arguments.version == self.DEFAULT_VERSION:
#             arguments.version = '1.0'
# 
#         return arguments
# 
#     def _common_args(self):
#         self.parser.add_argument('-S', '--settings', metavar='SETTINGS', type=str,
#                                  help='Path to the settings file.', default="settings.cfg")
# 
# Path: lib/Tools/WaitForEyeos.py
# class WaitForEyeos:
#     def __init__(self):
#         self.settings = Settings()
#         self.logger = Logger(__name__)
#         self.entrypoint = "proxy"
# 
#     def wait(self, timeout):
#         logging.getLogger("requests").setLevel(logging.ERROR)
#         starttime = time.time()
#         while True:
#             now = time.time()
#             if now - starttime > timeout:
#                 raise TimeoutError("Wait timed out")
#             try:
#                 ip = self.settings.getServiceIp(self.entrypoint)
#                 requests.packages.urllib3.disable_warnings()
#                 requests.get('http://{0}'.format(ip), verify=False)
#                 time.sleep(5)
#                 self.logger.info("Waited for {0} seconds".format(int(now - starttime)))
#                 break
#             except (UnknownHostError, requests.exceptions.RequestException) as e:
#                 time.sleep(0.5)
#                 continue


from lib.Wrappers.ArgumentParser import ArgumentParser
from lib.Tools.WaitForEyeos import WaitForEyeos


class Wait:
    def __init__(self, waiter=None):
        self.waiter = waiter or WaitForEyeos()

    def execute(self, *args):
        arguments = self._parse_arguments(*args)
        try:
            self.waiter.wait(arguments.timeout)
        except TimeoutError as e:
            exit(e)

    def _parse_arguments(self, command_name, *args):
        parser = ArgumentParser(description='Blocks until eyeos is ready',
                                prog='eyeos ' + command_name)

# Path: lib/Wrappers/ArgumentParser.py
# class ArgumentParser:
#     DEFAULT_VERSION = 'last stable'
# 
#     def __init__(self, *args, argument_parser=None, version_provider=None, **kwargs):
#         self.parser = argument_parser or argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
#                                                                  *args,
#                                                                  **kwargs)
#         self._common_args()
# 
#     def add_argument(self, *args, **kwargs):
#         self.parser.add_argument(*args, **kwargs)
# 
#     def parse_args(self, args):
#         arguments = self.parser.parse_args(args)
#         if 'version' in arguments and arguments.version == self.DEFAULT_VERSION:
#             arguments.version = '1.0'
# 
#         return arguments
# 
#     def _common_args(self):
#         self.parser.add_argument('-S', '--settings', metavar='SETTINGS', type=str,
#                                  help='Path to the settings file.', default="settings.cfg")
# 
# Path: lib/Tools/WaitForEyeos.py
# class WaitForEyeos:
#     def __init__(self):
#         self.settings = Settings()
#         self.logger = Logger(__name__)
#         self.entrypoint = "proxy"
# 
#     def wait(self, timeout):
#         logging.getLogger("requests").setLevel(logging.ERROR)
#         starttime = time.time()
#         while True:
#             now = time.time()
#             if now - starttime > timeout:
#                 raise TimeoutError("Wait timed out")
#             try:
#                 ip = self.settings.getServiceIp(self.entrypoint)
#                 requests.packages.urllib3.disable_warnings()
#                 requests.get('http://{0}'.format(ip), verify=False)
#                 time.sleep(5)
#                 self.logger.info("Waited for {0} seconds".format(int(now - starttime)))
#                 break
#             except (UnknownHostError, requests.exceptions.RequestException) as e:
#                 time.sleep(0.5)
#                 continue


# Path: lib/Subcommands/Wait.py
from lib.Wrappers.ArgumentParser import ArgumentParser
from lib.Tools.WaitForEyeos import WaitForEyeos



class Wait:
    def __init__(self, waiter=None):
        self.waiter = waiter or WaitForEyeos()

    def execute(self, *args):
        arguments = self._parse_arguments(*args)
        try:
            self.waiter.wait(arguments.timeout)
        except TimeoutError as e:
            exit(e)

    def _parse_arguments(self, command_name, *args):
        parser = ArgumentParser(description='Blocks until eyeos is ready',
                                prog='eyeos ' + command_name)

        parser.add_argument('--timeout', metavar='TIMEOUT', default='inf', nargs='?', type=float,