Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2@file
3@brief Various functions to install some application such as `pandoc <http://johnmacfarlane.net/pandoc/>`_.
4"""
5from __future__ import print_function
6import sys
7import re
8import os
10from ..installhelper.install_cmd_helper import run_cmd
11from .install_custom import download_page, download_file
14def IsPandocInstalled():
15 """
16 @return True of False whether or not it was installed
17 """
18 if sys.platform.startswith("win"):
19 path = "{0}\\AppData\\Local\\Pandoc\\pandoc.exe".format(
20 os.environ["USERPROFILE"])
21 return os.path.exists(path)
22 else:
23 raise NotImplementedError("not available on platform " + sys.platform)
26def install_pandoc(
27 temp_folder=".", fLOG=print, install=True, force_download=False, version=None):
28 """
29 Install `pandoc <http://johnmacfarlane.net/pandoc/>`_.
30 It does not do it a second time if it is already installed.
32 @param temp_folder where to download the setup
33 @param fLOG logging function
34 @param install install (otherwise only download)
35 @param force_download force the downloading of pandoc
36 @param version version to install (unused)
37 @return temporary file
38 """
39 if version is not None:
40 raise ValueError("cannot specify a version")
41 bb = IsPandocInstalled()
42 if bb and not force_download:
43 return True
45 link = "https://github.com/jgm/pandoc/releases"
46 page = download_page(link)
47 if sys.platform.startswith("win"):
48 reg = re.compile("href=\\\"(.*?[.]msi)\\\"")
49 alls = reg.findall(page)
50 if len(alls) == 0:
51 raise Exception(
52 "unable to find a link on a .msi file on page: " +
53 page)
55 file = alls[0].split("/")[-1]
56 filel = "https://github.com/jgm/pandoc/releases/download/{0}/pandoc-{0}-windows-x86_64.msi"
57 version = file.replace("pandoc-", "").replace("-windows.msi", "")
58 vershort = version.split("-")[0]
59 fLOG("[pymy] pandoc, version ", vershort)
60 full = filel.format(vershort)
61 outfile = os.path.join(temp_folder, full.split("/")[-1])
62 fLOG("[pymy] download ", full)
63 local = download_file(full, outfile)
64 if install and not bb:
65 run_cmd("msiexec /i " + local, fLOG=fLOG, wait=True)
66 return local
67 else:
68 raise NotImplementedError("not available on platform " + sys.platform)