#!/usr/bin/env python
#
#    Copyright 2017 EPAM Systems
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#

try:
    import docker_bootup
except ImportError:
    pass

import sys
import os
import argparse
import logging

from legion.edi.server import serve
import legion.utils

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Legion API server')
    parser.add_argument('--verbose',
                        help='verbose log output',
                        action='store_true')

    parser.add_argument('--namespace',
                                type=str, help='Namespace name')
    parser.add_argument('--deployment',
                                type=str, help='Deployment name')
    parser.add_argument('--legion-api-addr',
                                type=str)
    parser.add_argument('--legion-api-port',
                                type=int)

    # --------- END OF SECTIONS -----------
    args = parser.parse_args(sys.argv[1:])

    v = vars(args)

    if args.verbose or legion.utils.string_to_bool(os.getenv('VERBOSE', '')):
        log_level = logging.DEBUG
    else:
        log_level = logging.ERROR

    logging.basicConfig(level=log_level, format='%(asctime)s - %(levelname)s - %(message)s')

    serve(args)
