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 some applications such as `7z <http://www.7-zip.org/>`_. 

4""" 

5from __future__ import print_function 

6import sys 

7import re 

8import os 

9 

10from ..installhelper.install_cmd_helper import run_cmd 

11from .install_custom import download_page, download_file 

12 

13 

14def install_7z( 

15 temp_folder=".", fLOG=print, install=True, force_download=False, version=None): 

16 """ 

17 Install `7z <http://www.7-zip.org/>`_. 

18 It does not do it a second time if it is already installed. 

19 

20 @param temp_folder where to download the setup 

21 @param fLOG logging function 

22 @param install install (otherwise only download) 

23 @param force_download force the downloading of 7z 

24 @param version specify a version (unused) 

25 @return temporary file 

26 """ 

27 if version is not None: 

28 raise ValueError("cannot specify a version") 

29 link = "http://www.7-zip.org/download.html" 

30 page = download_page(link) 

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

32 reg = re.compile("href=\\\"(.*?x64[.]msi)\\\"") 

33 alls = reg.findall(page) 

34 if len(alls) == 0: 

35 raise Exception( 

36 "unable to find a link on a .msi file on page: " + link + "\n" + 

37 page) 

38 

39 url = "/".join(link.split("/")[:-1]) + "/" + alls[0] 

40 full = url.split("/")[-1] 

41 outfile = os.path.join(temp_folder, full) 

42 local = download_file(url, outfile, fLOG=fLOG) 

43 if install: 

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

45 return local 

46 else: 

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