for name in decode_names:
attr = getattr(self, name, None)
if attr:
# Try to decode strings
if isinstance(attr, str):
try:
setattr(self, name, unicode(attr, charset))
except UnicodeError:
raise error.ConfigurationError(message %
{'name': name})
# Look into lists and try to decode strings inside them
elif isinstance(attr, list):
for i in xrange(len(attr)):
item = attr[i]
if isinstance(item, str):
try:
attr[i] = unicode(item, charset)
except UnicodeError:
raise error.ConfigurationError(message %
{'name': name})
def _check_directories(self):
""" Make sure directories are accessible
Both data and underlay should exists and allow read, write and
execute.
"""
mode = os.F_OK | os.R_OK | os.W_OK | os.X_OK
for attr in ('data_dir', 'data_underlay_dir'):
path = getattr(self, attr)
# allow an empty underlay path or None
if attr == 'data_underlay_dir' and not path:
continue
path_pages = os.path.join(path, "pages")
if not (os.path.isdir(path_pages) and os.access(path_pages, mode)):
msg = """
%(attr)s "%(path)s" does not exist, or has incorrect ownership or
permissions.
Make sure the directory and the subdirectory "pages" are owned by the web
server and are readable, writable and executable by the web server user
and group.
It is recommended to use absolute paths and not relative paths. Check
also the spelling of the directory name.
""" % {'attr': attr, 'path': path, }
raise error.ConfigurationError(msg)
def _loadPluginModule(self):
"""
import all plugin modules
To be able to import plugin from arbitrary path, we have to load
the base package once using imp.load_module. Later, we can use
standard __import__ call to load plugins in this package.
Since each configured plugin path has unique plugins, we load the
plugin packages as "moin_plugin_<sha1(path)>.plugin".
"""
import imp
from MoinMoin.support.python_compatibility import hash_new
plugin_dirs = [self.plugin_dir] + self.plugin_dirs
self._plugin_modules = []
try:
# Lock other threads while we check and import
imp.acquire_lock()
try:
for pdir in plugin_dirs:
csum = 'p_%s' % hash_new('sha1', pdir).hexdigest()
modname = '%s.%s' % (self.siteid, csum)
# If the module is not loaded, try to load it
if not modname in sys.modules:
# Find module on disk and try to load - slow!
abspath = os.path.abspath(pdir)
parent_dir, pname = os.path.split(abspath)
fp, path, info = imp.find_module(pname, [parent_dir])
try:
# Load the module and set in sys.modules
module = imp.load_module(modname, fp, path, info)
setattr(sys.modules[self.siteid], 'csum', module)
finally:
# Make sure fp is closed properly
if fp:
fp.close()
if modname not in self._plugin_modules:
self._plugin_modules.append(modname)
finally:
imp.release_lock()
except ImportError, err:
msg = """
Could not import plugin package "%(path)s" because of ImportError:
%(err)s.
attr = getattr(self, name, None)
if attr:
# Try to decode strings
if isinstance(attr, str):
try:
setattr(self, name, unicode(attr, charset))
except UnicodeError:
raise error.ConfigurationError(message %
{'name': name})
# Look into lists and try to decode strings inside them
elif isinstance(attr, list):
for i in xrange(len(attr)):
item = attr[i]
if isinstance(item, str):
try:
attr[i] = unicode(item, charset)
except UnicodeError:
raise error.ConfigurationError(message %
{'name': name})
def _check_directories(self):
""" Make sure directories are accessible
Both data and underlay should exists and allow read, write and
execute.
"""
mode = os.F_OK | os.R_OK | os.W_OK | os.X_OK
for attr in ('data_dir', 'data_underlay_dir'):
path = getattr(self, attr)
# allow an empty underlay path or None
if attr == 'data_underlay_dir' and not path:
continue
path_pages = os.path.join(path, "pages")
if not (os.path.isdir(path_pages) and os.access(path_pages, mode)):
msg = """
%(attr)s "%(path)s" does not exist, or has incorrect ownership or
permissions.
Make sure the directory and the subdirectory "pages" are owned by the web
server and are readable, writable and executable by the web server user
and group.
It is recommended to use absolute paths and not relative paths. Check
also the spelling of the directory name.
""" % {'attr': attr, 'path': path, }
raise error.ConfigurationError(msg)
def _loadPluginModule(self):
"""
import all plugin modules
To be able to import plugin from arbitrary path, we have to load
the base package once using imp.load_module. Later, we can use
standard __import__ call to load plugins in this package.
Since each configured plugin path has unique plugins, we load the
plugin packages as "moin_plugin_<sha1(path)>.plugin".
"""
import imp
from MoinMoin.support.python_compatibility import hash_new
plugin_dirs = [self.plugin_dir] + self.plugin_dirs
self._plugin_modules = []
try:
# Lock other threads while we check and import
imp.acquire_lock()
try:
for pdir in plugin_dirs:
csum = 'p_%s' % hash_new('sha1', pdir).hexdigest()
modname = '%s.%s' % (self.siteid, csum)
# If the module is not loaded, try to load it
if not modname in sys.modules:
# Find module on disk and try to load - slow!
abspath = os.path.abspath(pdir)
parent_dir, pname = os.path.split(abspath)
fp, path, info = imp.find_module(pname, [parent_dir])
try:
# Load the module and set in sys.modules
module = imp.load_module(modname, fp, path, info)
setattr(sys.modules[self.siteid], 'csum', module)
finally:
# Make sure fp is closed properly
if fp:
fp.close()
if modname not in self._plugin_modules:
self._plugin_modules.append(modname)
finally:
imp.release_lock()
except ImportError, err:
msg = """
Could not import plugin package "%(path)s" because of ImportError:
%(err)s.