#!python
"""
Copyright 2015-2017 Hermann Krumrey

This file is part of kudubot.

kudubot is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

kudubot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with kudubot.  If not, see <http://www.gnu.org/licenses/>.
"""

import logging
import argparse
from kudubot.config.GlobalConfigHandler import GlobalConfigHandler
from kudubot.config.StandardConfigWriter import StandardConfigWriter

if __name__ == "__main__":

    parser = argparse.ArgumentParser()
    parser.add_argument("-d", "--delete-old", action="store_true",
                        help="Can be used to completely wipe theprevious configuration.")
    parser.add_argument("-v", "--verbose", action="store_true", help="Activates verbose output")
    parser.add_argument("-b", "--debug", action="store_true", help="Activates debug-level logging output")
    parser.add_argument("-s", "--standard-config", action="store_true", help="Generates the standard configuration")
    parser.add_argument("--remove-executable-service-files", action="store_true",
                        help="Deletes all executable service files. "
                             "They will be re-downloaded the next time the bot starts.")

    args = parser.parse_args()

    if args.debug:
        logging.basicConfig(level=logging.INFO)
    elif args.verbose:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.ERROR)

    args = parser.parse_args()
    config_handler = GlobalConfigHandler()
    config_handler.generate_configuration(args.delete_old)

    if args.standard_config:
        StandardConfigWriter(config_handler).write_standard_connection_config()
        StandardConfigWriter(config_handler).write_standard_service_config()

    if args.remove_executable_service_files:
        config_handler.delete_service_executables()
