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
10from ..installhelper.install_cmd_helper import run_cmd, unzip_files
11from .install_custom import download_page, download_file
14def install_graphviz(temp_folder=".", fLOG=print, install=True,
15 force_download=False, version=None, source=None):
16 """
17 Install `Graphviz <http://www.graphviz.org/>`_.
18 It does not do it a second time if it is already installed.
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 Graphviz
24 @param version specify a version (unused)
25 @param source change the source
26 @return temporary file
27 """
28 if version is not None:
29 raise ValueError("cannot specify a version")
30 if sys.platform.startswith("win"):
31 if source == "2":
32 url = "http://www.xavierdupre.fr/enseignement/setup/"
33 full = "graphviz-2.38.msi"
34 url += full
35 outfile = os.path.join(temp_folder, full)
36 if not os.path.exists(temp_folder):
37 os.makedirs(temp_folder)
38 elif source == "zip":
39 url = "http://www.xavierdupre.fr/enseignement/setup/"
40 full = "Graphviz.zip"
41 url += full
42 outfile = os.path.join(temp_folder, full)
43 if not os.path.exists(temp_folder):
44 os.makedirs(temp_folder)
45 else:
46 link = "http://www.graphviz.org/Download_windows.php"
47 repl = "http://www.graphviz.org"
48 page = download_page(link)
49 reg = re.compile("href=\\\"(.*?[.]msi)\\\"")
50 alls = reg.findall(page)
51 if len(alls) == 0:
52 raise Exception(
53 "unable to find a link on a .msi file on page: " +
54 page)
56 url = repl + alls[0]
57 full = url.split("/")[-1]
58 outfile = os.path.join(temp_folder, full)
60 fLOG("[pymy] download ", url)
61 local = download_file(url, outfile)
62 if install:
63 if source == "zip":
64 fLOG("[pymy] dest ", os.path.abspath(temp_folder))
65 unzip_files(local, temp_folder, fLOG=fLOG)
66 else:
67 run_cmd("msiexec /i " + local, fLOG=fLOG, wait=True)
68 return local
69 else:
70 raise NotImplementedError("not available on platform " + sys.platform)