2 from zipfile
import ZipFile
3 from tarfile
import TarFile
4 from urllib
import request
10 def print_progress(current
, maxprogress
):
11 status
= "%10d [%3.2f%%]" % (current
, current
* 100. / maxprogress
)
12 print(status
, end
='\r')
15 def read_chunks(url
, block_sz
=8192 * 8):
16 with request
.urlopen(url
) as openurl
:
18 data
= openurl
.read(block_sz
)
25 BASE_URL
= 'https://github.com/CRYTEK/CRYENGINE/releases/download/5.5.0/CRYENGINE_v5.5.0_SDKs'
29 # use ZIP on windows and tar on other platforms
30 if platform
.system() == 'Windows':
31 url
= BASE_URL
+ '.zip'
33 list_archive
= ZipFile
.namelist
35 url
= BASE_URL
+ '.tar.gz'
36 ArchiveFile
= TarFile
.open
37 list_archive
= TarFile
.getnames
40 file_name
= url
.split('/')[-1]
41 temp_file
= os
.path
.join(temp_folder
, file_name
)
43 u
= request
.urlopen(url
)
45 file_size
= int(u
.getheader("Content-Length"))
47 print("Downloading: %s Bytes: %s" % (file_name
, file_size
))
49 with
open(temp_file
, 'wb') as tfile
:
51 for chunk
in read_chunks(url
):
52 downloaded_bytes
+= len(chunk
)
55 print_progress(downloaded_bytes
, file_size
)
59 with
ArchiveFile(temp_file
) as zf
:
60 nameList
= list_archive(zf
)
61 num_files
= len(nameList
)
62 output_path
= 'Code/SDKs'
64 print('Extracting %d files to:"%s"' % (num_files
, output_path
))
66 for counter
, item
in enumerate(nameList
, start
=1):
67 zf
.extract(item
, output_path
)
68 print_progress(counter
, num_files
)
73 if __name__
== '__main__':