pick up config file from environment variable
This commit is contained in:
parent
8f0d383e20
commit
f10e8bb924
2 changed files with 34 additions and 8 deletions
|
@ -2,9 +2,12 @@ from sqlalchemy import create_engine
|
|||
from sqlalchemy.orm import scoped_session, sessionmaker
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
import yaml
|
||||
import os
|
||||
|
||||
with open("config.yaml", "rb") as config_file:
|
||||
config = yaml.load(config_file)
|
||||
configyaml = os.environ.get("CONFIG_FILE")
|
||||
|
||||
with open(configyaml, "rb") as config_file:
|
||||
config = yaml.load(config_file, Loader=yaml.SafeLoader)
|
||||
|
||||
engine = create_engine(config['SERVICE_DB'])
|
||||
db_session = scoped_session(sessionmaker(bind=engine))
|
||||
|
|
|
@ -7,6 +7,8 @@ import json
|
|||
import pnutpy
|
||||
import requests
|
||||
import magic
|
||||
import argparse
|
||||
import os
|
||||
|
||||
from matrix_client.api import MatrixHttpApi
|
||||
from matrix_client.api import MatrixError, MatrixRequestError
|
||||
|
@ -300,11 +302,32 @@ def wsthreader(threadfunc):
|
|||
return wrapper
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
|
||||
a_parser = argparse.ArgumentParser()
|
||||
a_parser.add_argument(
|
||||
'-d', action='store_true', dest='debug',
|
||||
help="debug logging"
|
||||
)
|
||||
# a_parser.add_argument(
|
||||
# '-c', '--config', default="config.yaml",
|
||||
# help="configuration file"
|
||||
# )
|
||||
args = a_parser.parse_args()
|
||||
|
||||
if args.debug:
|
||||
# websocket.enableTrace(True)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
else:
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
with open("config.yaml", "rb") as config_file:
|
||||
config = yaml.load(config_file)
|
||||
# with open(args.config, 'rb') as config_file:
|
||||
# config = yaml.load(config_file, Loader=yaml.SafeLoader)
|
||||
|
||||
configyaml = os.environ.get("CONFIG_FILE")
|
||||
|
||||
with open(configyaml, "rb") as config_file:
|
||||
config = yaml.load(config_file, Loader=yaml.SafeLoader)
|
||||
|
||||
ws_url = 'wss://stream.pnut.io/v0/app?access_token='
|
||||
ws_url += config['PNUT_APPTOKEN'] + '&key=' + config['PNUT_APPKEY']
|
||||
|
@ -326,7 +349,7 @@ if __name__ == '__main__':
|
|||
logger.debug("- sould join admin room -")
|
||||
join_room(config['MATRIX_ADMIN_ROOM'], config['MATRIX_AS_ID'])
|
||||
app.config.update(config)
|
||||
app.run(port=config['LISTEN_PORT'])
|
||||
app.run(host=config['LISTEN_HOST'], port=config['LISTEN_PORT'])
|
||||
|
||||
logger.info('!! shutdown initiated !!')
|
||||
_shutdown.set()
|
||||
|
|
Loading…
Reference in a new issue