config becomes object-oriented and pytests have been added

This commit is contained in:
Yax 2021-01-01 11:17:09 +01:00
parent 19112245c0
commit b09a576b4b
2 changed files with 101 additions and 41 deletions

View file

@ -4,59 +4,62 @@
import profig
# constants
FLASK_APP = 'flask.app'
FLASK_APP = "flask.app"
DB_URL = 'main.db_url'
DB_FILE = 'main.db_file'
LANG = 'main.lang'
COMMENT_POLLING = 'main.newcomment_polling'
DB_URL = "main.db_url"
DB_BACKUP_JSON_FILE = "main.db_backup_json_file"
LANG = "main.lang"
COMMENT_POLLING = "main.newcomment_polling"
HTTP_HOST = 'http.host'
HTTP_PORT = 'http.port'
HTTP_HOST = "http.host"
HTTP_PORT = "http.port"
RSS_PROTO = 'rss.proto'
RSS_FILE = 'rss.file'
RSS_PROTO = "rss.proto"
RSS_FILE = "rss.file"
IMAP_POLLING = 'imap.polling'
IMAP_SSL = 'imap.ssl'
IMAP_HOST = 'imap.host'
IMAP_PORT = 'imap.port'
IMAP_LOGIN = 'imap.login'
IMAP_PASSWORD = 'imap.password'
IMAP_POLLING = "imap.polling"
IMAP_SSL = "imap.ssl"
IMAP_HOST = "imap.host"
IMAP_PORT = "imap.port"
IMAP_LOGIN = "imap.login"
IMAP_PASSWORD = "imap.password"
SMTP_STARTTLS = 'smtp.starttls'
SMTP_HOST = 'smtp.host'
SMTP_PORT = 'smtp.port'
SMTP_LOGIN = 'smtp.login'
SMTP_PASSWORD = 'smtp.password'
SMTP_STARTTLS = "smtp.starttls"
SMTP_HOST = "smtp.host"
SMTP_PORT = "smtp.port"
SMTP_LOGIN = "smtp.login"
SMTP_PASSWORD = "smtp.password"
SITE_NAME = 'site.name'
SITE_URL = 'site.url'
SITE_TOKEN = 'site.token'
SITE_ADMIN_EMAIL = 'site.admin_email'
# variable
params = dict()
SITE_NAME = "site.name"
SITE_URL = "site.url"
SITE_TOKEN = "site.token"
SITE_ADMIN_EMAIL = "site.admin_email"
def initialize(config_pathname, flask_app):
cfg = profig.Config(config_pathname)
cfg.sync()
params.update(cfg)
params.update({FLASK_APP: flask_app})
class Config:
def __init__(self):
self._params = dict()
@classmethod
def load(cls, config_pathname):
cfg = profig.Config(config_pathname)
cfg.sync()
config = cls()
config._params.update(cfg)
return config
def get(key):
return params[key]
def exists(self, key):
return key in self._params
def get(self, key):
return self._params[key] if key in self._params else None
def get_int(key):
return int(params[key])
def put(self, key, value):
self._params[key] = value
def get_int(self, key):
return int(self._params[key])
def get_bool(key):
return params[key].lower() in ('yes', 'true', '1')
def get_bool(self, key):
return self._params[key].lower() in ("yes", "true")
def flaskapp():
return params[FLASK_APP]