@@ -101,52 +101,46 @@ def verify_files(filename, destination, rename_to):
101
101
t1 = time .time ()
102
102
if filename .endswith (".zip" ):
103
103
try :
104
- with zipfile .ZipFile (filename , "r" ) as archive :
105
- first_dir = archive .namelist ()[0 ].split ("/" )[0 ]
106
- total_files = len (archive .namelist ())
107
- for i , zipped_file in enumerate (archive .namelist (), 1 ):
108
- local_path = os .path .join (extracted_dir_path , zipped_file .replace (first_dir , rename_to , 1 ))
109
- if not os .path .exists (local_path ):
110
- print (f"\n Missing { zipped_file } on location: { extracted_dir_path } " )
111
- print (f"Verification failed; aborted in { format_time (time .time () - t1 )} " )
112
- return False
113
- print_verification_progress (total_files , i , t1 )
104
+ archive = zipfile .ZipFile (filename , "r" )
105
+ file_list = archive .namelist ()
114
106
except zipfile .BadZipFile :
115
- print (f"Verification failed; aborted in { format_time (time .time () - t1 )} " )
107
+ if verbose :
108
+ print (f"Verification failed; aborted in { format_time (time .time () - t1 )} " )
116
109
return False
117
110
elif filename .endswith (".tar.gz" ):
118
111
try :
119
- with tarfile .open (filename , "r:gz" ) as archive :
120
- first_dir = archive .getnames ()[0 ].split ("/" )[0 ]
121
- total_files = len (archive .getnames ())
122
- for i , zipped_file in enumerate (archive .getnames (), 1 ):
123
- local_path = os .path .join (extracted_dir_path , zipped_file .replace (first_dir , rename_to , 1 ))
124
- if not os .path .exists (local_path ):
125
- print (f"\n Missing { zipped_file } on location: { extracted_dir_path } " )
126
- print (f"Verification failed; aborted in { format_time (time .time () - t1 )} " )
127
- return False
128
- print_verification_progress (total_files , i , t1 )
112
+ archive = tarfile .open (filename , "r:gz" )
113
+ file_list = archive .getnames ()
129
114
except tarfile .ReadError :
130
- print (f"Verification failed; aborted in { format_time (time .time () - t1 )} " )
115
+ if verbose :
116
+ print (f"Verification failed; aborted in { format_time (time .time () - t1 )} " )
131
117
return False
132
118
elif filename .endswith (".tar.xz" ):
133
119
try :
134
- with tarfile .open (filename , "r:xz" ) as archive :
135
- first_dir = archive .getnames ()[0 ].split ("/" )[0 ]
136
- total_files = len (archive .getnames ())
137
- for i , zipped_file in enumerate (archive .getnames (), 1 ):
138
- local_path = os .path .join (extracted_dir_path , zipped_file .replace (first_dir , rename_to , 1 ))
139
- if not os .path .exists (local_path ):
140
- print (f"\n Missing { zipped_file } on location: { extracted_dir_path } " )
141
- print (f"Verification failed; aborted in { format_time (time .time () - t1 )} " )
142
- return False
143
- print_verification_progress (total_files , i , t1 )
120
+ archive = tarfile .open (filename , "r:xz" )
121
+ file_list = archive .getnames ()
144
122
except tarfile .ReadError :
145
- print (f"Verification failed; aborted in { format_time (time .time () - t1 )} " )
123
+ if verbose :
124
+ print (f"Verification failed; aborted in { format_time (time .time () - t1 )} " )
146
125
return False
147
126
else :
148
127
raise NotImplementedError ("Unsupported archive type" )
149
128
129
+ try :
130
+ first_dir = file_list [0 ].split ("/" )[0 ]
131
+ total_files = len (file_list )
132
+ for i , zipped_file in enumerate (file_list , 1 ):
133
+ local_path = os .path .join (extracted_dir_path , zipped_file .replace (first_dir , rename_to , 1 ))
134
+ if not os .path .exists (local_path ):
135
+ if verbose :
136
+ print (f"\n Missing { zipped_file } on location: { extracted_dir_path } " )
137
+ print (f"Verification failed; aborted in { format_time (time .time () - t1 )} " )
138
+ return False
139
+ print_verification_progress (total_files , i , t1 )
140
+ except Exception as e :
141
+ print (f"\n Error: { e } " )
142
+ return False
143
+
150
144
if verbose :
151
145
print (f"\n Verification passed; completed in { format_time (time .time () - t1 )} " )
152
146
@@ -231,7 +225,12 @@ def unpack(filename, destination, force_extract): # noqa: C901
231
225
shutil .rmtree (rename_to )
232
226
shutil .move (dirname , rename_to )
233
227
234
- return True
228
+ if verify_files (filename , destination , rename_to ):
229
+ print (" Files extracted successfully." )
230
+ return True
231
+ else :
232
+ print (" Failed to extract files." )
233
+ return False
235
234
236
235
237
236
def download_file_with_progress (url , filename , start_time ):
@@ -291,6 +290,7 @@ def get_tool(tool, force_download, force_extract):
291
290
local_path = dist_dir + archive_name
292
291
url = tool ["url" ]
293
292
start_time = time .time ()
293
+ print ("" )
294
294
if not os .path .isfile (local_path ) or force_download :
295
295
if verbose :
296
296
print ("Downloading '" + archive_name + "' to '" + local_path + "'" )
@@ -421,6 +421,9 @@ def identify_platform():
421
421
current_dir + "/../package/package_esp32_index.template.json" , identified_platform
422
422
)
423
423
mkdir_p (dist_dir )
424
+
425
+ print ("\n Downloading and extracting tools..." )
426
+
424
427
for tool in tools_to_download :
425
428
if is_test :
426
429
print ("Would install: {0}" .format (tool ["archiveFileName" ]))
@@ -432,4 +435,4 @@ def identify_platform():
432
435
print (f"Tool { tool ['archiveFileName' ]} was corrupted, but re-downloading did not help!\n " )
433
436
sys .exit (1 )
434
437
435
- print ("Platform Tools Installed" )
438
+ print ("\n Platform Tools Installed" )
0 commit comments