11#!/usr/bin/env python3
2+
3+ """
4+ Module for downloading and extracting NoC MLP benchmarks
5+ """
6+
27import sys
38import os
49import argparse
10+ import urllib .request
511import urllib .parse
6- import urllib .request , urllib .parse , urllib .error
7- import urllib .request , urllib .error , urllib .parse
12+ import urllib .error
813import math
914import textwrap
1015import tarfile
1116import tempfile
1217import shutil
1318import errno
1419
15-
16- class DownloadError (Exception ):
17- pass
18-
19-
20- class ChecksumError (Exception ):
21- pass
22-
23-
2420class ExtractionError (Exception ):
25- pass
21+ """
22+ Raised when extracting the downlaoded file fails
23+ """
2624
2725
2826URL_MIRRORS = {"eecg" : "https://www.eecg.utoronto.ca/~vaughn/titan/" }
2927
3028
3129def parse_args ():
30+ """
31+ Parses command line arguments
32+ """
3233 description = textwrap .dedent (
3334 """
3435 Download and extract a MLP NoC benchmarks into a
@@ -38,7 +39,8 @@ def parse_args():
3839 does nothing (unless --force is specified).
3940 """
4041 )
41- parser = argparse .ArgumentParser (formatter_class = argparse .ArgumentDefaultsHelpFormatter )
42+ parser = argparse .ArgumentParser (formatter_class = argparse .ArgumentDefaultsHelpFormatter ,
43+ description = description )
4244
4345 parser .add_argument (
4446 "--vtr_flow_dir" ,
@@ -64,6 +66,9 @@ def parse_args():
6466
6567
6668def main ():
69+ """
70+ main() implementation
71+ """
6772
6873 args = parse_args ()
6974
@@ -83,10 +88,6 @@ def main():
8388
8489 print ("Extracting {}" .format (tar_gz_filename ))
8590 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 )
9091 except ExtractionError as e :
9192 print ("Failed to extract NoC MLP benchmarks release:" , e )
9293 sys .exit (3 )
@@ -124,17 +125,11 @@ def extract_to_vtr_flow_dir(args, tar_gz_filename):
124125 benchmarks_dir = os .path .join (args .vtr_flow_dir , "benchmarks" )
125126 mlp_benchmarks_dir = os .path .join (benchmarks_dir , "noc/Large_Designs/MLP" )
126127
127-
128128 if not args .force :
129129 # 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 ))
138133
139134 # Create a temporary working directory
140135 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):
143138 with tarfile .open (tar_gz_filename , "r:gz" ) as tar :
144139 tar .extractall (tmpdir )
145140 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 ):
147142 for file in files :
148143 source_file = os .path .join (root , file )
149144 relative_path = os .path .relpath (source_file , tmp_source_blif_dir )
150145 destination_file = os .path .join (mlp_benchmarks_dir , relative_path )
151146 os .makedirs (os .path .dirname (destination_file ), exist_ok = True )
152- shutil .copy2 (source_file , destination_file )
147+ shutil .copy2 (source_file , destination_file )
153148
154149 # Create symbolic links to blif files
155150 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):
173168 os .makedirs (link_folder_path , exist_ok = True )
174169
175170 # Walk through all subdirectories
176- for root , dirs , files in os .walk (base_path ):
171+ for root , _ , files in os .walk (base_path ):
177172 if root == link_folder_path :
178173 continue
179174
0 commit comments