lhmd commited on
Commit
0299d25
·
verified ·
1 Parent(s): dfdf337

Update download.py

Browse files
Files changed (1) hide show
  1. download.py +18 -2
download.py CHANGED
@@ -195,12 +195,28 @@ def download(download_list: list, output_dir: str, is_clean_cache: bool):
195
  if is_clean_cache:
196
  clean_huggingface_cache(output_dir, repo)
197
 
198
- # unzip the file
199
  if rel_path.endswith('.zip'):
200
  zip_file = join(output_dir, rel_path)
 
 
 
 
 
201
  with zipfile.ZipFile(zip_file, 'r') as zip_ref:
202
- ofile = join(output_dir, os.path.dirname(rel_path))
203
  zip_ref.extractall(ofile)
 
 
 
 
 
 
 
 
 
 
 
 
204
  os.remove(zip_file)
205
  else:
206
  print(f'Download {rel_path} failed')
 
195
  if is_clean_cache:
196
  clean_huggingface_cache(output_dir, repo)
197
 
198
+ # unzip the file
199
  if rel_path.endswith('.zip'):
200
  zip_file = join(output_dir, rel_path)
201
+ hash_name = os.path.basename(rel_path).replace('.zip', '')
202
+ # Create target directory: output_dir/batch/hash_name
203
+ ofile = join(output_dir, os.path.dirname(rel_path), hash_name)
204
+ os.makedirs(ofile, exist_ok=True)
205
+
206
  with zipfile.ZipFile(zip_file, 'r') as zip_ref:
 
207
  zip_ref.extractall(ofile)
208
+
209
+ # Check if there's a nested hash/hash/ structure
210
+ inner_hash_dir = join(ofile, hash_name)
211
+ if os.path.exists(inner_hash_dir) and os.path.isdir(inner_hash_dir):
212
+ # Move all contents from inner hash dir to outer hash dir
213
+ for item in os.listdir(inner_hash_dir):
214
+ src = join(inner_hash_dir, item)
215
+ dst = join(ofile, item)
216
+ shutil.move(src, dst)
217
+ # Remove the now-empty inner hash directory
218
+ os.rmdir(inner_hash_dir)
219
+
220
  os.remove(zip_file)
221
  else:
222
  print(f'Download {rel_path} failed')