def _process_value(self, config_section, config_key, value_type):
"""
Process the value
:param config_section: The section in the config
:param config_key: The key in the config
:param value_type: The type of the value
:return: The processed value
"""
if config_section not in self.config:
return None
if config_key not in self.config[config_section]:
return None
value = self.config[config_section][config_key]
if value_type == bool:
value = value.strip().lower() == 'true'
elif value_type == str:
if value.startswith('file://'):
value_path = os.path.join(self.base_path, value[len('file://'):])
with open(value_path, 'r') as value_file:
value = value_file.read()
if value_path.lower().endswith('.md'):
try:
import pypandoc
value = pypandoc.convert_text(value, 'rst', format='md')
value = value.replace("\r", "")
except ImportError:
print("Pandoc not found. Markdown to reStructuredText conversion failed.")
elif value_type == list:
if value.startswith('file://'):
value_path = os.path.join(self.base_path, value[len('file://'):])
with open(value_path, 'r') as value_file:
value = value_file.readlines()
value = filter(lambda k: bool(k), value)
value = list(map(lambda k: k.strip().replace('\n', ''), value))
else:
value = value.split(',')
return value
评论列表
文章目录