1
1
#!/usr/bin/env python3
2
+ """
3
+ Script to download the SymbiFlow Series-7 architectures
4
+ """
5
+
2
6
import sys
3
7
import os
4
8
import argparse
5
- import urllib .parse
6
- import urllib .request , urllib .parse , urllib .error
7
- import urllib .request , urllib .error , urllib .parse
8
- import hashlib
9
9
import math
10
10
import textwrap
11
- import tarfile
12
11
import fnmatch
13
- import errno
14
12
import tempfile
15
13
import shutil
16
- import glob
17
14
import subprocess
15
+ from urllib import request
18
16
17
+ GCS_URL = (
18
+ "https://storage.googleapis.com/symbiflow-arch-defs/artifacts/prod/"
19
+ "foss-fpga-tools/symbiflow-arch-defs/presubmit/install/"
20
+ "731/20200926-090152/symbiflow-arch-defs-install-e3de025d.tar.xz"
21
+ )
19
22
20
- class DownloadError (Exception ):
21
- pass
22
-
23
-
24
- class ChecksumError (Exception ):
25
- pass
23
+ SYMBIFLOW_URL_MIRRORS = {"google" : GCS_URL }
26
24
27
25
28
26
class ExtractionError (Exception ):
29
- pass
30
-
31
-
32
- SYMBIFLOW_URL_MIRRORS = {
33
- "google" : "https://storage.googleapis.com/symbiflow-arch-defs/artifacts/prod/foss-fpga-tools/symbiflow-arch-defs/presubmit/install/731/20200926-090152/symbiflow-arch-defs-install-e3de025d.tar.xz"
34
- }
27
+ """
28
+ Extraction error exception class
29
+ """
35
30
36
31
37
32
def parse_args ():
33
+ """
34
+ Parses and returns script's arguments
35
+ """
36
+
38
37
description = textwrap .dedent (
39
38
"""
40
- Download and extract a symbiflow benchmark release into a
41
- VTR-style directory structure.
39
+ Download and extract a symbiflow benchmark release into a
40
+ VTR-style directory structure.
42
41
43
- If a previous matching symbiflow release tar.gz file is found
44
- does nothing (unless --force is specified).
45
- """
42
+ If a previous matching symbiflow release tar.gz file is found
43
+ does nothing (unless --force is specified).
44
+ """
45
+ )
46
+ parser = argparse .ArgumentParser (
47
+ formatter_class = argparse .ArgumentDefaultsHelpFormatter , description = description
46
48
)
47
- parser = argparse .ArgumentParser (formatter_class = argparse .ArgumentDefaultsHelpFormatter )
48
49
49
50
parser .add_argument (
50
51
"--vtr_flow_dir" ,
@@ -60,13 +61,11 @@ def parse_args():
60
61
help = "Run extraction step even if directores etc. already exist" ,
61
62
)
62
63
63
- parser .add_argument (
64
- "--mirror" , default = "google" , choices = ["google" ], help = "Download mirror"
65
- )
64
+ parser .add_argument ("--mirror" , default = "google" , choices = ["google" ], help = "Download mirror" )
66
65
67
66
parser .add_argument (
68
67
"--upgrade_archs" ,
69
- action = ' store_true' ,
68
+ action = " store_true" ,
70
69
default = True ,
71
70
help = "Try to upgrade included architecture files (using the upgrade_archs.py)" ,
72
71
)
@@ -75,6 +74,9 @@ def parse_args():
75
74
76
75
77
76
def main ():
77
+ """
78
+ Main function
79
+ """
78
80
79
81
args = parse_args ()
80
82
@@ -89,12 +91,9 @@ def main():
89
91
print ("Extracting {}" .format (tar_xz_filename ))
90
92
extract_to_vtr_flow_dir (args , tar_xz_filename )
91
93
92
- except DownloadError as e :
93
- print ("Failed to download: " , e )
94
+ except ExtractionError as error :
95
+ print ("Failed to extract data: " , error )
94
96
sys .exit (1 )
95
- except ExtractionError as e :
96
- print ("Failed to extract symbiflow release:" , e )
97
- sys .exit (2 )
98
97
99
98
sys .exit (0 )
100
99
@@ -103,7 +102,7 @@ def download_url(filename, url):
103
102
"""
104
103
Downloads the symbiflow release
105
104
"""
106
- urllib . request .urlretrieve (url , filename , reporthook = download_progress_callback )
105
+ request .urlretrieve (url , filename , reporthook = download_progress_callback )
107
106
108
107
109
108
def download_progress_callback (block_num , block_size , expected_size ):
@@ -119,14 +118,6 @@ def download_progress_callback(block_num, block_size, expected_size):
119
118
if block_num * block_size >= expected_size :
120
119
print ("" )
121
120
122
- def force_symlink (file1 , file2 ):
123
- try :
124
- os .symlink (file1 , file2 )
125
- except OSError as e :
126
- if e .errno == errno .EEXIST :
127
- os .remove (file2 )
128
- os .symlink (file1 , file2 )
129
-
130
121
131
122
def extract_to_vtr_flow_dir (args , tar_xz_filename ):
132
123
"""
@@ -137,7 +128,9 @@ def extract_to_vtr_flow_dir(args, tar_xz_filename):
137
128
# Reference directories
138
129
arch_dir = os .path .join (args .vtr_flow_dir , "arch" )
139
130
symbiflow_arch_extract_dir = os .path .join (arch_dir , "symbiflow" )
140
- symbiflow_test_dir = os .path .join (args .vtr_flow_dir , "tasks" , "regression_tests" , "vtr_reg_nightly" , "symbiflow" )
131
+ symbiflow_test_dir = os .path .join (
132
+ args .vtr_flow_dir , "tasks" , "regression_tests" , "vtr_reg_nightly" , "symbiflow"
133
+ )
141
134
142
135
arch_upgrade_script = os .path .join (
143
136
os .path .dirname (os .path .realpath (__file__ )), "upgrade_arch.py"
@@ -149,53 +142,41 @@ def extract_to_vtr_flow_dir(args, tar_xz_filename):
149
142
args .vtr_flow_dir ,
150
143
symbiflow_arch_extract_dir ,
151
144
]
152
- for dir in expected_dirs :
153
- if not os .path .isdir (dir ):
154
- raise ExtractionError ("{} should be a directory" .format (dir ))
145
+ for directory in expected_dirs :
146
+ if not os .path .isdir (directory ):
147
+ raise ExtractionError ("{} should be a directory" .format (directory ))
155
148
156
149
# Create a temporary working directory
157
150
tmpdir = tempfile .mkdtemp (suffix = "download_symbiflow" , dir = "." )
158
151
159
152
# Extract matching files into the temporary directory
160
- subprocess .call ("tar -C {} -xf {} share/symbiflow/arch/xc7a50t_test" .format (tmpdir , tar_xz_filename ), shell = True )
153
+ subprocess .call (
154
+ "tar -C {} -xf {} share/symbiflow/arch/xc7a50t_test" .format (tmpdir , tar_xz_filename ),
155
+ shell = True ,
156
+ )
161
157
162
158
# Move the extracted files to the relevant directories, SDC files first (since we
163
159
# need to look up the BLIF name to make it match)
164
- for dirpath , dirnames , filenames in os .walk (tmpdir ):
160
+ for dirpath , _ , filenames in os .walk (tmpdir ):
165
161
for filename in filenames :
166
162
src_file_path = os .path .join (dirpath , filename )
167
163
dst_file_path = None
168
164
169
165
if fnmatch .fnmatch (src_file_path , "*/xc7a50t_test/arch.timing.xml" ):
170
- dst_file_path = os .path .join (
171
- symbiflow_arch_extract_dir , "arch.timing.xml"
172
- )
166
+ dst_file_path = os .path .join (symbiflow_arch_extract_dir , "arch.timing.xml" )
173
167
174
168
subprocess .call ("{} {}" .format (arch_upgrade_script , src_file_path ), shell = True )
175
169
176
170
elif fnmatch .fnmatch (src_file_path , "*/xc7a50t_test/*.bin" ):
177
- dst_file_path = os .path .join (
178
- symbiflow_test_dir , filename
179
- )
171
+ dst_file_path = os .path .join (symbiflow_test_dir , filename )
180
172
181
173
if dst_file_path :
182
174
shutil .move (src_file_path , dst_file_path )
183
175
184
-
185
176
shutil .rmtree (tmpdir )
186
177
187
178
print ("Done" )
188
179
189
180
190
- def extract_callback (members ):
191
- for tarinfo in members :
192
- if fnmatch .fnmatch (tarinfo .name , "*/*.xml" ):
193
- print (tarinfo .name )
194
- yield tarinfo
195
- elif fnmatch .fnmatch (tarinfo .name , "*/*.bin" ):
196
- print (tarinfo .name )
197
- yield tarinfo
198
-
199
-
200
181
if __name__ == "__main__" :
201
182
main ()
0 commit comments