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.orm import scoped_session, sessionmaker
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
import yaml
|
import yaml
|
||||||
|
import os
|
||||||
|
|
||||||
with open("config.yaml", "rb") as config_file:
|
configyaml = os.environ.get("CONFIG_FILE")
|
||||||
config = yaml.load(config_file)
|
|
||||||
|
with open(configyaml, "rb") as config_file:
|
||||||
|
config = yaml.load(config_file, Loader=yaml.SafeLoader)
|
||||||
|
|
||||||
engine = create_engine(config['SERVICE_DB'])
|
engine = create_engine(config['SERVICE_DB'])
|
||||||
db_session = scoped_session(sessionmaker(bind=engine))
|
db_session = scoped_session(sessionmaker(bind=engine))
|
||||||
|
|
|
@ -7,6 +7,8 @@ import json
|
||||||
import pnutpy
|
import pnutpy
|
||||||
import requests
|
import requests
|
||||||
import magic
|
import magic
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
|
||||||
from matrix_client.api import MatrixHttpApi
|
from matrix_client.api import MatrixHttpApi
|
||||||
from matrix_client.api import MatrixError, MatrixRequestError
|
from matrix_client.api import MatrixError, MatrixRequestError
|
||||||
|
@ -300,12 +302,33 @@ def wsthreader(threadfunc):
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# websocket.enableTrace(True)
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
|
||||||
|
|
||||||
with open("config.yaml", "rb") as config_file:
|
|
||||||
config = yaml.load(config_file)
|
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(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 = 'wss://stream.pnut.io/v0/app?access_token='
|
||||||
ws_url += config['PNUT_APPTOKEN'] + '&key=' + config['PNUT_APPKEY']
|
ws_url += config['PNUT_APPTOKEN'] + '&key=' + config['PNUT_APPKEY']
|
||||||
ws_url += '&include_raw=1'
|
ws_url += '&include_raw=1'
|
||||||
|
@ -326,7 +349,7 @@ if __name__ == '__main__':
|
||||||
logger.debug("- sould join admin room -")
|
logger.debug("- sould join admin room -")
|
||||||
join_room(config['MATRIX_ADMIN_ROOM'], config['MATRIX_AS_ID'])
|
join_room(config['MATRIX_ADMIN_ROOM'], config['MATRIX_AS_ID'])
|
||||||
app.config.update(config)
|
app.config.update(config)
|
||||||
app.run(port=config['LISTEN_PORT'])
|
app.run(host=config['LISTEN_HOST'], port=config['LISTEN_PORT'])
|
||||||
|
|
||||||
logger.info('!! shutdown initiated !!')
|
logger.info('!! shutdown initiated !!')
|
||||||
_shutdown.set()
|
_shutdown.set()
|
||||||
|
|
Loading…
Reference in a new issue