1
1
#!/usr/bin/env python3
2
+
3
+ """
4
+ Module for downloading and extracting NoC MLP benchmarks
5
+ """
6
+
2
7
import sys
3
8
import os
4
9
import argparse
10
+ import urllib .request
5
11
import urllib .parse
6
- import urllib .request , urllib .parse , urllib .error
7
- import urllib .request , urllib .error , urllib .parse
12
+ import urllib .error
8
13
import math
9
14
import textwrap
10
15
import tarfile
11
16
import tempfile
12
17
import shutil
13
18
import errno
14
19
15
-
16
- class DownloadError (Exception ):
17
- pass
18
-
19
-
20
- class ChecksumError (Exception ):
21
- pass
22
-
23
-
24
20
class ExtractionError (Exception ):
25
- pass
21
+ """
22
+ Raised when extracting the downlaoded file fails
23
+ """
26
24
27
25
28
26
URL_MIRRORS = {"eecg" : "https://www.eecg.utoronto.ca/~vaughn/titan/" }
29
27
30
28
31
29
def parse_args ():
30
+ """
31
+ Parses command line arguments
32
+ """
32
33
description = textwrap .dedent (
33
34
"""
34
35
Download and extract a MLP NoC benchmarks into a
@@ -38,7 +39,8 @@ def parse_args():
38
39
does nothing (unless --force is specified).
39
40
"""
40
41
)
41
- parser = argparse .ArgumentParser (formatter_class = argparse .ArgumentDefaultsHelpFormatter )
42
+ parser = argparse .ArgumentParser (formatter_class = argparse .ArgumentDefaultsHelpFormatter ,
43
+ description = description )
42
44
43
45
parser .add_argument (
44
46
"--vtr_flow_dir" ,
@@ -64,6 +66,9 @@ def parse_args():
64
66
65
67
66
68
def main ():
69
+ """
70
+ main() implementation
71
+ """
67
72
68
73
args = parse_args ()
69
74
@@ -83,10 +88,6 @@ def main():
83
88
84
89
print ("Extracting {}" .format (tar_gz_filename ))
85
90
extract_to_vtr_flow_dir (args , tar_gz_filename )
86
-
87
- except DownloadError as e :
88
- print ("Failed to download:" , e )
89
- sys .exit (1 )
90
91
except ExtractionError as e :
91
92
print ("Failed to extract NoC MLP benchmarks release:" , e )
92
93
sys .exit (3 )
@@ -124,17 +125,11 @@ def extract_to_vtr_flow_dir(args, tar_gz_filename):
124
125
benchmarks_dir = os .path .join (args .vtr_flow_dir , "benchmarks" )
125
126
mlp_benchmarks_dir = os .path .join (benchmarks_dir , "noc/Large_Designs/MLP" )
126
127
127
-
128
128
if not args .force :
129
129
# Check that all expected directories exist
130
- expected_dirs = [
131
- args .vtr_flow_dir ,
132
- benchmarks_dir ,
133
- mlp_benchmarks_dir ,
134
- ]
135
- for dir in expected_dirs :
136
- if not os .path .isdir (dir ):
137
- raise ExtractionError ("{} should be a directory" .format (dir ))
130
+ for directory in [args .vtr_flow_dir , benchmarks_dir , mlp_benchmarks_dir ]:
131
+ if not os .path .isdir (directory ):
132
+ raise ExtractionError ("{} should be a directory" .format (directory ))
138
133
139
134
# Create a temporary working directory
140
135
tmpdir = tempfile .mkdtemp (suffix = "download_NoC_MLP" , dir = os .path .abspath ("." ))
@@ -143,13 +138,13 @@ def extract_to_vtr_flow_dir(args, tar_gz_filename):
143
138
with tarfile .open (tar_gz_filename , "r:gz" ) as tar :
144
139
tar .extractall (tmpdir )
145
140
tmp_source_blif_dir = os .path .join (tmpdir , "MLP_Benchmark_Netlist_Files" )
146
- for root , dirs , files in os .walk (tmp_source_blif_dir ):
141
+ for root , _ , files in os .walk (tmp_source_blif_dir ):
147
142
for file in files :
148
143
source_file = os .path .join (root , file )
149
144
relative_path = os .path .relpath (source_file , tmp_source_blif_dir )
150
145
destination_file = os .path .join (mlp_benchmarks_dir , relative_path )
151
146
os .makedirs (os .path .dirname (destination_file ), exist_ok = True )
152
- shutil .copy2 (source_file , destination_file )
147
+ shutil .copy2 (source_file , destination_file )
153
148
154
149
# Create symbolic links to blif files
155
150
find_and_link_files (mlp_benchmarks_dir , ".blif" , "blif_files" )
@@ -173,7 +168,7 @@ def find_and_link_files(base_path, target_extension, link_folder_name):
173
168
os .makedirs (link_folder_path , exist_ok = True )
174
169
175
170
# Walk through all subdirectories
176
- for root , dirs , files in os .walk (base_path ):
171
+ for root , _ , files in os .walk (base_path ):
177
172
if root == link_folder_path :
178
173
continue
179
174
0 commit comments