Git based wiki inspired by Gollum
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
3.2KB

  1. import os
  2. import json
  3. from urlparse import urlparse
  4. def update(data):
  5. conf = read()
  6. conf.update(data)
  7. return save(data)
  8. def read():
  9. conf = dict()
  10. for k, v in os.environ.items():
  11. if k.startswith('REALMS_'):
  12. conf[k[7:]] = v
  13. loc = get_path()
  14. with open(loc) as f:
  15. conf.update(json.load(f))
  16. for k in ['APP_PATH', 'USER_HOME']:
  17. if k in conf:
  18. del conf[k]
  19. return conf
  20. def save(conf):
  21. loc = get_path(check_write=True)
  22. with open(loc, 'w') as f:
  23. f.write(json.dumps(conf, sort_keys=True, indent=4, separators=(',', ': ')).strip() + '\n')
  24. return loc
  25. def get_path(check_write=False):
  26. """Find config path
  27. """
  28. for loc in "/etc/realms-wiki", os.path.expanduser("~"), os.curdir:
  29. if not loc:
  30. continue
  31. path = os.path.join(loc, "realms-wiki.json")
  32. if os.path.isfile(path):
  33. # file exists
  34. if not check_write:
  35. # Don't care if I can write
  36. return path
  37. if os.access(path, os.W_OK):
  38. # Has write access, ok!
  39. return path
  40. elif os.path.isdir(loc) and check_write:
  41. # dir exists file doesn't
  42. if os.access(loc, os.W_OK):
  43. # can write file
  44. return path
  45. return None
  46. APP_PATH = os.path.abspath(os.path.dirname(__file__) + "/../..")
  47. USER_HOME = os.path.abspath(os.path.expanduser("~"))
  48. # Best to change to /var/run
  49. PIDFILE = "/tmp/realms-wiki.pid"
  50. ENV = 'DEV'
  51. DEBUG = True
  52. ASSETS_DEBUG = True
  53. SQLALCHEMY_ECHO = False
  54. PORT = 5000
  55. BASE_URL = 'http://localhost'
  56. SITE_TITLE = "Realms"
  57. # https://pythonhosted.org/Flask-SQLAlchemy/config.html#connection-uri-format
  58. DB_URI = 'sqlite:////tmp/wiki.db'
  59. # DB_URI = 'mysql://scott:tiger@localhost/mydatabase'
  60. # DB_URI = 'postgresql://scott:tiger@localhost/mydatabase'
  61. # DB_URI = 'oracle://scott:tiger@127.0.0.1:1521/sidname'
  62. # DB_URI = 'crate://'
  63. CACHE_TYPE = 'simple'
  64. # Redis
  65. #CACHE_TYPE = 'redis'
  66. CACHE_REDIS_HOST = '127.0.0.1'
  67. CACHE_REDIS_PORT = 6379
  68. CACHE_REDIS_DB = '0'
  69. # Memcached
  70. #CACHE_TYPE = 'memcached'
  71. CACHE_MEMCACHED_SERVERS = ['127.0.0.1:11211']
  72. # Get ReCaptcha Keys for your domain here:
  73. # https://www.google.com/recaptcha/admin#whyrecaptcha
  74. RECAPTCHA_ENABLE = False
  75. RECAPTCHA_USE_SSL = False
  76. RECAPTCHA_PUBLIC_KEY = "6LfYbPkSAAAAAB4a2lG2Y_Yjik7MG9l4TDzyKUao"
  77. RECAPTCHA_PRIVATE_KEY = "6LfYbPkSAAAAAG-KlkwjZ8JLWgwc9T0ytkN7lWRE"
  78. RECAPTCHA_OPTIONS = {}
  79. SECRET_KEY = 'CHANGE_ME'
  80. # Path on file system where wiki data will reside
  81. WIKI_PATH = '/tmp/wiki'
  82. # Name of page that will act as home
  83. WIKI_HOME = 'home'
  84. ALLOW_ANON = True
  85. REGISTRATION_ENABLED = True
  86. # Used by Flask-Login
  87. LOGIN_DISABLED = ALLOW_ANON
  88. # None, firepad, and/or togetherjs
  89. COLLABORATION = 'togetherjs'
  90. # Required for firepad
  91. FIREBASE_HOSTNAME = None
  92. # Page names that can't be modified
  93. WIKI_LOCKED_PAGES = []
  94. # Depreciated variable name
  95. LOCKED = WIKI_LOCKED_PAGES
  96. ROOT_ENDPOINT = 'wiki.page'
  97. globals().update(read())
  98. if BASE_URL.endswith('/'):
  99. BASE_URL = BASE_URL[-1]
  100. SQLALCHEMY_DATABASE_URI = DB_URI
  101. _url = urlparse(BASE_URL)
  102. RELATIVE_PATH = _url.path
  103. if ENV != "DEV":
  104. DEBUG = False
  105. ASSETS_DEBUG = False
  106. SQLALCHEMY_ECHO = False
  107. MODULES = ['wiki', 'auth']