# HG changeset patch # User Ludovic Chabant # Date 1384931187 28800 # Node ID 7c8543878b4767be8813f04013d650847cfd61ef # Parent b07cdd68de70e82cd8476fb733c7a75d0e59c0e9 Auto-detect the wiki root, and support custom Flask config files. diff -r b07cdd68de70 -r 7c8543878b47 wikked/utils.py --- 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) diff -r b07cdd68de70 -r 7c8543878b47 wikked/web.py --- 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.