Changes conf settings to lowercase #12

Merged
osilkin98 merged 1 commit from conf-lowercase into master 2019-08-24 06:35:41 +02:00
6 changed files with 32 additions and 32 deletions

View file

@ -1,17 +1,17 @@
{ {
"PATH": { "path": {
"DATABASE": "database/default.db", "database": "database/default.db",
"ERROR_LOG": "logs/error.log", "error_log": "logs/error.log",
"DEBUG_LOG": "logs/debug.log", "debug_log": "logs/debug.log",
"SERVER_LOG": "logs/server.log" "server_log": "logs/server.log"
}, },
"LOGGING": { "logging": {
"FORMAT": "%(asctime)s | %(levelname)s | %(name)s | %(module)s.%(funcName)s:%(lineno)d | %(message)s", "format": "%(asctime)s | %(levelname)s | %(name)s | %(module)s.%(funcName)s:%(lineno)d | %(message)s",
"AIOHTTP_FORMAT": "%(asctime)s | %(levelname)s | %(name)s | %(message)s", "aiohttp_format": "%(asctime)s | %(levelname)s | %(name)s | %(message)s",
"DATEFMT": "%Y-%m-%d %H:%M:%S" "datefmt": "%Y-%m-%d %H:%M:%S"
}, },
"HOST": "localhost", "host": "localhost",
"PORT": 5921, "port": 5921,
"BACKUP_INT": 3600, "backup_int": 3600,
"LBRYNET": "http://localhost:5279" "lbrynet": "http://localhost:5279"
} }

View file

@ -13,12 +13,12 @@ def config_logging_from_settings(conf):
"disable_existing_loggers": False, "disable_existing_loggers": False,
"formatters": { "formatters": {
"standard": { "standard": {
"format": conf['LOGGING']['FORMAT'], "format": conf['logging']['format'],
"datefmt": conf['LOGGING']['DATEFMT'] "datefmt": conf['logging']['datefmt']
}, },
"aiohttp": { "aiohttp": {
"format": conf['LOGGING']['AIOHTTP_FORMAT'], "format": conf['logging']['aiohttp_format'],
"datefmt": conf['LOGGING']['DATEFMT'] "datefmt": conf['logging']['datefmt']
} }
}, },
"handlers": { "handlers": {
@ -32,7 +32,7 @@ def config_logging_from_settings(conf):
"level": "DEBUG", "level": "DEBUG",
"formatter": "standard", "formatter": "standard",
"class": "logging.handlers.RotatingFileHandler", "class": "logging.handlers.RotatingFileHandler",
"filename": conf['PATH']['DEBUG_LOG'], "filename": conf['path']['debug_log'],
"maxBytes": 10485760, "maxBytes": 10485760,
"backupCount": 5 "backupCount": 5
}, },
@ -40,7 +40,7 @@ def config_logging_from_settings(conf):
"level": "ERROR", "level": "ERROR",
"formatter": "standard", "formatter": "standard",
"class": "logging.handlers.RotatingFileHandler", "class": "logging.handlers.RotatingFileHandler",
"filename": conf['PATH']['ERROR_LOG'], "filename": conf['path']['error_log'],
"maxBytes": 10485760, "maxBytes": 10485760,
"backupCount": 5 "backupCount": 5
}, },
@ -48,7 +48,7 @@ def config_logging_from_settings(conf):
"level": "NOTSET", "level": "NOTSET",
"formatter": "aiohttp", "formatter": "aiohttp",
"class": "logging.handlers.RotatingFileHandler", "class": "logging.handlers.RotatingFileHandler",
"filename": conf['PATH']['SERVER_LOG'], "filename": conf['path']['server_log'],
"maxBytes": 10485760, "maxBytes": 10485760,
"backupCount": 5 "backupCount": 5
} }
@ -77,7 +77,7 @@ def main(argv=None):
args = parser.parse_args(argv) args = parser.parse_args(argv)
config_logging_from_settings(config) config_logging_from_settings(config)
if args.port: if args.port:
config['PORT'] = args.port config['port'] = args.port
config_logging_from_settings(config) config_logging_from_settings(config)
run_app(config) run_app(config)

