realms-wiki/realms/config/__init__.py

197 lines
4.5 KiB
Python
Raw Normal View History

2014-08-20 18:28:25 +03:00
import os
import json
from urlparse import urlparse
from realms.lib.util import in_vagrant
def update(data):
conf = read()
conf.update(data)
2014-10-17 00:54:45 +03:00
return save(data)
def read():
conf = dict()
2014-10-17 00:54:45 +03:00
for k, v in os.environ.items():
if k.startswith('REALMS_'):
conf[k[7:]] = v
2014-10-24 02:58:58 +03:00
loc = get_path()
if loc:
with open(loc) as f:
conf.update(json.load(f))
2014-10-17 00:54:45 +03:00
for k in ['APP_PATH', 'USER_HOME']:
if k in conf:
del conf[k]
return conf
def save(conf):
2014-10-24 02:58:58 +03:00
loc = get_path(check_write=True)
with open(loc, 'w') as f:
f.write(json.dumps(conf, sort_keys=True, indent=4, separators=(',', ': ')).strip() + '\n')
return loc
def get_path(check_write=False):
"""Find config path
"""
2014-11-21 20:27:34 +02:00
for loc in os.curdir, os.path.expanduser("~"), "/etc/realms-wiki":
2014-10-24 02:58:58 +03:00
if not loc:
continue
path = os.path.join(loc, "realms-wiki.json")
if os.path.isfile(path):
# file exists
if not check_write:
# Don't care if I can write
return path
if os.access(path, os.W_OK):
# Has write access, ok!
return path
elif os.path.isdir(loc) and check_write:
# dir exists file doesn't
if os.access(loc, os.W_OK):
# can write file
return path
return None
APP_PATH = os.path.abspath(os.path.dirname(__file__) + "/../..")
USER_HOME = os.path.abspath(os.path.expanduser("~"))
2014-09-02 17:29:04 +03:00
2014-10-17 00:54:45 +03:00
# Best to change to /var/run
PIDFILE = "/tmp/realms-wiki.pid"
2014-08-20 18:28:25 +03:00
ENV = 'DEV'
2013-12-03 22:09:57 +02:00
2014-08-20 18:28:25 +03:00
DEBUG = True
ASSETS_DEBUG = True
SQLALCHEMY_ECHO = False
2014-08-30 18:06:12 +03:00
PORT = 5000
BASE_URL = 'http://localhost'
SITE_TITLE = "Realms"
2013-12-03 22:09:57 +02:00
# https://pythonhosted.org/Flask-SQLAlchemy/config.html#connection-uri-format
2014-10-17 00:54:45 +03:00
DB_URI = 'sqlite:////tmp/wiki.db'
# DB_URI = 'mysql://scott:tiger@localhost/mydatabase'
# DB_URI = 'postgresql://scott:tiger@localhost/mydatabase'
# DB_URI = 'oracle://scott:tiger@127.0.0.1:1521/sidname'
2014-10-24 02:58:58 +03:00
# DB_URI = 'crate://'
2014-08-30 18:06:12 +03:00
2015-10-15 01:36:22 +03:00
LDAP = {
'URI': 'ldap://localhost:8389',
# This BIND_DN/BIND_PASSWORD default to '', this is shown here for demonstrative purposes
2015-10-15 01:36:22 +03:00
# The values '' perform an anonymous bind so we may use search/bind method
'BIND_DN': '',
'BIND_AUTH': '',
# Adding the USER_SEARCH field tells the flask-ldap-login that we are using
# the search/bind method
'USER_SEARCH': {'base': 'dc=example,dc=com', 'filter': 'uid=%(username)s'},
# Map ldap keys into application specific keys
'KEY_MAP': {
'name': 'cn',
'company': 'o',
'location': 'l',
'email': 'mail',
}
}
OAUTH = {
'twitter': {
'key': '',
'secret': ''
},
'github': {
'key': '',
'secret': ''
}
}
2014-08-30 18:06:12 +03:00
CACHE_TYPE = 'simple'
# Redis
2014-11-13 23:07:14 +02:00
# CACHE_TYPE = 'redis'
2014-08-30 18:06:12 +03:00
CACHE_REDIS_HOST = '127.0.0.1'
CACHE_REDIS_PORT = 6379
CACHE_REDIS_DB = '0'
# Memcached
2014-11-13 23:07:14 +02:00
# CACHE_TYPE = 'memcached'
CACHE_MEMCACHED_SERVERS = ['127.0.0.1:11211']
2014-11-21 17:49:36 +02:00
SEARCH_TYPE = 'simple' # simple is not good for large wikis
2014-11-13 01:06:56 +02:00
# SEARCH_TYPE = 'elasticsearch'
2014-11-10 18:54:46 +02:00
ELASTICSEARCH_URL = 'http://127.0.0.1:9200'
ELASTICSEARCH_FIELDS = ["name"]
2014-11-10 18:54:46 +02:00
2014-11-21 17:49:36 +02:00
# SEARCH_TYPE = 'whoosh'
2014-11-13 23:07:14 +02:00
WHOOSH_INDEX = '/tmp/whoosh'
WHOOSH_LANGUAGE = 'en'
2014-11-13 23:07:14 +02:00
# Get ReCaptcha Keys for your domain here:
# https://www.google.com/recaptcha/admin#whyrecaptcha
2014-09-02 17:29:04 +03:00
RECAPTCHA_ENABLE = False
2014-08-30 18:06:12 +03:00
RECAPTCHA_USE_SSL = False
RECAPTCHA_PUBLIC_KEY = "6LfYbPkSAAAAAB4a2lG2Y_Yjik7MG9l4TDzyKUao"
RECAPTCHA_PRIVATE_KEY = "6LfYbPkSAAAAAG-KlkwjZ8JLWgwc9T0ytkN7lWRE"
RECAPTCHA_OPTIONS = {}
SECRET_KEY = 'CHANGE_ME'
2013-12-03 22:09:57 +02:00
# Path on file system where wiki data will reside
2014-10-17 00:54:45 +03:00
WIKI_PATH = '/tmp/wiki'
# Name of page that will act as home
2014-08-20 18:28:25 +03:00
WIKI_HOME = 'home'
2014-08-20 18:28:25 +03:00
ALLOW_ANON = True
REGISTRATION_ENABLED = True
PRIVATE_WIKI = False
2014-10-17 00:54:45 +03:00
# None, firepad, and/or togetherjs
2014-10-02 01:14:54 +03:00
COLLABORATION = 'togetherjs'
# Required for firepad
FIREBASE_HOSTNAME = None
# Page names that can't be modified
WIKI_LOCKED_PAGES = []
2013-12-03 22:09:57 +02:00
ROOT_ENDPOINT = 'wiki.page'
2014-10-17 00:54:45 +03:00
globals().update(read())
2014-08-20 18:28:25 +03:00
2014-10-31 00:59:19 +02:00
# Used by Flask-Login
LOGIN_DISABLED = ALLOW_ANON
2014-10-24 22:55:12 +03:00
# Depreciated variable name
LOCKED = WIKI_LOCKED_PAGES[:]
2014-08-20 18:28:25 +03:00
if BASE_URL.endswith('/'):
BASE_URL = BASE_URL[-1]
2014-08-30 18:06:12 +03:00
SQLALCHEMY_DATABASE_URI = DB_URI
2014-08-20 18:28:25 +03:00
_url = urlparse(BASE_URL)
RELATIVE_PATH = _url.path
if in_vagrant():
# sendfile doesn't work well with Virtualbox shared folders
USE_X_SENDFILE = False
2014-08-20 18:28:25 +03:00
if ENV != "DEV":
DEBUG = False
ASSETS_DEBUG = False
2014-09-02 17:29:04 +03:00
SQLALCHEMY_ECHO = False
2014-08-20 18:28:25 +03:00
2015-10-16 01:36:47 +03:00
MODULES = ['wiki', 'search', 'auth', 'auth.local', 'auth.oauth', 'auth.ldap', 'auth.oauth']