@@ -147,7 +147,36 @@ def verify_files(filename, destination, rename_to):
147
147
return True
148
148
149
149
150
- def unpack (filename , destination , force_extract ): # noqa: C901
150
+ def is_latest_version (destination , dirname , rename_to , cfile , checksum ):
151
+ current_version = None
152
+ expected_version = None
153
+
154
+ try :
155
+ expected_version = checksum
156
+ with open (os .path .join (destination , rename_to , ".package_checksum" ), "r" ) as f :
157
+ current_version = f .read ()
158
+
159
+ if verbose :
160
+ print (f"\n Tool: { rename_to } " )
161
+ print (f"Current version: { current_version } " )
162
+ print (f"Expected version: { expected_version } " )
163
+
164
+ if current_version and current_version == expected_version :
165
+ if verbose :
166
+ print ("Latest version already installed. Skipping extraction" )
167
+ return True
168
+
169
+ if verbose :
170
+ print ("New version detected" )
171
+
172
+ except Exception as e :
173
+ if verbose :
174
+ print (f"Falied to verify version for { rename_to } : { e } " )
175
+
176
+ return False
177
+
178
+
179
+ def unpack (filename , destination , force_extract , checksum ): # noqa: C901
151
180
dirname = ""
152
181
cfile = None # Compressed file
153
182
file_is_corrupted = False
@@ -196,11 +225,11 @@ def unpack(filename, destination, force_extract): # noqa: C901
196
225
rename_to = "esp32-arduino-libs"
197
226
198
227
if not force_extract :
199
- if verify_files ( filename , destination , rename_to ):
200
- print ( " Files ok. Skipping Extraction" )
201
- return True
202
- else :
203
- print (" Extracting archive..." )
228
+ if is_latest_version ( destination , dirname , rename_to , cfile , checksum ):
229
+ if verify_files ( filename , destination , rename_to ):
230
+ print ( " Files ok. Skipping Extraction" )
231
+ return True
232
+ print (" Extracting archive..." )
204
233
else :
205
234
print (" Forcing extraction" )
206
235
@@ -225,6 +254,9 @@ def unpack(filename, destination, force_extract): # noqa: C901
225
254
shutil .rmtree (rename_to )
226
255
shutil .move (dirname , rename_to )
227
256
257
+ with open (os .path .join (destination , rename_to , ".package_checksum" ), "w" ) as f :
258
+ f .write (checksum )
259
+
228
260
if verify_files (filename , destination , rename_to ):
229
261
print (" Files extracted successfully." )
230
262
return True
@@ -324,11 +356,11 @@ def get_tool(tool, force_download, force_extract):
324
356
print ("Tool {0} already downloaded" .format (archive_name ))
325
357
sys .stdout .flush ()
326
358
327
- if "esp32-arduino-libs" not in archive_name and sha256sum (local_path ) != checksum :
359
+ if sha256sum (local_path ) != checksum :
328
360
print ("Checksum mismatch for {0}" .format (archive_name ))
329
361
return False
330
362
331
- return unpack (local_path , "." , force_extract )
363
+ return unpack (local_path , "." , force_extract , checksum )
332
364
333
365
334
366
def load_tools_list (filename , platform ):
@@ -379,21 +411,17 @@ def identify_platform():
379
411
if __name__ == "__main__" :
380
412
parser = argparse .ArgumentParser (description = "Download and extract tools" )
381
413
382
- parser .add_argument ("-v" , "--verbose" , type = bool , default = False , required = False , help = "Print verbose output" )
414
+ parser .add_argument ("-v" , "--verbose" , action = "store_true" , required = False , help = "Print verbose output" )
383
415
384
- parser .add_argument (
385
- "-d" , "--force_download" , type = bool , default = False , required = False , help = "Force download of tools"
386
- )
416
+ parser .add_argument ("-d" , "--force_download" , action = "store_true" , required = False , help = "Force download of tools" )
387
417
388
- parser .add_argument (
389
- "-e" , "--force_extract" , type = bool , default = False , required = False , help = "Force extraction of tools"
390
- )
418
+ parser .add_argument ("-e" , "--force_extract" , action = "store_true" , required = False , help = "Force extraction of tools" )
391
419
392
420
parser .add_argument (
393
- "-f" , "--force_all" , type = bool , default = False , required = False , help = "Force download and extraction of tools"
421
+ "-f" , "--force_all" , action = "store_true" , required = False , help = "Force download and extraction of tools"
394
422
)
395
423
396
- parser .add_argument ("-t" , "--test" , type = bool , default = False , required = False , help = argparse .SUPPRESS )
424
+ parser .add_argument ("-t" , "--test" , action = "store_true" , required = False , help = argparse .SUPPRESS )
397
425
398
426
args = parser .parse_args ()
399
427
0 commit comments