Skip to content

Commit e0b000c

Browse files
committed
symbiflow: fix linter issues
Signed-off-by: Alessandro Comodi <[email protected]>
1 parent 6127f33 commit e0b000c

File tree

1 file changed

+47
-66
lines changed

1 file changed

+47
-66
lines changed
Lines changed: 47 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,51 @@
11
#!/usr/bin/env python3
2+
"""
3+
Script to download the SymbiFlow Series-7 architectures
4+
"""
5+
26
import sys
37
import os
48
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
99
import math
1010
import textwrap
11-
import tarfile
1211
import fnmatch
13-
import errno
1412
import tempfile
1513
import shutil
16-
import glob
1714
import subprocess
15+
from urllib import request
1816

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+
)
1922

20-
class DownloadError(Exception):
21-
pass
22-
23-
24-
class ChecksumError(Exception):
25-
pass
23+
SYMBIFLOW_URL_MIRRORS = {"google": GCS_URL}
2624

2725

2826
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+
"""
3530

3631

3732
def parse_args():
33+
"""
34+
Parses and returns script's arguments
35+
"""
36+
3837
description = textwrap.dedent(
3938
"""
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.
4241
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
4648
)
47-
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
4849

4950
parser.add_argument(
5051
"--vtr_flow_dir",
@@ -60,13 +61,11 @@ def parse_args():
6061
help="Run extraction step even if directores etc. already exist",
6162
)
6263

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")
6665

6766
parser.add_argument(
6867
"--upgrade_archs",
69-
action='store_true',
68+
action="store_true",
7069
default=True,
7170
help="Try to upgrade included architecture files (using the upgrade_archs.py)",
7271
)
@@ -75,6 +74,9 @@ def parse_args():
7574

7675

7776
def main():
77+
"""
78+
Main function
79+
"""
7880

7981
args = parse_args()
8082

@@ -89,12 +91,9 @@ def main():
8991
print("Extracting {}".format(tar_xz_filename))
9092
extract_to_vtr_flow_dir(args, tar_xz_filename)
9193

92-
except DownloadError as e:
93-
print("Failed to download:", e)
94+
except ExtractionError as error:
95+
print("Failed to extract data: ", error)
9496
sys.exit(1)
95-
except ExtractionError as e:
96-
print("Failed to extract symbiflow release:", e)
97-
sys.exit(2)
9897

9998
sys.exit(0)
10099

@@ -103,7 +102,7 @@ def download_url(filename, url):
103102
"""
104103
Downloads the symbiflow release
105104
"""
106-
urllib.request.urlretrieve(url, filename, reporthook=download_progress_callback)
105+
request.urlretrieve(url, filename, reporthook=download_progress_callback)
107106

108107

109108
def download_progress_callback(block_num, block_size, expected_size):
@@ -119,14 +118,6 @@ def download_progress_callback(block_num, block_size, expected_size):
119118
if block_num * block_size >= expected_size:
120119
print("")
121120

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-
130121

131122
def extract_to_vtr_flow_dir(args, tar_xz_filename):
132123
"""
@@ -137,7 +128,9 @@ def extract_to_vtr_flow_dir(args, tar_xz_filename):
137128
# Reference directories
138129
arch_dir = os.path.join(args.vtr_flow_dir, "arch")
139130
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+
)
141134

142135
arch_upgrade_script = os.path.join(
143136
os.path.dirname(os.path.realpath(__file__)), "upgrade_arch.py"
@@ -149,53 +142,41 @@ def extract_to_vtr_flow_dir(args, tar_xz_filename):
149142
args.vtr_flow_dir,
150143
symbiflow_arch_extract_dir,
151144
]
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))
155148

156149
# Create a temporary working directory
157150
tmpdir = tempfile.mkdtemp(suffix="download_symbiflow", dir=".")
158151

159152
# 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+
)
161157

162158
# Move the extracted files to the relevant directories, SDC files first (since we
163159
# 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):
165161
for filename in filenames:
166162
src_file_path = os.path.join(dirpath, filename)
167163
dst_file_path = None
168164

169165
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")
173167

174168
subprocess.call("{} {}".format(arch_upgrade_script, src_file_path), shell=True)
175169

176170
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)
180172

181173
if dst_file_path:
182174
shutil.move(src_file_path, dst_file_path)
183175

184-
185176
shutil.rmtree(tmpdir)
186177

187178
print("Done")
188179

189180

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-
200181
if __name__ == "__main__":
201182
main()

0 commit comments

Comments
 (0)