1515import tarfile
1616import zipfile
1717import re
18- import requests
1918if sys .version_info [0 ] == 3 :
2019 from urllib .request import urlretrieve
2120else :
2221 # Not Python 3 - today, it is most likely to be Python 2
2322 from urllib import urlretrieve
2423
25- dist_dir = 'dist/'
24+ if 'Windows' in platform .system ():
25+ import requests
26+
27+ current_dir = os .path .dirname (os .path .realpath (__file__ ))
28+ dist_dir = current_dir + '/dist/'
2629
2730def sha256sum (filename , blocksize = 65536 ):
2831 hash = hashlib .sha256 ()
@@ -46,7 +49,8 @@ def report_progress(count, blockSize, totalSize):
4649
4750def unpack (filename , destination ):
4851 dirname = ''
49- print ('Extracting {0}' .format (filename ))
52+ print ('Extracting {0}' .format (os .path .basename (filename )))
53+ sys .stdout .flush ()
5054 if filename .endswith ('tar.gz' ):
5155 tfile = tarfile .open (filename , 'r:gz' )
5256 tfile .extractall (destination )
@@ -72,26 +76,26 @@ def get_tool(tool):
7276 local_path = dist_dir + archive_name
7377 url = tool ['url' ]
7478 #real_hash = tool['checksum'].split(':')[1]
75- if 'CYGWIN_NT' in sys_name :
76- ctx = ssl .create_default_context ()
77- ctx .check_hostname = False
78- ctx .verify_mode = ssl .CERT_NONE
7979 if not os .path .isfile (local_path ):
8080 print ('Downloading ' + archive_name );
81+ sys .stdout .flush ()
8182 if 'CYGWIN_NT' in sys_name :
82- urlretrieve (url , local_path , report_progress ,context = ctx )
83+ ctx = ssl .create_default_context ()
84+ ctx .check_hostname = False
85+ ctx .verify_mode = ssl .CERT_NONE
86+ urlretrieve (url , local_path , report_progress , context = ctx )
87+ elif 'Windows' in sys_name :
88+ r = requests .get (url )
89+ f = open (local_path , 'wb' )
90+ f .write (r .content )
91+ f .close ()
8392 else :
84- try :
85- urlretrieve (url , local_path , report_progress )
86- except Exception ,e :
87- r = requests .get (url )
88- f = open (local_path , 'wb' )
89- f .write (r .content )
90- f .close ()
93+ urlretrieve (url , local_path , report_progress )
9194 sys .stdout .write ("\r Done\n " )
9295 sys .stdout .flush ()
9396 else :
9497 print ('Tool {0} already downloaded' .format (archive_name ))
98+ sys .stdout .flush ()
9599 #local_hash = sha256sum(local_path)
96100 #if local_hash != real_hash:
97101 # print('Hash mismatch for {0}, delete the file and try again'.format(local_path))
@@ -117,15 +121,19 @@ def identify_platform():
117121 if sys .maxsize > 2 ** 32 :
118122 bits = 64
119123 sys_name = platform .system ()
120- if 'Linux' in sys_name and platform .platform ().find ('arm' ) > 0 :
124+ sys_platform = platform .platform ()
125+ print ('System: %s, Info: %s' % (sys_name , sys_platform ))
126+ if 'Linux' in sys_name and sys_platform .find ('arm' ) > 0 :
121127 sys_name = 'LinuxARM'
122128 if 'CYGWIN_NT' in sys_name :
123129 sys_name = 'Windows'
124130 return arduino_platform_names [sys_name ][bits ]
125131
126132if __name__ == '__main__' :
127- print ('Platform: {0}' .format (identify_platform ()))
128- tools_to_download = load_tools_list ('../package/package_esp32_index.template.json' , identify_platform ())
133+ identified_platform = identify_platform ()
134+ print ('Platform: {0}' .format (identified_platform ))
135+ tools_to_download = load_tools_list (current_dir + '/../package/package_esp32_index.template.json' , identified_platform )
129136 mkdir_p (dist_dir )
130137 for tool in tools_to_download :
131138 get_tool (tool )
139+ print ('Done' )
0 commit comments