Skip to content

Commit

Permalink
Rework configuration system
Browse files Browse the repository at this point in the history
Make DB connection params live in (replica.)my.cnf since we have only
one connection anyway. This makes the system with separate dev and prod
configs unneeded.
  • Loading branch information
MaxSem committed Jul 23, 2018
1 parent aab4477 commit cc5b748
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 31 deletions.
7 changes: 2 additions & 5 deletions commonsbot/config.py
Expand Up @@ -6,11 +6,8 @@
file = open(basedir + 'config.json', 'rt')
settings = json.loads(file.read())
file.close()
db_connections = settings['db_connections']

dry_run = False
if 'dry-run' in settings:
dry_run = settings['dry-run']
dry_run = settings['dry-run']

file = open(basedir + 'wikis-enabled', 'r')
wikis = set([s.strip() for s in file.readlines()])
Expand All @@ -26,4 +23,4 @@
if mysql_config_file is None:
raise OSError('replica.my.cnf not found!')

__all__ = ('settings', 'db_connections', 'mysql_config_file', 'dry_run')
__all__ = ('settings', 'mysql_config_file', 'dry_run')
8 changes: 2 additions & 6 deletions commonsbot/mysql.py
Expand Up @@ -13,12 +13,8 @@ def decode_tuple(tuple):
return result


def connect(connection_name):
conf = config.db_connections[connection_name]
return pymysql.connect(conf['host'],
port=conf['port'],
db=conf['database'],
read_default_file=config.mysql_config_file,
def connect():
return pymysql.connect(read_default_file=config.mysql_config_file,
charset='utf8',
use_unicode=True)

Expand Down
9 changes: 0 additions & 9 deletions config.dev.json

This file was deleted.

9 changes: 0 additions & 9 deletions config.prod.json

This file was deleted.

2 changes: 1 addition & 1 deletion make-list.py
Expand Up @@ -8,7 +8,7 @@
from pprint import pprint

commons = Site('commons', 'commons')
userdb = mysql.connect('userdb')
userdb = mysql.connect()
store = DeletionStateStore(userdb)


Expand Down
2 changes: 1 addition & 1 deletion post-notifs.py
Expand Up @@ -17,7 +17,7 @@
commons = Site('commons', 'commons')

def with_store(callable):
userdb = mysql.connect('userdb')
userdb = mysql.connect()
store = DeletionStateStore(userdb)
callable(store)
userdb.commit()
Expand Down

0 comments on commit cc5b748

Please sign in to comment.