#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Saver_utils v1.02.3.5 _py31404 Git Version"""

# %% === Imports
# benötigte Packages
import logging
from datetime import datetime
from pathlib import Path
from time import time

from eSaver_Data_App import App_Data


# ## === Variables Global anlegen

pass  # ## ==========


# ? =============================================
# %% === Logger aktivieren und beenden
def logger_Settings():
    """Logger Settings

    Initialisierung der Bezeichnung-Namen (EN)
    """
    logging.debug('debug Beschreibung Test der Meldungen')
    logging.info('info')
    logging.warning('warning')
    logging.error('error')
    logging.critical('critical')
    logging.info('info ========================================')
    logging.info('_PRG')

    return


# %% === logger_On
def logger_On(parent: Path, loggerFileName: str):
    """Einschalten des Loggers open Logger-file"""
    try:
        logging.getLogger().removeHandler(logging.getLogger().handlers[0])
        logging.getLogger().removeHandler(logging.getLogger().handlers[0])
    except:  # noqa: E722
        pass

    parent = parent

    strTimeFtime = datetime.now().strftime('%y%m%d_%H%M%S')

    logFileName = f'{loggerFileName}{strTimeFtime}.log'

    strFileLog = parent / logFileName
    print(f'>>> Log_FileName: {strFileLog}')
    logging.basicConfig(
        filename=strFileLog,
        filemode='w',  # default = 'a'
        format='%(asctime)s %(name)15s - %(levelname)8s: - %(message)s',
        datefmt='%d.%m.%y %H:%M:%S',
        level=logging.INFO,
    )
    return


# %% === logger_Off
def logger_Off():
    """Ausschalten des Loggers close Logger-file"""
    logging.shutdown()

    return


# %% === main
def main():
    """main Programm

    INIT Eintagungen aus Excel lesen
    in App_Data eintragen
    """
    tStart = time()  # todo: Zeitmessung

    app_data = App_Data()

    app_data.strTimeFtime = datetime.now().strftime('%Y%m%d_%H%M')

    # ## === Path-Variablen holen ===
    cwd = Path.cwd()
    parent = cwd.parent

    # ========== logger aktivieren ==========
    # ?: Hier sollte der Dateiname aus der App_Data.xx gelesen werden.
    logger_On(parent, 'x_eSaver_Ausw_Erspar_Log_')
    logger_Settings()

    tStart2 = time()  # todo: Zeitmessung
    tDauer = tStart2 - tStart
    logging.info(f'main_testen - started                                        / tDauer {tDauer}')

    pass

    # ========== main_app ==========
    # main_app()

    pass

    tEnde = time()  # todo: Zeitmessung
    tDauer = tEnde - tStart
    logging.info(f'main_testen - stopped                                        / tDauer {tDauer}')

    logger_Off()

    return


# %% === Start __main__ ==========
if __name__ == '__main__':
    """Einsprung Start der Anlage

    """
    # ## === Variables Global anlegen
    pass

    main()

    pass  # ## ==========


# %% === EOF
# EOF
