Nebularer commited on
Commit
c3f6340
·
verified ·
1 Parent(s): 874b462

Update zip_merged_poses.py

Browse files
Files changed (1) hide show
  1. zip_merged_poses.py +2 -12
zip_merged_poses.py CHANGED
@@ -7,7 +7,6 @@ from pathlib import Path
7
  def zip_directory_with_progress(source_dir, output_zip):
8
  source_path = Path(source_dir)
9
 
10
- # 1. Scanning directory to calculate total size
11
  print(f"Scanning directory: {source_dir} ...", flush=True)
12
  file_list = []
13
  total_size = 0
@@ -25,19 +24,14 @@ def zip_directory_with_progress(source_dir, output_zip):
25
  processed_size = 0
26
  start_time = time.time()
27
 
28
- # 2. Start Archiving
29
- # Using ZIP_STORED for maximum speed with 119GB of data
30
  with zipfile.ZipFile(output_zip, 'w', zipfile.ZIP_STORED) as zf:
31
  for file_path in file_list:
32
- # Write to zip
33
  arcname = os.path.relpath(file_path, source_path.parent)
34
  zf.write(file_path, arcname)
35
 
36
- # Update progress
37
  file_size = os.path.getsize(file_path)
38
  processed_size += file_size
39
 
40
- # Calculate time and percentage
41
  percent = (processed_size / total_size) * 100
42
  elapsed_time = time.time() - start_time
43
 
@@ -47,10 +41,8 @@ def zip_directory_with_progress(source_dir, output_zip):
47
  else:
48
  remaining_time = 0
49
 
50
- # Formatting progress bar
51
  mb_per_sec = (processed_size / (1024**2)) / elapsed_time if elapsed_time > 0 else 0
52
 
53
- # Using \r and flush=True to ensure real-time updates in logs
54
  progress_msg = (
55
  f"\rProgress: [{int(percent/2)*'=':50}] {percent:.1f}% | "
56
  f"Speed: {mb_per_sec:.2f} MB/s | "
@@ -64,9 +56,7 @@ def zip_directory_with_progress(source_dir, output_zip):
64
  print(f"Output File: {output_zip}", flush=True)
65
 
66
  if __name__ == "__main__":
67
- # Paths based on your cluster environment
68
- TARGET = "/mnt/shared-storage-user/mllm/zangyuhang/pmx/SLGDatasets/CSL_News/merged_poses"
69
- OUTPUT = "/mnt/shared-storage-user/mllm/zangyuhang/pmx/SLGDatasets/CSL_News/merged_poses.zip"
70
 
71
- # Run with -u if possible: python3 -u zip_with_progress.py
72
  zip_directory_with_progress(TARGET, OUTPUT)
 
7
  def zip_directory_with_progress(source_dir, output_zip):
8
  source_path = Path(source_dir)
9
 
 
10
  print(f"Scanning directory: {source_dir} ...", flush=True)
11
  file_list = []
12
  total_size = 0
 
24
  processed_size = 0
25
  start_time = time.time()
26
 
 
 
27
  with zipfile.ZipFile(output_zip, 'w', zipfile.ZIP_STORED) as zf:
28
  for file_path in file_list:
 
29
  arcname = os.path.relpath(file_path, source_path.parent)
30
  zf.write(file_path, arcname)
31
 
 
32
  file_size = os.path.getsize(file_path)
33
  processed_size += file_size
34
 
 
35
  percent = (processed_size / total_size) * 100
36
  elapsed_time = time.time() - start_time
37
 
 
41
  else:
42
  remaining_time = 0
43
 
 
44
  mb_per_sec = (processed_size / (1024**2)) / elapsed_time if elapsed_time > 0 else 0
45
 
 
46
  progress_msg = (
47
  f"\rProgress: [{int(percent/2)*'=':50}] {percent:.1f}% | "
48
  f"Speed: {mb_per_sec:.2f} MB/s | "
 
56
  print(f"Output File: {output_zip}", flush=True)
57
 
58
  if __name__ == "__main__":
59
+ TARGET = ""
60
+ OUTPUT = ""
 
61
 
 
62
  zip_directory_with_progress(TARGET, OUTPUT)