You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
import os, sys, importlib, inspect, glob, re
|
|
|
|
from ffx.configuration_controller import ConfigurationController
|
|
from ffx.database import databaseContext
|
|
|
|
from sqlalchemy import Engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
|
|
class Conversion():
|
|
|
|
def __init__(self):
|
|
|
|
self._context = {}
|
|
self._context['config'] = ConfigurationController()
|
|
|
|
self._context['database'] = databaseContext(databasePath=self._context['config'].getDatabaseFilePath())
|
|
|
|
self.__databaseSession: sessionmaker = self._context['database']['session']
|
|
self.__databaseEngine: Engine = self._context['database']['engine']
|
|
|
|
|
|
@staticmethod
|
|
def list():
|
|
|
|
basePath = os.path.dirname(__file__)
|
|
|
|
filenamePattern = re.compile("conversion_([0-9]+)_([0-9]+)\\.py")
|
|
|
|
filenameList = [os.path.basename(fp) for fp in glob.glob(f"{ basePath }/*.py") if fp != __file__]
|
|
|
|
versionTupleList = [(fm.group(1), fm.group(2)) for fn in filenameList if (fm := filenamePattern.search(fn))]
|
|
|
|
return versionTupleList
|
|
|
|
|
|
@staticmethod
|
|
def getClassReference(versionFrom, versionTo):
|
|
importlib.import_module(f"ffx.model.conversions.conversion_{ versionFrom }_{ versionTo }")
|
|
for name, obj in inspect.getmembers(sys.modules[f"ffx.model.conversions.conversion_{ versionFrom }_{ versionTo }"]):
|
|
#HINT: Excluding DispositionCombination as it seems to be included by import (?)
|
|
if inspect.isclass(obj) and name != 'Conversion' and name.startswith('Conversion'):
|
|
return obj
|
|
|
|
@staticmethod
|
|
def getAllClassReferences():
|
|
return [Conversion.getClassReference(verFrom, verTo) for verFrom, verTo in Conversion.list()]
|