Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Check whether it is already installed
pypandoc.get_pandoc_version()
except OSError:
# Pandoc not installed. Let's download it silently.
with open(os.devnull, 'w') as devnull:
sys.stdout = devnull
pypandoc.download_pandoc()
sys.stdout = sys.__stdout__
# Hack to delete the downloaded file from the folder,
# otherwise it could get accidently committed to the repo
# by other scripts in the repo.
pf = sys.platform
if pf.startswith('linux'):
pf = 'linux'
url = pypandoc.pandoc_download._get_pandoc_urls()[0][pf]
filename = url.split('/')[-1]
os.remove(filename)
# pandoc and pandoc-citeproc are in ./usr/bin subfolder
for exe in ["pandoc", "pandoc-citeproc"]:
src = os.path.join(tempfolder, "usr", "bin", exe)
dst = os.path.join(targetfolder, exe)
print("* Copying %s to %s ..." % (exe, targetfolder))
shutil.copyfile(src, dst)
pandoc_download._make_executable(dst)
src = os.path.join(tempfolder, "usr", "share", "doc", "pandoc", "copyright")
dst = os.path.join(targetfolder, "copyright.pandoc")
print("* Copying copyright to %s ..." % (targetfolder))
shutil.copyfile(src, dst)
finally:
os.chdir(cur_wd)
shutil.rmtree(tempfolder)
pandoc_urls, _ = retry(pandoc_download._get_pandoc_urls, version="latest")
pf = sys.platform
if pf.startswith("linux"):
pf = "linux"
if platform.architecture()[0] != "64bit":
raise RuntimeError("Linux pandoc is only compiled for 64bit.")
if pf not in pandoc_urls:
raise RuntimeError("Can't handle your platform (only Linux, Mac OS X, Windows).")
filename = pandoc_urls[pf].split("/")[-1]
os.environ["PATH"] = "%s:%s" % (path, os.environ["PATH"])
# Seems like it always downloads to the current working directory, and then unpack to
# the given path. Let's download to the given path as well.
prev = os.getcwd()
os.chdir(path)