forked from grantwilk/d-noise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
urlutils.py
82 lines (63 loc) · 2.6 KB
/
urlutils.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""
Copyright (C) 2018 Grant Wilk
This file is part of D-NOISE: AI-Acclerated Denoiser.
D-NOISE: AI-Acclerated Denoiser is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
D-NOISE: AI-Acclerated Denoiser is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with D-NOISE: AI-Acclerated Denoiser. If not, see <https://www.gnu.org/licenses/>.
"""
from urllib import request
from urllib.request import urlopen
import os
import shutil
import threading
import zipfile
from . import fmutils
URL = "https://www.googleapis.com/drive/v3/files/1xTttPPtDWVeVQBZ5IvgphLMzfMqGwbiZ/?key=AIzaSyAeQC-x72dJTVWT6z_BqMescy4y26GG-aY&alt=media"
FILE_NAME = "DNOISE_OptiXBinaries.zip"
SCRIPT_DIR = os.path.dirname(__file__)
CHUNK_SIZE = 1024000 #bytes = 1MB
DOWNLOAD_PERCENT = 0
def downloadbin():
"""Downloads and extracts the OptiX binaries on a separate thread"""
global SCRIPT_DIR, CHUNK_SIZE, DOWNLOAD_PERCENT, FILE_NAME, URL
global FILE_SIZE
def download():
os.chdir(SCRIPT_DIR)
if os.path.isdir("OptiXDenoiser"):
shutil.rmtree("OptiXDenoiser")
chunkcount = 0
filesize = int(request.urlopen(URL).info().get('Content-Length'))
response = urlopen(URL)
with open(FILE_NAME, 'wb') as f:
while True:
chunk = response.read(CHUNK_SIZE)
if not chunk:
break
f.write(chunk)
chunkcount += 1
updateprogress(chunkcount, filesize)
with zipfile.ZipFile(FILE_NAME, 'r') as zip_ref:
zip_ref.extractall("")
os.remove(FILE_NAME)
fmutils.forceUIUpdate("USER_PREFERENCES")
t = threading.Thread(target=download)
t.start()
def updateprogress(chunkcount, filesize):
"""Calculates how far along the OptiX binaries download is and then forces the User Prefs areas to update"""
global CHUNK_SIZE, DOWNLOAD_PERCENT
downloadsize = chunkcount * CHUNK_SIZE
DOWNLOAD_PERCENT = (downloadsize / filesize) * 100
if DOWNLOAD_PERCENT > 100:
DOWNLOAD_PERCENT = 100
fmutils.forceUIUpdate("USER_PREFERENCES")
def getprogress():
"""Returns the percent downloaded"""
global DOWNLOAD_PERCENT
return DOWNLOAD_PERCENT