Merge pull request #4 from Tech-Workers-Coalition-Italia/conf
Basic configuration.
This commit is contained in:
commit
47f8c0aa17
|
@ -9,6 +9,9 @@ __pycache__/
|
|||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# Ignore dynaconf secret files
|
||||
**/.secrets.*
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
__version__ = '0.1.0'
|
||||
|
||||
|
||||
from . import publishers
|
|
@ -0,0 +1,25 @@
|
|||
import logging.config
|
||||
import sys
|
||||
from argparse import ArgumentParser
|
||||
|
||||
from config import settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def command_line():
|
||||
parser = ArgumentParser()
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def run():
|
||||
logging.config.dictConfig(settings.logging)
|
||||
logger.debug("Test message debug")
|
||||
logger.info("Test message info")
|
||||
logger.error("Test message error")
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
|
@ -0,0 +1,35 @@
|
|||
from dynaconf import Dynaconf, Validator
|
||||
|
||||
settings = Dynaconf(
|
||||
environments=True,
|
||||
envvar_prefix="MOBILIZON_BOTS",
|
||||
settings_files=[
|
||||
"mobilizon_bots/settings.toml",
|
||||
"mobilizon_bots/.secrets.toml",
|
||||
"/etc/mobilizon_bots.toml",
|
||||
"/etc/mobilizon_bots_secrets.toml",
|
||||
],
|
||||
validators=[
|
||||
# Ensure some parameters exists (are required)
|
||||
Validator("local_state_dir", "log_dir", "db_path", must_exist=True),
|
||||
# Ensure some parameter mets a condition
|
||||
# conditions: (eq, ne, lt, gt, lte, gte, identity, is_type_of, is_in, is_not_in)
|
||||
Validator("local_state_dir", "log_dir", "db_path", is_type_of=str),
|
||||
# check file or directory
|
||||
# validate a value is eq in specific env
|
||||
# Validator('PROJECT', eq='hello_world', env='production'),
|
||||
#
|
||||
# # Ensure some parameter (string) meets a condition
|
||||
# # conditions: (len_eq, len_ne, len_min, len_max, cont)
|
||||
# # Determines the minimum and maximum length for the value
|
||||
# Validator("NAME", len_min=3, len_max=125),
|
||||
#
|
||||
# # Signifies the presence of the value in a set, text or word
|
||||
# Validator("DEV_SERVERS", cont='localhost'),
|
||||
#
|
||||
# # Checks whether the length is the same as defined.
|
||||
# Validator("PORT", len_eq=4),
|
||||
],
|
||||
)
|
||||
|
||||
settings.validators.validate()
|
|
@ -0,0 +1,39 @@
|
|||
[default]
|
||||
debug = true
|
||||
default = true
|
||||
local_state_dir = "/var/mobots"
|
||||
log_dir = "/var/log/mobots"
|
||||
db_name = "events.db"
|
||||
db_path = "@format {this.local_state_dir}/{this.db_name}"
|
||||
|
||||
[default.logging]
|
||||
version = 1
|
||||
disable_existing_loggers = false
|
||||
|
||||
[default.logging.formatters.standard]
|
||||
format = '[%(asctime)s] [%(levelno)s] [%(levelname)s] %(message)s'
|
||||
|
||||
[default.logging.handlers.console]
|
||||
level = "INFO"
|
||||
class = "logging.StreamHandler"
|
||||
formatter = "standard"
|
||||
stream = "ext://sys.stderr"
|
||||
|
||||
[default.logging.handlers.logfile]
|
||||
level = "DEBUG"
|
||||
class = "logging.handlers.RotatingFileHandler"
|
||||
formatter = "standard"
|
||||
filename = "@format {this.log_dir}/mobilizon_bots.log"
|
||||
maxBytes = 52428800
|
||||
backupCount = 500
|
||||
encoding = "utf8"
|
||||
|
||||
[default.logging.root]
|
||||
level = "DEBUG"
|
||||
handlers = ['console', 'logfile']
|
||||
|
||||
[testing]
|
||||
DEBUG = true
|
||||
LOCAL_STATE_DIR = "/tmp/mobots"
|
||||
LOG_DIR = "/tmp/mobots"
|
||||
DB_PATH = ":memory:"
|
|
@ -12,7 +12,7 @@ aiosqlite = "^0.16"
|
|||
Jinja2 = "^2.11.3"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
pytest = "^5.2"
|
||||
pytest = "^5.3"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
|
|
Loading…
Reference in New Issue