1
1
import json
2
2
import os
3
+ from pathlib import Path
3
4
4
5
from sc2_datasets .utils .zip_utils import unpack_zipfile
5
6
8
9
9
10
def load_replaypack_information (
10
11
replaypack_name : str ,
11
- replaypack_path : str ,
12
+ replaypack_path : Path ,
12
13
unpack_n_workers : int ,
13
14
) -> Tuple [str , Dict [str , str ], Dict [str , str ]]:
14
15
"""
@@ -56,9 +57,9 @@ def load_replaypack_information(
56
57
>>> assert unpack_n_workers >= 1
57
58
"""
58
59
59
- replaypack_files = os . listdir (replaypack_path )
60
+ replaypack_files = list (replaypack_path . iterdir () )
60
61
# Initializing variables that should be returned:
61
- replaypack_data_path = os . path . join (replaypack_path , replaypack_name + "_data" )
62
+ replaypack_data_path = Path (replaypack_path , replaypack_name + "_data" ). resolve ( )
62
63
replaypack_main_log_obj_list = []
63
64
replaypack_processed_failed = {}
64
65
replaypack_summary = {}
@@ -67,29 +68,34 @@ def load_replaypack_information(
67
68
# Extracting the nested .zip files,
68
69
# and loading replaypack information files:
69
70
for file in replaypack_files :
70
- if file .endswith ("_data.zip" ):
71
+ filename = file .name
72
+ if filename .endswith ("_data.zip" ):
71
73
# Unpack the .zip archive only if it is not unpacked already:
72
- if not os . path . isdir ( replaypack_data_path ):
74
+ if not replaypack_data_path . is_dir ( ):
73
75
replaypack_data_path = unpack_zipfile (
74
76
destination_dir = replaypack_path ,
75
77
subdir = replaypack_name + "_data" ,
76
78
zip_path = os .path .join (replaypack_path , file ),
77
79
n_workers = unpack_n_workers ,
78
80
)
79
- if file .endswith ("_main_log.log" ):
80
- with open (os .path .join (replaypack_path , file )) as main_log_file :
81
+ if filename .endswith ("_main_log.log" ):
82
+ main_log_filepath = Path (replaypack_path , file ).resolve ()
83
+ with main_log_filepath .open (encoding = "utf-8" ) as main_log_file :
81
84
# Reading the lines of the log file and parsing them:
82
85
for line in main_log_file .readlines ():
83
86
log_object = json .loads (line )
84
87
replaypack_main_log_obj_list .append (log_object )
85
- if file .endswith ("_processed_failed.log" ):
86
- with open (os .path .join (replaypack_path , file )) as processed_files :
88
+ if filename .endswith ("_processed_failed.log" ):
89
+ processed_files_filepath = Path (replaypack_path , file ).resolve ()
90
+ with processed_files_filepath .open (encoding = "utf-8" ) as processed_files :
87
91
replaypack_processed_failed = json .load (processed_files )
88
- if file .endswith ("_processed_mapping.json" ):
89
- with open (os .path .join (replaypack_path , file )) as mapping_file :
92
+ if filename .endswith ("_processed_mapping.json" ):
93
+ mapping_file_filepath = Path (replaypack_path , file ).resolve ()
94
+ with mapping_file_filepath .open (encoding = "utf-8" ) as mapping_file :
90
95
replaypack_dir_mapping = json .load (mapping_file )
91
- if file .endswith ("_summary.json" ):
92
- with open (os .path .join (replaypack_path , file )) as summary_file :
96
+ if filename .endswith ("_summary.json" ):
97
+ summary_file_filepath = Path (replaypack_path , file ).resolve ()
98
+ with summary_file_filepath .open (encoding = "utf-8" ) as summary_file :
93
99
replaypack_summary = json .load (summary_file )
94
100
95
101
return (
0 commit comments