@@ -147,52 +147,20 @@ def verify_files(filename, destination, rename_to):
147
147
148
148
return True
149
149
150
- def is_latest_version (filename , destination , dirname , rename_to , cfile ):
151
- # Regex to extract version number from any of the sources below
152
- regex = r'(?<![{,])(?:[ _\-vV])(\d+\.\d+(?:\.\d+)?)'
150
+ def is_latest_version (filename , destination , dirname , rename_to , cfile , checksum ):
153
151
current_version = None
154
- try :
155
- expected_version = re .search (regex , filename ).group (1 )
156
- except Exception as e :
157
- expected_version = None
152
+ expected_version = None
158
153
159
154
try :
160
155
if rename_to .startswith ("esp32-arduino-libs" ):
161
- # overwrite expected_version with the one from versions.txt
162
- if filename .endswith ("tar.gz" ) or filename .endswith ("tar.xz" ):
163
- expected_version = cfile .extractfile (dirname + "/versions.txt" ).read ().decode ("utf-8" )
164
- else :
165
- expected_version = cfile .read (dirname + "/versions.txt" ).decode ("utf-8" )
156
+ expected_version = cfile .read (dirname + "/versions.txt" ).decode ("utf-8" )
166
157
with open (os .path .join (destination , rename_to , "versions.txt" ), "r" ) as f :
167
158
# cfile is zip
168
159
current_version = f .read ()
169
- elif rename_to .startswith ("mklittlefs" ):
170
- # overwrite expected_version with the one from package.json
171
- if filename .endswith ("tar.gz" ) or filename .endswith ("tar.xz" ):
172
- expected_version = cfile .extractfile (dirname + "/package.json" ).read ().decode ("utf-8" )
173
- else :
174
- expected_version = cfile .read (dirname + "/package.json" ).decode ("utf-8" )
175
- with open (os .path .join (destination , rename_to , "package.json" ), "r" ) as f :
176
- # cfile is tar.gz
177
- current_version = f .read ()
178
- elif rename_to .startswith ("esptool" ):
179
- bin_path = os .path .join (destination , rename_to , "esptool" )
180
- result = subprocess .run ([bin_path , "--help" ], text = True , check = True , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
181
- current_version = re .search (regex , result .stdout ).group (1 )
182
160
else :
183
- if rename_to .startswith ("xtensa-esp-elf-gdb" ):
184
- bin_path = os .path .join (destination , rename_to , "bin" , "xtensa-esp32-elf-gdb" )
185
- elif rename_to .startswith ("riscv32-esp-elf-gdb" ):
186
- bin_path = os .path .join (destination , rename_to , "bin" , "riscv32-esp-elf-gdb" )
187
- elif rename_to .startswith ("openocd" ):
188
- bin_path = os .path .join (destination , rename_to , "bin" , "openocd" )
189
- elif rename_to .startswith ("mkspiffs" ):
190
- bin_path = os .path .join (destination , rename_to , "mkspiffs" )
191
- else :
192
- bin_path = os .path .join (destination , rename_to , "bin" , rename_to + "-gcc" )
193
-
194
- result = subprocess .run ([bin_path , "--version" ], text = True , check = True , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
195
- current_version = re .search (regex , result .stdout ).group (1 )
161
+ expected_version = checksum
162
+ with open (os .path .join (destination , rename_to , ".package_checksum" ), "r" ) as f :
163
+ current_version = f .read ()
196
164
197
165
if verbose :
198
166
print (f"\n Tool: { rename_to } " )
@@ -213,7 +181,7 @@ def is_latest_version(filename, destination, dirname, rename_to, cfile):
213
181
214
182
return False
215
183
216
- def unpack (filename , destination , force_extract ): # noqa: C901
184
+ def unpack (filename , destination , force_extract , checksum ): # noqa: C901
217
185
dirname = ""
218
186
cfile = None # Compressed file
219
187
file_is_corrupted = False
@@ -262,7 +230,7 @@ def unpack(filename, destination, force_extract): # noqa: C901
262
230
rename_to = "esp32-arduino-libs"
263
231
264
232
if not force_extract :
265
- if is_latest_version (filename , destination , dirname , rename_to , cfile ):
233
+ if is_latest_version (filename , destination , dirname , rename_to , cfile , checksum ):
266
234
if verify_files (filename , destination , rename_to ):
267
235
print (" Files ok. Skipping Extraction" )
268
236
return True
@@ -291,6 +259,9 @@ def unpack(filename, destination, force_extract): # noqa: C901
291
259
shutil .rmtree (rename_to )
292
260
shutil .move (dirname , rename_to )
293
261
262
+ with open (os .path .join (destination , rename_to , ".package_checksum" ), "w" ) as f :
263
+ f .write (checksum )
264
+
294
265
if verify_files (filename , destination , rename_to ):
295
266
print (" Files extracted successfully." )
296
267
return True
@@ -394,7 +365,7 @@ def get_tool(tool, force_download, force_extract):
394
365
print ("Checksum mismatch for {0}" .format (archive_name ))
395
366
return False
396
367
397
- return unpack (local_path , "." , force_extract )
368
+ return unpack (local_path , "." , force_extract , checksum )
398
369
399
370
400
371
def load_tools_list (filename , platform ):
0 commit comments