def _get_pandoc_version(pandoc_path):
new_env = os.environ.copy()
if 'HOME' not in os.environ:
new_env['HOME'] = tempfile.gettempdir()
p = subprocess.Popen(
[pandoc_path, '--version'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
env=new_env)
comm = p.communicate()
out_lines = comm[0].decode().splitlines(False)
if p.returncode != 0 or len(out_lines) == 0:
raise RuntimeError("Couldn't call pandoc to get version information. Output from "
"pandoc:\n%s" % str(comm))
version_pattern = re.compile(r"^\d+(\.\d+){1,}$")
for tok in out_lines[0].split():
if version_pattern.match(tok):
version = tok
break
return version
评论列表
文章目录