From 0cbcf1a702f714c900b88adfbdb26708e5620710 Mon Sep 17 00:00:00 2001 From: Maveno Date: Mon, 4 Nov 2024 11:30:59 +0100 Subject: [PATCH] Tests passed, Config-File --- .gitignore | 1 + bin/check.py | 32 ------------------ bin/dd.py | 6 ---- bin/ffx.py | 22 ++++++------ bin/ffx/configuration_controller.py | 48 ++++++++++++++++++++++++++ bin/ffx/dashboard_screen.py | 16 --------- bin/ffx/database.py | 2 +- bin/ffx/warning_screen.py | 11 ------ bin/ffx_tests.py | 13 ++++---- bin/logg.py | 52 ----------------------------- bin/prod.py | 32 ------------------ ffx_test_report.log | 0 12 files changed, 68 insertions(+), 167 deletions(-) delete mode 100644 bin/check.py delete mode 100644 bin/dd.py create mode 100644 bin/ffx/configuration_controller.py delete mode 100644 bin/ffx/dashboard_screen.py delete mode 100644 bin/ffx/warning_screen.py delete mode 100755 bin/logg.py delete mode 100644 bin/prod.py delete mode 100644 ffx_test_report.log diff --git a/.gitignore b/.gitignore index 9487c3a..472e594 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__ junk/ .vscode/launch.json +.ipynb_checkpoints/ diff --git a/bin/check.py b/bin/check.py deleted file mode 100644 index 9759724..0000000 --- a/bin/check.py +++ /dev/null @@ -1,32 +0,0 @@ -import os - -from ffx.pattern_controller import PatternController - -from ffx.model.show import Base -from sqlalchemy import create_engine, Column, Integer, String, ForeignKey -from sqlalchemy.orm import relationship, sessionmaker, Mapped, backref - -filename = 'Boruto.Naruto.Next.Generations.S01E256.GerEngSub.AAC.1080p.WebDL.x264-Tanuki.mkv' - - - -# Data 'input' variable -context = {} - -# Initialize DB -homeDir = os.path.expanduser("~") -ffxVarDir = os.path.join(homeDir, '.local', 'var', 'ffx') -if not os.path.exists(ffxVarDir): - os.makedirs(ffxVarDir) - -context['database_url'] = f"sqlite:///{os.path.join(ffxVarDir, 'ffx.db')}" -context['database_engine'] = create_engine(context['database_url']) -context['database_session'] = sessionmaker(bind=context['database_engine']) - -Base.metadata.create_all(context['database_engine']) - - -pc = PatternController(context) - - -print(pc.matchFilename(filename)) diff --git a/bin/dd.py b/bin/dd.py deleted file mode 100644 index 41c541b..0000000 --- a/bin/dd.py +++ /dev/null @@ -1,6 +0,0 @@ -from ffx.helper import dictDiff - -a = {'name': 'yolo', 'mass': 56} -b = {'name': 'zolo', 'mass': 58} - -print(dictDiff(a, b)) diff --git a/bin/ffx.py b/bin/ffx.py index d27a282..53b4ab3 100755 --- a/bin/ffx.py +++ b/bin/ffx.py @@ -2,6 +2,8 @@ import os, click, time, logging +from ffx.configuration_controller import ConfigurationController + from ffx.file_properties import FileProperties from ffx.ffx_app import FfxApp @@ -19,7 +21,7 @@ from ffx.track_disposition import TrackDisposition from ffx.process import executeProcess -VERSION='0.1.3' +VERSION='0.2.0' # 0.1.1 # Bugfixes, TMBD identify shows @@ -27,7 +29,8 @@ VERSION='0.1.3' # Bugfixes # 0.1.3 # Subtitle file imports - +# 0.2.0 +# Tests, Config-File @click.group() @click.pass_context @@ -38,7 +41,12 @@ def ffx(ctx, database_file, verbose, dry_run): """FFX""" ctx.obj = {} - ctx.obj['database'] = databaseContext(databasePath=database_file) + + ctx.obj['config'] = ConfigurationController() + + ctx.obj['database'] = databaseContext(databasePath=database_file + if database_file else ctx.obj['config'].getDatabaseFilePath()) + ctx.obj['dry_run'] = dry_run ctx.obj['verbosity'] = verbose @@ -50,16 +58,10 @@ def ffx(ctx, database_file, verbose, dry_run): fileLogVerbosity = max(40 - verbose * 10, 10) consoleLogVerbosity = max(20 - verbose * 10, 10) - homeDir = os.path.expanduser("~") - ffxLogDir = os.path.join(homeDir, '.local', 'var', 'log') - if not os.path.exists(ffxLogDir): - os.makedirs(ffxLogDir) - ffxLogFilePath = os.path.join(ffxLogDir, 'ffx.log') - ctx.obj['logger'] = logging.getLogger('FFX') ctx.obj['logger'].setLevel(logging.DEBUG) - ffxFileHandler = logging.FileHandler(ffxLogFilePath) + ffxFileHandler = logging.FileHandler(ctx.obj['config'].getLogFilePath()) ffxFileHandler.setLevel(fileLogVerbosity) ffxConsoleHandler = logging.StreamHandler() ffxConsoleHandler.setLevel(consoleLogVerbosity) diff --git a/bin/ffx/configuration_controller.py b/bin/ffx/configuration_controller.py new file mode 100644 index 0000000..b1882c2 --- /dev/null +++ b/bin/ffx/configuration_controller.py @@ -0,0 +1,48 @@ +import os, json + +class ConfigurationController(): + + CONFIG_FILENAME = 'ffx.json' + DATABASE_FILENAME = 'ffx.db' + LOG_FILENAME = 'ffx.log' + + DATABASE_PATH_CONFIG_KEY = 'databasePath' + LOG_DIRECTORY_CONFIG_KEY = 'logDirectory' + + def __init__(self): + + self.__homeDir = os.path.expanduser("~") + self.__localVarDir = os.path.join(self.__homeDir, '.local', 'var') + self.__localEtcDir = os.path.join(self.__homeDir, '.local', 'etc') + + self.__configurationData = {} + + # .local/etc/ffx.json + self.__configFilePath = os.path.join(self.__localEtcDir, ConfigurationController.CONFIG_FILENAME) + if os.path.isfile(self.__configFilePath): + with open(self.__configFilePath, 'r') as configurationFile: + self.__configurationData = json.load(configurationFile) + + if ConfigurationController.DATABASE_PATH_CONFIG_KEY in self.__configurationData.keys(): + self.__databaseFilePath = self.__configurationData[ConfigurationController.DATABASE_PATH_CONFIG_KEY] + os.makedirs(os.path.dirname(self.__databaseFilePath), exist_ok=True) + else: + ffxVarDir = os.path.join(self.__localVarDir, 'ffx') + os.makedirs(ffxVarDir, exist_ok=True) + self.__databaseFilePath = os.path.join(ffxVarDir, ConfigurationController.DATABASE_FILENAME) + + if ConfigurationController.LOG_DIRECTORY_CONFIG_KEY in self.__configurationData.keys(): + self.__logDir = self.__configurationData[ConfigurationController.LOG_DIRECTORY_CONFIG_KEY] + else: + self.__logDir = os.path.join(self.__localVarDir, 'log') + os.makedirs(self.__logDir, exist_ok=True) + + + def getHomeDirectory(self): + return self.__homeDir + + def getLogFilePath(self): + return os.path.join(self.__logDir, ConfigurationController.LOG_FILENAME) + + def getDatabaseFilePath(self): + return self.__databaseFilePath diff --git a/bin/ffx/dashboard_screen.py b/bin/ffx/dashboard_screen.py deleted file mode 100644 index 31305a3..0000000 --- a/bin/ffx/dashboard_screen.py +++ /dev/null @@ -1,16 +0,0 @@ -from textual.app import App, ComposeResult -from textual.screen import Screen -from textual.widgets import Header, Footer, Placeholder, Label - -class DashboardScreen(Screen): - - def __init__(self): - super().__init__() - - context = self.app.getContext() - context['dashboard'] = 'dashboard' - - def compose(self) -> ComposeResult: - yield Header(show_clock=True) - yield Placeholder("Dashboard Screen") - yield Footer() diff --git a/bin/ffx/database.py b/bin/ffx/database.py index 5b1783a..0835a38 100644 --- a/bin/ffx/database.py +++ b/bin/ffx/database.py @@ -12,11 +12,11 @@ from ffx.model.track_tag import TrackTag def databaseContext(databasePath: str = ''): - """sqlite:///:memory:""" databaseContext = {} if databasePath is None: + # sqlite:///:memory: databasePath = ':memory:' elif not databasePath: homeDir = os.path.expanduser("~") diff --git a/bin/ffx/warning_screen.py b/bin/ffx/warning_screen.py deleted file mode 100644 index 1bed7f5..0000000 --- a/bin/ffx/warning_screen.py +++ /dev/null @@ -1,11 +0,0 @@ -from textual.app import App, ComposeResult -from textual.screen import Screen -from textual.widgets import Header, Footer, Placeholder, Label - -class WarningScreen(Screen): - def __init__(self): - super().__init__() - context = self.app.getContext() - def compose(self) -> ComposeResult: - yield Label("Warning! This file is not compliant to the defined source schema!") - yield Footer() diff --git a/bin/ffx_tests.py b/bin/ffx_tests.py index 8a2f03f..6b3b542 100755 --- a/bin/ffx_tests.py +++ b/bin/ffx_tests.py @@ -2,6 +2,8 @@ import os, logging, click +from ffx.configuration_controller import ConfigurationController + from ffx.file_properties import FileProperties from ffx.ffx_controller import FfxController @@ -21,6 +23,9 @@ def ffx(ctx, verbose, dry_run): """FFX""" ctx.obj = {} + + ctx.obj['config'] = ConfigurationController() + ctx.obj['database'] = None ctx.obj['dry_run'] = dry_run @@ -34,19 +39,13 @@ def ffx(ctx, verbose, dry_run): fileLogVerbosity = max(40 - verbose * 10, 10) consoleLogVerbosity = max(20 - verbose * 10, 10) - homeDir = os.path.expanduser("~") - ffxLogDir = os.path.join(homeDir, '.local', 'var', 'log') - if not os.path.exists(ffxLogDir): - os.makedirs(ffxLogDir) - ffxLogFilePath = os.path.join(ffxLogDir, 'ffx.tests.log') - ctx.obj['logger'] = logging.getLogger('FFX Tests') ctx.obj['logger'].setLevel(logging.DEBUG) ctx.obj['report_logger'] = logging.getLogger('FFX Test Result') ctx.obj['report_logger'].setLevel(logging.INFO) - ffxFileHandler = logging.FileHandler(ffxLogFilePath) + ffxFileHandler = logging.FileHandler(ctx.obj['config'].getLogFilePath()) ffxFileHandler.setLevel(fileLogVerbosity) ffxConsoleHandler = logging.StreamHandler() ffxConsoleHandler.setLevel(consoleLogVerbosity) diff --git a/bin/logg.py b/bin/logg.py deleted file mode 100755 index c9a84a7..0000000 --- a/bin/logg.py +++ /dev/null @@ -1,52 +0,0 @@ -#! /usr/bin/python3 - -import logging - -logger = logging.getLogger('FFX') -logger.setLevel(logging.DEBUG) - -testLogger = logging.getLogger('FFX Test') -testLogger.setLevel(logging.DEBUG) - - -# create file handler that logs debug and higher level messages -ffxFileHandler = logging.FileHandler('ffx.log') -ffxFileHandler.setLevel(logging.DEBUG) - -# create file handler that logs debug and higher level messages -ffxTestReportFileHandler = logging.FileHandler('ffx_test_report.log') -ffxTestReportFileHandler.setLevel(logging.DEBUG) - -# create console handler with a higher log level -ffxConsoleHandler = logging.StreamHandler() -#ffxConsoleHandler.setLevel(logging.ERROR) - -# create formatter and add it to the handlers -formatter = logging.Formatter( - '%(asctime)s - %(name)s - %(levelname)s - %(message)s') -ffxConsoleHandler.setFormatter(formatter) -ffxFileHandler.setFormatter(formatter) - - -# add the handlers to logger -testLogger.addHandler(ffxConsoleHandler) - - -logger.addHandler(ffxConsoleHandler) -logger.addHandler(ffxFileHandler) - - - -logger.debug('debug message') -logger.info('info message') -logger.warning('warn message') -logger.error('error message') -logger.critical('critical message') - - -testLogger.info('TEST: info message') - - - -click / consoleLogger - diff --git a/bin/prod.py b/bin/prod.py deleted file mode 100644 index 2d0cd01..0000000 --- a/bin/prod.py +++ /dev/null @@ -1,32 +0,0 @@ -import itertools - -class c1(): - def getYield(): - for i in range(3): - yield i - -class c2(): - def getYield(): - for i in range(5): - yield i - -class c3(): - def getYield(): - for i in range(7): - yield i -sc = {} -sc['y1'] = c1 -sc['y2'] = c2 -sc['y3'] = c3 - -sc_list = [(k,v) for k,v in sc.items()] - -y = [] -for p in itertools.product(*[v.getYield() for k,v in sc_list]): - z = {} - for i in range(len(p)): - z[sc_list[i][0]] = p[i] - y.append(z) -print(y) - - diff --git a/ffx_test_report.log b/ffx_test_report.log deleted file mode 100644 index e69de29..0000000