python: fix flake8 warnings and format with black
Most of the flake8 warnings in this repository were fairly trivial,
so fixed them. The "openbmctool" is 7000+ lines of pretty heavily
warned code, so just disabling that one. Format everything with
black.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Icb3f6ee9bf03dece58785f7af00617c87a84aa65
diff --git a/rootfs_size/rootfs_size.py b/rootfs_size/rootfs_size.py
index 3e21b78..db2dd7b 100755
--- a/rootfs_size/rootfs_size.py
+++ b/rootfs_size/rootfs_size.py
@@ -1,34 +1,44 @@
#!/usr/bin/python3
-import subprocess
-import tempfile
-import os
-from os.path import join, getsize
import argparse
-from multiprocessing import Pool, cpu_count
+import os
import shutil
+import subprocess
import sys
+import tempfile
+from multiprocessing import Pool, cpu_count
+from os.path import getsize
# Set command line arguments
parser = argparse.ArgumentParser(
- formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter
+)
-parser.add_argument("-b", "--build_dir",
- dest="BUILD_DIR",
- default="/home/ed/openbmc-openbmc",
- help="Build directory path.")
+parser.add_argument(
+ "-b",
+ "--build_dir",
+ dest="BUILD_DIR",
+ default="/home/ed/openbmc-openbmc",
+ help="Build directory path.",
+)
-parser.add_argument("-s", "--squashfs_file",
- dest="SQUASHFS_FILE",
- default="/build/tmp/deploy/images/wolfpass" +
- "/intel-platforms-wolfpass.squashfs-xz",
- help="Squashfs file.")
+parser.add_argument(
+ "-s",
+ "--squashfs_file",
+ dest="SQUASHFS_FILE",
+ default="/build/tmp/deploy/images/wolfpass"
+ + "/intel-platforms-wolfpass.squashfs-xz",
+ help="Squashfs file.",
+)
-parser.add_argument("-t", "--threads",
- dest="threads",
- default=int(cpu_count()),
- type=int,
- help="Number of threads to use (defaults to cpu count)")
+parser.add_argument(
+ "-t",
+ "--threads",
+ dest="threads",
+ default=int(cpu_count()),
+ type=int,
+ help="Number of threads to use (defaults to cpu count)",
+)
args = parser.parse_args()
@@ -48,26 +58,39 @@
def get_unsquash_results(filepath):
with tempfile.TemporaryDirectory() as newsquashfsroot:
input_path = os.path.join(newsquashfsroot, "input")
- shutil.copytree(squashfsdir, input_path, symlinks=True,
- ignore_dangling_symlinks=True)
+ shutil.copytree(
+ squashfsdir,
+ input_path,
+ symlinks=True,
+ ignore_dangling_symlinks=True,
+ )
file_to_remove = os.path.join(input_path, filepath)
try:
os.remove(file_to_remove)
except IsADirectoryError:
shutil.rmtree(file_to_remove)
subprocess.check_output(
- ["mksquashfs", input_path,
- newsquashfsroot + "/test", "-comp", "xz", '-processors', '1'])
+ [
+ "mksquashfs",
+ input_path,
+ newsquashfsroot + "/test",
+ "-comp",
+ "xz",
+ "-processors",
+ "1",
+ ]
+ )
- return ((filepath.replace(squashfsdir, ""),
- original_size -
- getsize(newsquashfsroot + "/test")))
+ return (
+ filepath.replace(squashfsdir, ""),
+ original_size - getsize(newsquashfsroot + "/test"),
+ )
with tempfile.TemporaryDirectory() as tempsquashfsdir:
print("writing to " + tempsquashfsdir)
squashfsdir = os.path.join(tempsquashfsdir, "squashfs-root")
- #squashfsdir = os.path.join("/tmp", "squashfs-root")
+ # squashfsdir = os.path.join("/tmp", "squashfs-root")
command = ["unsquashfs", "-d", squashfsdir, SQUASHFS]
print(" ".join(command))
subprocess.check_call(command)
@@ -79,20 +102,24 @@
if not os.path.islink(filepath):
if getsize(filepath) > FILE_SIZE_LIMIT:
files_to_test.append(
- os.path.relpath(filepath, squashfsdir))
+ os.path.relpath(filepath, squashfsdir)
+ )
print("{} files to attempt removing".format(len(files_to_test)))
print("Using {} threads".format(args.threads))
with Pool(args.threads) as p:
- for i, res in enumerate(p.imap_unordered(get_unsquash_results, files_to_test)):
+ for i, res in enumerate(
+ p.imap_unordered(get_unsquash_results, files_to_test)
+ ):
results.append(res)
- sys.stderr.write('\rdone {:.1f}%'.format(
- 100 * (i/len(files_to_test))))
+ sys.stderr.write(
+ "\rdone {:.1f}%".format(100 * (i / len(files_to_test)))
+ )
results.sort(key=lambda x: x[1], reverse=True)
-with open("results.txt", 'w') as result_file:
+with open("results.txt", "w") as result_file:
for filepath, size in results:
result = "{:>10}: {}".format(size, filepath)
print(result)