This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
/
install_custom_git.py
48 lines (43 loc) · 1.69 KB
/
install_custom_git.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
@file
@brief Various functions to install some applications such as `Git <http://www.git-scm.com/>`_.
"""
from __future__ import print_function
import sys
import re
import os
from ..installhelper.install_cmd_helper import run_cmd
from .install_custom import download_page, download_file
def install_git(
temp_folder=".", fLOG=print, install=True, force_download=False, version=None):
"""
Install `Git <http://www.git-scm.com/>`_.
It does not do it a second time if it is already installed.
@param temp_folder where to download the setup
@param fLOG logging function
@param install install (otherwise only download)
@param force_download force the downloading of Git
@param version specify a version (unused)
@return temporary file
"""
if version is not None:
raise ValueError("cannot specify a version")
if sys.platform.startswith("win"):
link = "http://www.git-scm.com/download/win"
page = download_page(link)
reg = re.compile("href=\\\"(.*?64-bit[.]((msi)|(exe)))\\\"")
alls = reg.findall(page)
if len(alls) == 0:
raise AssertionError(
"unable to find a link on a .msi file on page: " + link + "\n" +
page)
url = alls[0][0]
full = url.split("/")[-1]
outfile = os.path.join(temp_folder, full)
fLOG("[pymy] download ", url)
local = download_file(url, outfile)
if install:
run_cmd("msiexec /i " + local, fLOG=fLOG, wait=True)
return local
else:
raise NotImplementedError("not available on platform " + sys.platform)