def load_app(configpath): global config config = yaml.safe_load(open(configpath)) if not config["sqlite"]["db"].startswith('/'): config["sqlite"][ "db"] = config["app_base_path"] + config["sqlite"]["db"] if not config["sqlite"]["schema"].startswith('/'): config["sqlite"][ "schema"] = config["app_base_path"] + config["sqlite"]["schema"] logging.config.dictConfig(config["logging"]) logging.info('Started') logger = getLogger(__name__) with app.app_context(): logging.info('Clearing all cached programs.') db = DB(app, config["sqlite"]["db"]) numrows = db.clear("programs") if numrows != None: logging.info('Expired resources deleted: ' + str(numrows)) logger.info("Application loaded using config: {}".format(config)) return app
def clear_table(db_name): with app.app_context(): logging.info('Clearing all rows from table: ' + db_name) db = DB(app, config["sqlite"]["db"]) numrows = db.clear(db_name) if numrows != None: line = 'Number of rows deleted from ' + db_name + ': ' + str( numrows) logging.info(line) response = Response(line) response.headers['Content-type'] = "text/plain" return (response, 200) else: line = "Failed to delete rows from table: " + db_name + " -- Mind you, there may have been no rows to delete." logging.info(line) logging.info("numrows was: {}".format(numrows)) return (line, 500)
logger.info("Application loaded using config: {}".format(config)) return app if __name__ == "__main__": from modules.config_parser import args config = yaml.safe_load(open(args.config)) if not config["sqlite"]["db"].startswith('/'): config["sqlite"][ "db"] = config["app_base_path"] + config["sqlite"]["db"] if not config["sqlite"]["schema"].startswith('/'): config["sqlite"][ "schema"] = config["app_base_path"] + config["sqlite"]["schema"] logging.config.dictConfig(config["logging"]) logging.info('Started') logger = getLogger(__name__) with app.app_context(): logging.info('Clearing all cached programs.') db = DB(app, config["sqlite"]["db"]) numrows = db.clear("programs") if numrows != None: logging.info('Expired resources deleted: ' + str(numrows)) logger.info("Application loaded using config: {}".format(config)) app.run(debug=True, host="0.0.0.0", port=8000)