# -*- coding: iso-8859-1 -*-
"""
MoinMoin - Multiple configuration handler and Configuration defaults class
@copyright: 2000-2004 Juergen Hermann <
[email protected]>,
2005-2008 MoinMoin:ThomasWaldmann.
2008 MoinMoin:JohannesBerg
@license: GNU GPL, see COPYING for details.
"""
import re
import os
import sys
import time
from MoinMoin import log
logging = log.getLogger(__name__)
from MoinMoin import config, error, util, wikiutil
from MoinMoin.auth import MoinAuth
import MoinMoin.events as events
from MoinMoin.events import PageChangedEvent, PageRenamedEvent
from MoinMoin.events import PageDeletedEvent, PageCopiedEvent
from MoinMoin.events import PageRevertedEvent, FileAttachedEvent
from MoinMoin import session
from MoinMoin.packages import packLine
from MoinMoin.security import AccessControlList
from MoinMoin.support.python_compatibility import set
_url_re_cache = None
_farmconfig_mtime = None
_config_cache = {}
def _importConfigModule(name):
""" Import and return configuration module and its modification time
Handle all errors except ImportError, because missing file is not
always an error.
@param name: module name
@rtype: tuple
@return: module, modification time
"""
try:
module = __import__(name, globals(), {})
mtime = os.path.getmtime(module.__file__)
except ImportError:
raise
except IndentationError, err:
logging.exception('Your source code / config file is not correctly indented!')
msg = """IndentationError: %(err)s
The configuration files are Python modules. Therefore, whitespace is
important. Make sure that you use only spaces, no tabs are allowed here!
You have to use four spaces at the beginning of the line mostly.
""" % {
'err': err,
}
raise error.ConfigurationError(msg)
except Exception, err:
logging.exception('An exception happened.')
msg = '%s: %s' % (err.__class__.__name__, str(err))
raise error.ConfigurationError(msg)
return module, mtime
def _url_re_list():
""" Return url matching regular expression
Import wikis list from farmconfig on the first call and compile the
regexes. Later just return the cached regex list.
@rtype: list of tuples of (name, compiled re object)
@return: url to wiki config name matching list
"""
global _url_re_cache, _farmconfig_mtime
if _url_re_cache is None:
try:
farmconfig, _farmconfig_mtime = _importConfigModule('farmconfig')
except ImportError, err:
if 'farmconfig' in str(err):
# we failed importing farmconfig
logging.debug("could not import farmconfig, mapping all URLs to wikiconfig")
_farmconfig_mtime = 0
_url_re_cache = [('wikiconfig', re.compile(r'.')), ] # matches everything
else:
# maybe there was a failing import statement inside farmconfig
raise
else:
logging.info("using farm config: %s" % os.path.abspath(farmconfig.__file__))
try:
cache = []
for name, regex in farmconfig.wikis:
cache.append((name, re.compile(regex)))
_url_re_cache = cache
except AttributeError:
logging.error("required 'wikis' list missing in farmconfig")
msg = """
Missing required 'wikis' list in 'farmconfig.py'.
If you run a single wiki you do not need farmconfig.py. Delete it and
use wikiconfig.py.
"""
raise error.ConfigurationError(msg)
return _url_re_cache