wiki配置管理

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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值