moves settings into json format

This commit is contained in:
Oleg Silkin 2019-05-20 05:08:04 -04:00
parent c2c6d78442
commit 75fb6fd9ba
5 changed files with 38 additions and 12 deletions

14
config/conf.json Normal file
View file

@ -0,0 +1,14 @@
{
"files": {
"schema": "schema/comments_ddl.sql",
"main": "database/comments.db",
"backup": "database/comments.backup.db",
"dev": "database/example.db"
},
"anonymous": {
"channel_id": "9cb713f01bf247a0e03170b5ed00d5161340c486",
"channel_name": "@Anonymous"
},
"host": "localhost",
"port": "2903"
}

View file

@ -1,2 +1,5 @@
from lbry_comment_server.database import DatabaseConnection from lbry_comment_server.database import obtain_connection, generate_schema
from lbry_comment_server.conf import database_dir, anonymous from lbry_comment_server.database import get_comments_by_id, get_comment_ids, get_claim_comments, create_comment
from lbry_comment_server.database import create_backup, validate_input
from lbry_comment_server.conf import database_dir, anonymous, schema_dir, backup_dir, project_dir

View file

@ -1,9 +0,0 @@
project_dir = '/home/oleg/PycharmProjects/comment-server'
schema_dir = '/'.join((project_dir, 'schema/comments_ddl.sql',))
database_dir = '/'.join((project_dir, 'example.db',)) # change this
backup_dir = '/'.join((project_dir, 'example.backup.db'))
anonymous = {
'channel_id': '9cb713f01bf247a0e03170b5ed00d5161340c486',
'channel_name': '@Anonymous'
}

View file

@ -3,8 +3,9 @@ import json
from aiohttp import web from aiohttp import web
from settings import config
from lbry_comment_server import database_dir from lbry_comment_server import database_dir
from lbry_comment_server.database import DatabaseConnection from lbry_comment_server.database import obtain_connection
ERRORS = { ERRORS = {
'INVALID_PARAMS': {'code': -32602, 'message': 'Invalid parameters'}, 'INVALID_PARAMS': {'code': -32602, 'message': 'Invalid parameters'},

View file

@ -0,0 +1,17 @@
import json
import pathlib
root_dir = pathlib.Path(__file__).parent.parent
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['files'].items():
conf['files'][key] = str(root_dir / path)
return conf
config = get_config(config_path)
print(json.dumps(config, indent=4))