ytsm/app/YtManagerApp/management/appconfig.py

35 lines
1.2 KiB
Python
Raw Normal View History

from dynamic_preferences.registries import global_preferences_registry
from YtManagerApp.dynamic_preferences_registry import Initialized, YouTubeAPIKey, AllowRegistrations, SyncSchedule, SchedulerConcurrency
class AppConfig(object):
# Properties
props = {
'initialized': Initialized,
'youtube_api_key': YouTubeAPIKey,
'allow_registrations': AllowRegistrations,
'sync_schedule': SyncSchedule,
'concurrency': SchedulerConcurrency
}
# Init
def __init__(self, pref_manager):
self.__pref_manager = pref_manager
def __getattr__(self, item):
prop_class = AppConfig.props[item]
prop_full_name = prop_class.section.name + "__" + prop_class.name
return self.__pref_manager[prop_full_name]
def __setattr__(self, key, value):
if key in AppConfig.props:
prop_class = AppConfig.props[key]
prop_full_name = prop_class.section.name + "__" + prop_class.name
self.__pref_manager[prop_full_name] = value
else:
super().__setattr__(key, value)
global_prefs = global_preferences_registry.manager()
appconfig = AppConfig(global_prefs)