View file

@ -27,7 +27,7 @@ async def setup_db_schema(app):
async def database_backup_routine(app): async def database_backup_routine(app):
try: try:
while True: while True:
await asyncio.sleep(app['config']['BACKUP_INT']) await asyncio.sleep(app['config']['backup_int'])
with app['reader'] as conn: with app['reader'] as conn:
logger.debug('backing up database') logger.debug('backing up database')
backup_database(conn, app['backup']) backup_database(conn, app['backup'])
@ -59,14 +59,14 @@ async def close_comment_scheduler(app):
class CommentDaemon: class CommentDaemon:
def __init__(self, config, db_file=None, backup=None, **kwargs): def __init__(self, config, db_file=None, backup=None, **kwargs):
self.config = config
app = web.Application() app = web.Application()
app['config'] = config app['config'] = config
self.config = app['config']
if db_file: if db_file:
app['db_path'] = db_file app['db_path'] = db_file
app['backup'] = backup app['backup'] = backup
else: else:
app['db_path'] = config['PATH']['DATABASE'] app['db_path'] = config['path']['database']
app['backup'] = backup or (app['db_path'] + '.backup') app['backup'] = backup or (app['db_path'] + '.backup')
app.on_startup.append(setup_db_schema) app.on_startup.append(setup_db_schema)
app.on_startup.append(start_background_tasks) app.on_startup.append(start_background_tasks)
@ -83,16 +83,16 @@ class CommentDaemon:
self.app_site = None self.app_site = None
async def start(self, host=None, port=None): async def start(self, host=None, port=None):
self.app['START_TIME'] = time.time() self.app['start_time'] = time.time()
self.app_runner = web.AppRunner(self.app) self.app_runner = web.AppRunner(self.app)
await self.app_runner.setup() await self.app_runner.setup()
self.app_site = web.TCPSite( self.app_site = web.TCPSite(
runner=self.app_runner, runner=self.app_runner,
host=host or self.config['HOST'], host=host or self.config['host'],
port=port or self.config['PORT'], port=port or self.config['port'],
) )
await self.app_site.start() await self.app_site.start()
logger.info(f'Comment Server is running on {self.config["HOST"]}:{self.config["PORT"]}') logger.info(f'Comment Server is running on {self.config["host"]}:{self.config["port"]}')
async def stop(self): async def stop(self):
await self.app_runner.shutdown() await self.app_runner.shutdown()

View file

@ -129,5 +129,5 @@ async def get_api_endpoint(request: web.Request):
return web.json_response({ return web.json_response({
'text': 'OK', 'text': 'OK',
'is_running': True, 'is_running': True,
'uptime': int(time.time()) - request.app['START_TIME'] 'uptime': int(time.time()) - request.app['start_time']
}) })

View file

@ -44,7 +44,7 @@ def make_error(error, exc=None) -> dict:
async def request_lbrynet(app, method, **params): async def request_lbrynet(app, method, **params):
body = {'method': method, 'params': {**params}} body = {'method': method, 'params': {**params}}
try: try:
async with aiohttp.request('POST', app['config']['LBRYNET'], json=body) as req: async with aiohttp.request('POST', app['config']['lbrynet'], json=body) as req:
try: try:
resp = await req.json() resp = await req.json()
except JSONDecodeError as jde: except JSONDecodeError as jde:

View file

@ -9,8 +9,8 @@ config_path = root_dir / 'config' / 'conf.json'
def get_config(filepath): def get_config(filepath):
with open(filepath, 'r') as cfile: with open(filepath, 'r') as cfile:
conf = json.load(cfile) conf = json.load(cfile)
for key, path in conf['PATH'].items(): for key, path in conf['path'].items():
conf['PATH'][key] = str(root_dir / path) conf['path'][key] = str(root_dir / path)
return conf return conf