config.py 1.41 KB
Newer Older
Nicolas Joyard committed
1 2 3 4 5 6 7 8
# -*- coding: utf-8 -*-

import os


BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


9
class DefaultConfig(object):
Nicolas Joyard committed
10 11
    DEBUG = False
    SECRET_KEY = 'not secret'
12 13
    SQLALCHEMY_DATABASE_URI = \
        'postgresql://parlapi:parlapi@localhost:5432/parlapi'
Nicolas Joyard committed
14 15
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    DATA_DIR = os.path.join(BASE_DIR, 'data')
16
    API_PAGE_SIZE = 10
Nicolas Joyard committed
17 18


19
class DebugConfig(DefaultConfig):
Nicolas Joyard committed
20 21 22
    DEBUG = True


23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
class OpenshiftConfig(DefaultConfig):
    SQLALCHEMY_DATABASE_URI = \
        'postgresql://%(user)s:%(pass)s@%(host)s:%(port)s/%(name)s' % {
            'name': os.environ['OPENSHIFT_APP_NAME'],
            'user': os.environ['OPENSHIFT_POSTGRESQL_DB_USERNAME'],
            'pass': os.environ['OPENSHIFT_POSTGRESQL_DB_PASSWORD'],
            'host': os.environ['OPENSHIFT_POSTGRESQL_DB_HOST'],
            'port': os.environ['OPENSHIFT_POSTGRESQL_DB_PORT'],
        }

    DATA_DIR = os.environ['OPENSHIFT_DATA_DIR']

    SECRET_FILE = os.path.join(DATA_DIR, 'secret.txt')
    if not os.path.exists(SECRET_FILE):
        chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'

        from random import SystemRandom
        rnd = SystemRandom()
        key = ''.join([chars[rnd.randint(1, len(chars))-1]
                       for i in range(1, 50)])

        with open(SECRET_FILE, 'w+') as f:
            f.write(key)

    with open(SECRET_FILE, 'r') as f:
        SECRET_KEY = f.read()