#!/usr/bin/python3 -d

"""
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""

import argparse
import sys

from logging import getLogger

from monipy.core.configuration import Configuration
from monipy.core.environment import Environment
from monipy.core.monipy import Monipy
# will only be used when running in daemon mode.
# from monipy.core.monipyd import Monipyd

__version__ = '0.1'
__author__ = 'Johannes Findeisen <you@hanez.org>'

logger = getLogger('monipy')


def parse_args():
    parser = argparse.ArgumentParser(
        description='monipyd is a infrastructure monitoring daemon.',
        epilog='author: ' + __author__,
        prog='monipyd')

    parser.add_argument('configuration_path', metavar='CONFIGURATION_PATH',
                        help='the configuration path to use')

    parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + str(__version__))

    return parser.parse_args()


def main():
    args = parse_args()

    try:
        configuration = Configuration(args.configuration_path)
        configuration.dump_to_ini()
    except Exception as err:
        logger.error(str('[uplink] configuration error: {0}'.format(err)))
        sys.exit(1)

    environment = Environment(configuration)
    monipy = Monipy(configuration, environment)
    # monipyd = Monipyd(configuration, environment)


if __name__ == '__main__':
    main()
