Tests passed, Config-File
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
__pycache__
|
||||
junk/
|
||||
.vscode/launch.json
|
||||
.ipynb_checkpoints/
|
||||
|
||||
32
bin/check.py
32
bin/check.py
@@ -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))
|
||||
@@ -1,6 +0,0 @@
|
||||
from ffx.helper import dictDiff
|
||||
|
||||
a = {'name': 'yolo', 'mass': 56}
|
||||
b = {'name': 'zolo', 'mass': 58}
|
||||
|
||||
print(dictDiff(a, b))
|
||||
22
bin/ffx.py
22
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)
|
||||
|
||||
48
bin/ffx/configuration_controller.py
Normal file
48
bin/ffx/configuration_controller.py
Normal file
@@ -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
|
||||
@@ -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()
|
||||
@@ -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("~")
|
||||
|
||||
@@ -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()
|
||||
@@ -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)
|
||||
|
||||
52
bin/logg.py
52
bin/logg.py
@@ -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
|
||||
|
||||
32
bin/prod.py
32
bin/prod.py
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user