-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.py
65 lines (54 loc) · 1.96 KB
/
install.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import requests
import zipfile
import io
import os
import sys
import platform
from tqdm import tqdm
import requests
import math
import tarfile
def install():
versionUrl = "https://github.com/mozilla/geckodriver/releases/latest"
fname = ""
url = ""
filePath = ""
vr = requests.get(versionUrl)
print(vr.url)
versionUrlArray = str(vr.url).split("/")
version = versionUrlArray[len(versionUrlArray) - 1]
system = sys.platform.replace("32", "") + platform.architecture()[0].replace("bit", "")
print("Arch: ", platform.architecture()[0])
print("System: ", system)
fileType = sys.platform.replace("win32", "zip").replace("linux", "tar.gz")
fname = "geckodriver-" + version + "-" + system + "." + fileType
url = "https://github.com/mozilla/geckodriver/releases/download/" + version + "/" + fname
filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)),fname)
print("File path: ", filePath)
print("Downloading ", url)
if not os.path.isfile(filePath):
# Streaming, so we can iterate over the response.
r = requests.get(url, stream=True)
# Total size in bytes.
total_size = int(r.headers.get('content-length', 0));
block_size = 1024
wrote = 0
with open(fname, 'wb') as f:
for data in tqdm(r.iter_content(block_size), total=math.ceil(total_size//block_size) , unit='KB', unit_scale=True):
wrote = wrote + len(data)
f.write(data)
if total_size != 0 and wrote != total_size:
print("ERROR, something went wrong")
print("Extracting File")
if (fname.endswith("tar.gz")):
tar = tarfile.open(fname, "r:gz")
tar.extractall()
tar.close()
elif (fname.endswith("tar")):
tar = tarfile.open(fname, "r:")
tar.extractall()
tar.close()
elif (fname.endswith("zip")):
tar = zipfile.ZipFile(fname, "r")
tar.extractall()
tar.close()