aboutsummaryrefslogtreecommitdiffstats
path: root/server.py
blob: e77485cb92d8eefe3bb5e8342913b1ff0b51971e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
from flask import Flask
from siteconfig import siteconfig

app = Flask(__name__)

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)
        ]
        app.config.update(
            {
                'MAIN_SITE_DIRS': sorted(top_dirs)
            }
        )

    app.config.update({'DOMAIN': siteconfig.DOMAIN})
    app.config.update({'HOME_TITLE': siteconfig.HOME_TITLE})

# Setup needs to come first to be compatible with wsgi
setup()
if __name__ == '__main__':
    app.run()