Files
python-store/store/__init__.py
2022-04-11 10:59:06 +02:00

31 lines
975 B
Python
Executable File

import os
import configparser
import socket
config = configparser.ConfigParser()
config.read([
os.path.join(os.path.dirname(__file__), 'store.cfg'),
os.path.expanduser('~/.store.cfg'),
os.environ.get('STORE_CONFIG', '')
])
PGPASS = '/nfsopt/mdevaluate/pgpass'
if os.path.exists(PGPASS):
with open(PGPASS) as f:
for pgpass in f:
hostname, *_, username, password = pgpass.split(':')
if hostname == 'db.cluster' and username == 'store':
config['store']['pg_password'] = password.strip()
# we sometimes have problems with the internal DNS, therefore try to resolve
# the database host in advance and use IP directly
try:
config['store']['pg_host'] = socket.gethostbyname(config['store']['pg_host'])
except OSError:
pass
from .store import get, update, delete, init_db, observables, systems, merge, dump_db
__all__ = ['get', 'update', 'delete', 'init_db', 'observables', 'systems', 'merge', 'dump_db']