From 74aae9222d76a386085e42f9f00824e6a68c6a47 Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Sat, 24 Aug 2019 00:19:11 -0400 Subject: [PATCH] Changes conf settings to lowercase --- config/conf.json | 26 +++++++++++++------------- src/main.py | 16 ++++++++-------- src/server/app.py | 14 +++++++------- src/server/handles.py | 2 +- src/server/misc.py | 2 +- src/settings.py | 4 ++-- 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/config/conf.json b/config/conf.json index 4e4d027..75776dd 100644 --- a/config/conf.json +++ b/config/conf.json @@ -1,17 +1,17 @@ { - "PATH": { - "DATABASE": "database/default.db", - "ERROR_LOG": "logs/error.log", - "DEBUG_LOG": "logs/debug.log", - "SERVER_LOG": "logs/server.log" + "path": { + "database": "database/default.db", + "error_log": "logs/error.log", + "debug_log": "logs/debug.log", + "server_log": "logs/server.log" }, - "LOGGING": { - "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", - "DATEFMT": "%Y-%m-%d %H:%M:%S" + "logging": { + "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", + "datefmt": "%Y-%m-%d %H:%M:%S" }, - "HOST": "localhost", - "PORT": 5921, - "BACKUP_INT": 3600, - "LBRYNET": "http://localhost:5279" + "host": "localhost", + "port": 5921, + "backup_int": 3600, + "lbrynet": "http://localhost:5279" } \ No newline at end of file diff --git a/src/main.py b/src/main.py index 71f4cf7..859e224 100644 --- a/src/main.py +++ b/src/main.py @@ -13,12 +13,12 @@ def config_logging_from_settings(conf): "disable_existing_loggers": False, "formatters": { "standard": { - "format": conf['LOGGING']['FORMAT'], - "datefmt": conf['LOGGING']['DATEFMT'] + "format": conf['logging']['format'], + "datefmt": conf['logging']['datefmt'] }, "aiohttp": { - "format": conf['LOGGING']['AIOHTTP_FORMAT'], - "datefmt": conf['LOGGING']['DATEFMT'] + "format": conf['logging']['aiohttp_format'], + "datefmt": conf['logging']['datefmt'] } }, "handlers": { @@ -32,7 +32,7 @@ def config_logging_from_settings(conf): "level": "DEBUG", "formatter": "standard", "class": "logging.handlers.RotatingFileHandler", - "filename": conf['PATH']['DEBUG_LOG'], + "filename": conf['path']['debug_log'], "maxBytes": 10485760, "backupCount": 5 }, @@ -40,7 +40,7 @@ def config_logging_from_settings(conf): "level": "ERROR", "formatter": "standard", "class": "logging.handlers.RotatingFileHandler", - "filename": conf['PATH']['ERROR_LOG'], + "filename": conf['path']['error_log'], "maxBytes": 10485760, "backupCount": 5 }, @@ -48,7 +48,7 @@ def config_logging_from_settings(conf): "level": "NOTSET", "formatter": "aiohttp", "class": "logging.handlers.RotatingFileHandler", - "filename": conf['PATH']['SERVER_LOG'], + "filename": conf['path']['server_log'], "maxBytes": 10485760, "backupCount": 5 } @@ -77,7 +77,7 @@ def main(argv=None): args = parser.parse_args(argv) config_logging_from_settings(config) if args.port: - config['PORT'] = args.port + config['port'] = args.port config_logging_from_settings(config) run_app(config) diff --git a/src/server/app.py b/src/server/app.py index 520120f..bc4c7e1 100644 --- a/src/server/app.py +++ b/src/server/app.py @@ -27,7 +27,7 @@ async def setup_db_schema(app): async def database_backup_routine(app): try: while True: - await asyncio.sleep(app['config']['BACKUP_INT']) + await asyncio.sleep(app['config']['backup_int']) with app['reader'] as conn: logger.debug('backing up database') backup_database(conn, app['backup']) @@ -59,14 +59,14 @@ async def close_comment_scheduler(app): class CommentDaemon: def __init__(self, config, db_file=None, backup=None, **kwargs): - self.config = config app = web.Application() app['config'] = config + self.config = app['config'] if db_file: app['db_path'] = db_file app['backup'] = backup else: - app['db_path'] = config['PATH']['DATABASE'] + app['db_path'] = config['path']['database'] app['backup'] = backup or (app['db_path'] + '.backup') app.on_startup.append(setup_db_schema) app.on_startup.append(start_background_tasks) @@ -83,16 +83,16 @@ class CommentDaemon: self.app_site = 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) await self.app_runner.setup() self.app_site = web.TCPSite( runner=self.app_runner, - host=host or self.config['HOST'], - port=port or self.config['PORT'], + host=host or self.config['host'], + port=port or self.config['port'], ) 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): await self.app_runner.shutdown() diff --git a/src/server/handles.py b/src/server/handles.py index faeacb1..f098a99 100644 --- a/src/server/handles.py +++ b/src/server/handles.py @@ -129,5 +129,5 @@ async def get_api_endpoint(request: web.Request): return web.json_response({ 'text': 'OK', 'is_running': True, - 'uptime': int(time.time()) - request.app['START_TIME'] + 'uptime': int(time.time()) - request.app['start_time'] }) diff --git a/src/server/misc.py b/src/server/misc.py index 6db95f4..0e1e0c6 100644 --- a/src/server/misc.py +++ b/src/server/misc.py @@ -44,7 +44,7 @@ def make_error(error, exc=None) -> dict: async def request_lbrynet(app, method, **params): body = {'method': method, 'params': {**params}} 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: resp = await req.json() except JSONDecodeError as jde: diff --git a/src/settings.py b/src/settings.py index 4506d01..2d720c2 100644 --- a/src/settings.py +++ b/src/settings.py @@ -9,8 +9,8 @@ config_path = root_dir / 'config' / 'conf.json' def get_config(filepath): with open(filepath, 'r') as cfile: conf = json.load(cfile) - for key, path in conf['PATH'].items(): - conf['PATH'][key] = str(root_dir / path) + for key, path in conf['path'].items(): + conf['path'][key] = str(root_dir / path) return conf -- 2.45.2