Mercurial > wikked
changeset 118:7c8543878b47
Auto-detect the wiki root, and support custom Flask config files.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 19 Nov 2013 23:06:27 -0800 |
parents | b07cdd68de70 |
children | 013c531733cc |
files | wikked/utils.py wikked/web.py |
diffstat | 2 files changed, 21 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/wikked/utils.py Tue Nov 19 13:14:05 2013 -0800 +++ b/wikked/utils.py Tue Nov 19 23:06:27 2013 -0800 @@ -1,9 +1,25 @@ import re +import os import os.path import unicodedata from xml.sax.saxutils import escape, unescape +def find_wiki_root(path=None): + if not path: + path = os.getcwd() + while True: + if os.path.isfile(os.path.join(path, '.wikirc')): + return path + if (os.path.isdir(os.path.join(path, '.git')) or + os.path.isdir(os.path.join(path, '.hg'))): + return path + path = os.path.dirname(path) + if not path or path == '/': + break + return None + + def get_absolute_url(base_url, url, do_slugify=True): if base_url[0] != '/': raise ValueError("The base URL must be absolute. Got: %s" % base_url)
--- a/wikked/web.py Tue Nov 19 13:14:05 2013 -0800 +++ b/wikked/web.py Tue Nov 19 23:06:27 2013 -0800 @@ -1,6 +1,7 @@ import os import os.path from flask import Flask, abort, g +from utils import find_wiki_root # Create the main app. app = Flask("wikked") @@ -9,9 +10,10 @@ # Find the wiki root. -wiki_root = app.config.get('WIKI_ROOT') -if not wiki_root: - wiki_root = os.getcwd() +wiki_root = find_wiki_root() +config_path = os.path.join(wiki_root, '.wiki', 'app.cfg') +if os.path.isfile(config_path): + app.config.from_pyfile(config_path) # Make the app serve static content and wiki assets in DEBUG mode.