""" server.py - sets up and runs the flask server """ import os from flask import Flask from siteconfig import siteconfig from flask_compress import Compress from flask_caching import Cache app = Flask(__name__) compress = Compress() cache = Cache(config=siteconfig.cache_config) from views import * def setup(): """ setup - sets up the app according to the settings specified (or not specified) in `siteconfig` """ if siteconfig.SECRET_KEY: app.config['SECRET_KEY'] = siteconfig.SECRET_KEY else: SECRET_KEY = os.urandom(32) app.config['SECRET_KEY'] = SECRET_KEY if siteconfig.MAIN_SITE_DIRS: app.config.update({'MAIN_SITE_DIRS': siteconfig.MAIN_SITE_DIRS}) else: s = "./templates/site/" top_dirs = [ x for x in os.listdir(s) if os.path.isdir(s + x) and not x.startswith(".") ] app.config.update({'MAIN_SITE_DIRS': sorted(top_dirs)}) app.config.update({'DOMAIN': siteconfig.DOMAIN}) app.config.update({'HOME_TITLE': siteconfig.HOME_TITLE}) app.config.update( {'COMPRESS_MIMETYPES': siteconfig.COMPRESS_MIMETYPES} ) # Setup needs to come first to be compatible with wsgi setup() if __name__ == "__main__": compress.init_app(app) cache.init_app(app) app.run()