mirror of https://github.com/kianby/stacosys
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.
66 lines
1.6 KiB
Python
66 lines
1.6 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from enum import Enum
|
|
import profig
|
|
|
|
|
|
class ConfigParameter(Enum):
|
|
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"
|
|
|
|
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"
|
|
|
|
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"
|
|
|
|
|
|
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 exists(self, key: ConfigParameter):
|
|
return key.value in self._params
|
|
|
|
def get(self, key: ConfigParameter):
|
|
return self._params[key.value] if key.value in self._params else None
|
|
|
|
def put(self, key: ConfigParameter, value):
|
|
self._params[key.value] = value
|
|
|
|
def get_int(self, key: ConfigParameter):
|
|
return int(self._params[key.value])
|
|
|
|
def get_bool(self, key: ConfigParameter):
|
|
return self._params[key.value].lower() in ("yes", "true")
|
|
|