From 4c120bb89f0960573d140e1431f308444530d198 Mon Sep 17 00:00:00 2001 From: dmt <> Date: Thu, 3 Oct 2019 18:59:33 +0200 Subject: [PATCH] Instead class attributes use descriptors. --- cml/shared/settings.py | 48 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/cml/shared/settings.py b/cml/shared/settings.py index 69bc969..3c9dbcf 100644 --- a/cml/shared/settings.py +++ b/cml/shared/settings.py @@ -1,13 +1,57 @@ """Settings module. """ + + from itertools import starmap from dataclasses import dataclass from configparser import ConfigParser -# TODO (dmt): Set default values -class Settings: +class SetFeatures: + def __init__(self): + self.set_features = None + + def __get__(self, instance, owner): + return self.set_features + + def __set__(self, instance, value): + # TODO (dmt): Validate user input! + self.set_features = [int(i) for i in value.split(",")] + + +class CutTimeStamp: + def __init__(self): + self.cut_time_stamp = False + + def __get__(self, instance, owner): + return self.cut_time_stamp + + def __set__(self, instance, value): + # TODO (dmt): Validate user input! + self.cut_time_stamp = bool(value) + + +class BlockSize: + def __init__(self): + self.block_size = None + + def __get__(self, instance, owner): + return self.block_size + + def __set__(self, instance, value): + # TODO (dmt): Validate user input! + self.block_size = int(value) + + +class MetaSettings(type): + SET_FEATURES: SetFeatures = SetFeatures() + CUT_TIME_STAMP: CutTimeStamp = CutTimeStamp() + BLOCK_SIZE: BlockSize = BlockSize() + + +# TODO (dmt): Set default values. +class Settings(metaclass=MetaSettings): INPUT_FILE: str = "" LEARN_DIR: str = "" MAX_LEARN_DIR: int = 0 -- GitLab