2014-08-20 18:28:25 +03:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
from urlparse import urlparse
|
2013-12-03 22:09:57 +02:00
|
|
|
|
2014-09-18 00:13:10 +03:00
|
|
|
|
|
|
|
def update(data):
|
|
|
|
conf = read()
|
|
|
|
conf.update(data)
|
2014-10-17 00:54:45 +03:00
|
|
|
return save(data)
|
2014-09-18 00:13:10 +03:00
|
|
|
|
|
|
|
|
|
|
|
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()
|
2014-10-24 06:22:30 +03:00
|
|
|
|
|
|
|
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]
|
2014-09-18 00:13:10 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-09-18 00:13:10 +03:00
|
|
|
|
|
|
|
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
|
2014-09-18 00:13:10 +03:00
|
|
|
SQLALCHEMY_ECHO = False
|
2014-08-30 18:06:12 +03:00
|
|
|
|
2014-09-04 05:29:47 +03:00
|
|
|
PORT = 5000
|
2014-09-18 00:13:10 +03:00
|
|
|
BASE_URL = 'http://localhost'
|
2014-09-04 05:29:47 +03:00
|
|
|
SITE_TITLE = "Realms"
|
2013-12-03 22:09:57 +02:00
|
|
|
|
2014-10-03 21:49:18 +03: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'
|
2014-10-03 21:49:18 +03:00
|
|
|
# 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
|
|
|
|
|
|
|
CACHE_TYPE = 'simple'
|
|
|
|
|
2014-09-18 00:13:10 +03:00
|
|
|
# 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'
|
2014-09-18 00:13:10 +03:00
|
|
|
|
|
|
|
# Memcached
|
2014-11-13 23:07:14 +02:00
|
|
|
# CACHE_TYPE = 'memcached'
|
2014-09-18 00:13:10 +03:00
|
|
|
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'
|
|
|
|
|
2014-11-21 17:49:36 +02:00
|
|
|
# SEARCH_TYPE = 'whoosh'
|
2014-11-13 23:07:14 +02:00
|
|
|
WHOOSH_INDEX = '/tmp/whoosh'
|
2014-11-21 16:40:40 +02:00
|
|
|
WHOOSH_LANGUAGE = 'en'
|
2014-11-13 23:07:14 +02:00
|
|
|
|
2014-09-04 05:29:47 +03: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 = {}
|
|
|
|
|
2014-09-18 00:13:10 +03:00
|
|
|
SECRET_KEY = 'CHANGE_ME'
|
2013-12-03 22:09:57 +02:00
|
|
|
|
2014-09-14 06:47:17 +03:00
|
|
|
# Path on file system where wiki data will reside
|
2014-10-17 00:54:45 +03:00
|
|
|
WIKI_PATH = '/tmp/wiki'
|
2014-09-14 06:47:17 +03:00
|
|
|
|
|
|
|
# Name of page that will act as home
|
2014-08-20 18:28:25 +03:00
|
|
|
WIKI_HOME = 'home'
|
2014-09-14 06:47:17 +03:00
|
|
|
|
2014-08-20 18:28:25 +03:00
|
|
|
ALLOW_ANON = True
|
2014-09-14 06:47:17 +03:00
|
|
|
REGISTRATION_ENABLED = True
|
2015-07-18 12:02:59 +03:00
|
|
|
PRIVATE_WIKI = False
|
2014-09-14 06:47:17 +03:00
|
|
|
|
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
|
|
|
|
|
2014-09-10 21:58:47 +03:00
|
|
|
# Page names that can't be modified
|
2014-09-14 06:47:17 +03:00
|
|
|
WIKI_LOCKED_PAGES = []
|
2014-09-10 21:58:47 +03:00
|
|
|
|
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 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
|
|
|
|
2014-11-10 18:54:46 +02:00
|
|
|
MODULES = ['wiki', 'auth', 'search']
|