Qi28 commited on
Commit
4765698
·
verified ·
1 Parent(s): 752a58a

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +1 -12
main.py CHANGED
@@ -87,10 +87,6 @@ openi_datasets = [
87
 
88
 
89
  def download_openi(datasets):
90
- """
91
- 下载多个数据集到不同目录,如果保存路径不存在则不下载,如果配置文件中已存在则不下载
92
- 根据 dataset 中的 extract 和 use_unzip 参数控制是否解压以及使用何种解压工具
93
- """
94
  for dataset in datasets:
95
  dataset_name = dataset["dataset_name"]
96
  file_name = dataset["file_name"]
@@ -98,25 +94,20 @@ def download_openi(datasets):
98
  extract = dataset.get("extract", True)
99
  use_unzip = dataset.get("use_unzip", True)
100
 
101
- # 检查保存路径是否存在
102
  if not os.path.exists(save_path):
103
  print(f"保存路径 {save_path} 不存在,跳过下载 {file_name}。")
104
  continue
105
 
106
- # 读取对应数据集的 time.ini 配置文件
107
  config = configparser.ConfigParser()
108
  config.read(os.path.join(save_path, 'time.ini'))
109
 
110
- # 检查 time.ini 配置文件中是否已存在该文件
111
  if config.has_option('downloaded_files', file_name):
112
  print(f"配置文件中已存在 {file_name},跳过下载。")
113
  continue
114
 
115
- # 下载数据集
116
  os.system(f'openi dataset download {dataset_name} {file_name} --cluster NPU --save_path {save_path}')
117
  print(f"数据集 {file_name} 已下载到 {save_path} 目录。")
118
 
119
- # 更新对应数据集的 time.ini 配置文件
120
  if not config.has_section('downloaded_files'):
121
  config.add_section('downloaded_files')
122
  config.set('downloaded_files', file_name, 'True')
@@ -133,7 +124,6 @@ def download_openi(datasets):
133
  else:
134
  os.system(f'7z x {os.path.join(save_path, file_name)} -o{extract_path} -aoa')
135
 
136
- # 将解压后的文件移动到指定的路径
137
  for root, dirs, files in os.walk(extract_path):
138
  for file in files:
139
  src_path = os.path.join(root, file)
@@ -143,11 +133,10 @@ def download_openi(datasets):
143
  src_path = os.path.join(root, dir)
144
  dst_path = os.path.join(save_path, dir)
145
  shutil.move(src_path, dst_path)
146
- # 删除解压后创建的文件夹
147
  shutil.rmtree(extract_path)
148
  print(f"数据集 {file_name} 已解压到 {save_path} 目录。")
149
 
150
- # 删除压缩包文件
151
  os.remove(os.path.join(save_path, file_name))
152
  print(f"已删除压缩包文件 {file_name}。")
153
 
 
87
 
88
 
89
  def download_openi(datasets):
 
 
 
 
90
  for dataset in datasets:
91
  dataset_name = dataset["dataset_name"]
92
  file_name = dataset["file_name"]
 
94
  extract = dataset.get("extract", True)
95
  use_unzip = dataset.get("use_unzip", True)
96
 
 
97
  if not os.path.exists(save_path):
98
  print(f"保存路径 {save_path} 不存在,跳过下载 {file_name}。")
99
  continue
100
 
 
101
  config = configparser.ConfigParser()
102
  config.read(os.path.join(save_path, 'time.ini'))
103
 
 
104
  if config.has_option('downloaded_files', file_name):
105
  print(f"配置文件中已存在 {file_name},跳过下载。")
106
  continue
107
 
 
108
  os.system(f'openi dataset download {dataset_name} {file_name} --cluster NPU --save_path {save_path}')
109
  print(f"数据集 {file_name} 已下载到 {save_path} 目录。")
110
 
 
111
  if not config.has_section('downloaded_files'):
112
  config.add_section('downloaded_files')
113
  config.set('downloaded_files', file_name, 'True')
 
124
  else:
125
  os.system(f'7z x {os.path.join(save_path, file_name)} -o{extract_path} -aoa')
126
 
 
127
  for root, dirs, files in os.walk(extract_path):
128
  for file in files:
129
  src_path = os.path.join(root, file)
 
133
  src_path = os.path.join(root, dir)
134
  dst_path = os.path.join(save_path, dir)
135
  shutil.move(src_path, dst_path)
136
+
137
  shutil.rmtree(extract_path)
138
  print(f"数据集 {file_name} 已解压到 {save_path} 目录。")
139
 
 
140
  os.remove(os.path.join(save_path, file_name))
141
  print(f"已删除压缩包文件 {file_name}。")
142