Hide keyboard shortcuts

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 `Miktex <http://miktex.org/>`_. 

4""" 

5from __future__ import print_function 

6import sys 

7import os 

8import re 

9from ..installhelper.install_cmd_helper import run_cmd 

10from .install_custom import download_page, download_file 

11 

12 

13def install_miktex(dest_folder=".", fLOG=print, install=True, version=None): 

14 """ 

15 install `MikTex <http://miktex.org/>`_ (only on Windows) 

16 

17 @param dest_folder where to download the setup 

18 @param fLOG logging function 

19 @param install install (otherwise only download) 

20 @param version version to install (unused) 

21 @return temporary file 

22 

23 """ 

24 if version is not None: 

25 raise ValueError("cannot specify a version") 

26 if not sys.platform.startswith("win"): 

27 raise NotImplementedError( 

28 "MinGW can only be installed on Windows at the moment") 

29 

30 link = "http://miktex.org/download" 

31 page = download_page(link) 

32 if sys.platform.startswith("win"): 

33 reg = re.compile("href=\\\"(.*?basic.*?x64[.]exe)\\\"") 

34 alls = reg.findall(page) 

35 if len(alls) == 0: 

36 raise Exception( 

37 "unable to find a link on a .exe file on page: " + 

38 page) 

39 

40 url = alls[0] 

41 outfile = os.path.join(dest_folder, url.split("/")[-1]) 

42 if not os.path.exists(outfile): 

43 fLOG("[pymy] download ", url) 

44 local = download_file(url, outfile) 

45 else: 

46 return outfile 

47 if install: 

48 run_cmd("msiexec /i " + local, fLOG=fLOG, wait=True) 

49 return local 

50 else: 

51 raise NotImplementedError("not available on platform " + sys.platform)