scripts: format to black
authorDoug Kerr <dek3rr@gmail.com>
Fri, 15 Apr 2022 19:54:30 +0000 (15:54 -0400)
committerHauke Mehrtens <hauke@hauke-m.de>
Sat, 16 Apr 2022 12:53:17 +0000 (14:53 +0200)
clean up formatting with black using 80 character line limit

Signed-off-by: Doug Kerr <dek3rr@gmail.com>
scripts/cfe-partition-tag.py
scripts/cfe-wfi-tag.py

index 875bfae85d5349a621c1613ee6d6567207b3b1e2..41495a9af0524f95b16a386be16911c07e4534bb 100755 (executable)
@@ -25,96 +25,115 @@ PART_VERSION_SIZE = 21
 
 
 def auto_int(x):
-       return int(x, 0)
+    return int(x, 0)
+
 
 def str_to_bytes_pad(string, size):
-       str_bytes = string.encode()
-       num_bytes = len(str_bytes)
-       if (num_bytes >= size):
-               str_bytes = str_bytes[:size - 1] + '\0'.encode()
-       else:
-               str_bytes += '\0'.encode() * (size - num_bytes)
-       return str_bytes
+    str_bytes = string.encode()
+    num_bytes = len(str_bytes)
+    if num_bytes >= size:
+        str_bytes = str_bytes[: size - 1] + "\0".encode()
+    else:
+        str_bytes += "\0".encode() * (size - num_bytes)
+    return str_bytes
+
 
 def create_tag(args, in_bytes, size):
     # JAM CRC32 is bitwise not and unsigned
-    crc = (~binascii.crc32(in_bytes) & 0xFFFFFFFF)
+    crc = ~binascii.crc32(in_bytes) & 0xFFFFFFFF
+
+    tag = bytearray()
+    tag += struct.pack(">I", args.part_id)
+    tag += struct.pack(">I", size)
+    tag += struct.pack(">H", args.part_flags)
+    tag += str_to_bytes_pad(args.part_name, PART_NAME_SIZE)
+    tag += str_to_bytes_pad(args.part_version, PART_VERSION_SIZE)
+    tag += struct.pack(">I", crc)
 
-       tag = bytearray()
-       tag += struct.pack('>I', args.part_id)
-       tag += struct.pack('>I', size)
-       tag += struct.pack('>H', args.part_flags)
-       tag += str_to_bytes_pad(args.part_name, PART_NAME_SIZE)
-       tag += str_to_bytes_pad(args.part_version, PART_VERSION_SIZE)
-       tag += struct.pack('>I', crc)
+    return tag
 
-       return tag
 
 def create_output(args):
-       in_st = os.stat(args.input_file)
-       in_size = in_st.st_size
+    in_st = os.stat(args.input_file)
+    in_size = in_st.st_size
 
-       in_f = open(args.input_file, 'r+b')
-       in_bytes = in_f.read(in_size)
-       in_f.close()
+    in_f = open(args.input_file, "r+b")
+    in_bytes = in_f.read(in_size)
+    in_f.close()
 
-       tag = create_tag(args, in_bytes, in_size)
+    tag = create_tag(args, in_bytes, in_size)
+
+    out_f = open(args.output_file, "w+b")
+    out_f.write(tag)
+    out_f.close()
 
-       out_f = open(args.output_file, 'w+b')
-       out_f.write(tag)
-       out_f.close()
 
 def main():
-       global args
-
-       parser = argparse.ArgumentParser(description='')
-
-       parser.add_argument('--flags',
-               dest='part_flags',
-               action='store',
-               type=auto_int,
-               help='Partition Flags')
-
-       parser.add_argument('--id',
-               dest='part_id',
-               action='store',
-               type=auto_int,
-               help='Partition ID')
-
-       parser.add_argument('--input-file',
-               dest='input_file',
-               action='store',
-               type=str,
-               help='Input file')
-
-       parser.add_argument('--output-file',
-               dest='output_file',
-               action='store',
-               type=str,
-               help='Output file')
-
-       parser.add_argument('--name',
-               dest='part_name',
-               action='store',
-               type=str,
-               help='Partition Name')
-
-       parser.add_argument('--version',
-               dest='part_version',
-               action='store',
-               type=str,
-               help='Partition Version')
-
-       args = parser.parse_args()
-
-       if ((not args.part_flags) or
-           (not args.part_id) or
-           (not args.input_file) or
-           (not args.output_file) or
-           (not args.part_name) or
-           (not args.part_version)):
-               parser.print_help()
-       else:
-               create_output(args)
+    global args
+
+    parser = argparse.ArgumentParser(description="")
+
+    parser.add_argument(
+        "--flags",
+        dest="part_flags",
+        action="store",
+        type=auto_int,
+        help="Partition Flags",
+    )
+
+    parser.add_argument(
+        "--id",
+        dest="part_id",
+        action="store",
+        type=auto_int,
+        help="Partition ID",
+    )
+
+    parser.add_argument(
+        "--input-file",
+        dest="input_file",
+        action="store",
+        type=str,
+        help="Input file",
+    )
+
+    parser.add_argument(
+        "--output-file",
+        dest="output_file",
+        action="store",
+        type=str,
+        help="Output file",
+    )
+
+    parser.add_argument(
+        "--name",
+        dest="part_name",
+        action="store",
+        type=str,
+        help="Partition Name",
+    )
+
+    parser.add_argument(
+        "--version",
+        dest="part_version",
+        action="store",
+        type=str,
+        help="Partition Version",
+    )
+
+    args = parser.parse_args()
+
+    if (
+        (not args.part_flags)
+        or (not args.part_id)
+        or (not args.input_file)
+        or (not args.output_file)
+        or (not args.part_name)
+        or (not args.part_version)
+    ):
+        parser.print_help()
+    else:
+        create_output(args)
+
 
 main()
index c98301d91ad3376c14cac1b5254caf51a5ac2873..5fac8ee4751974821bff4d4ea327d6a120c741d6 100755 (executable)
@@ -47,82 +47,103 @@ import binascii
 
 
 def auto_int(x):
-       return int(x, 0)
+    return int(x, 0)
+
 
 def create_tag(args, in_bytes):
     # JAM CRC32 is bitwise not and unsigned
-    crc = (~binascii.crc32(in_bytes) & 0xFFFFFFFF)
-       tag = struct.pack('>IIIII', crc, args.tag_version, args.chip_id, args.flash_type, args.flags)
-       return tag
+    crc = ~binascii.crc32(in_bytes) & 0xFFFFFFFF
+    tag = struct.pack(
+        ">IIIII",
+        crc,
+        args.tag_version,
+        args.chip_id,
+        args.flash_type,
+        args.flags,
+    )
+    return tag
+
 
 def create_output(args):
-       in_st = os.stat(args.input_file)
-       in_size = in_st.st_size
+    in_st = os.stat(args.input_file)
+    in_size = in_st.st_size
 
-       in_f = open(args.input_file, 'r+b')
-       in_bytes = in_f.read(in_size)
-       in_f.close()
+    in_f = open(args.input_file, "r+b")
+    in_bytes = in_f.read(in_size)
+    in_f.close()
 
-       tag = create_tag(args, in_bytes)
+    tag = create_tag(args, in_bytes)
+
+    out_f = open(args.output_file, "w+b")
+    out_f.write(in_bytes)
+    out_f.write(tag)
+    out_f.close()
 
-       out_f = open(args.output_file, 'w+b')
-       out_f.write(in_bytes)
-       out_f.write(tag)
-       out_f.close()
 
 def main():
-       global args
-
-       parser = argparse.ArgumentParser(description='')
-
-       parser.add_argument('--input-file',
-               dest='input_file',
-               action='store',
-               type=str,
-               help='Input file')
-
-       parser.add_argument('--output-file',
-               dest='output_file',
-               action='store',
-               type=str,
-               help='Output file')
-
-       parser.add_argument('--version',
-               dest='tag_version',
-               action='store',
-               type=auto_int,
-               help='WFI Tag Version')
-
-       parser.add_argument('--chip-id',
-               dest='chip_id',
-               action='store',
-               type=auto_int,
-               help='WFI Chip ID')
-
-       parser.add_argument('--flash-type',
-               dest='flash_type',
-               action='store',
-               type=auto_int,
-               help='WFI Flash Type')
-
-       parser.add_argument('--flags',
-               dest='flags',
-               action='store',
-               type=auto_int,
-               help='WFI Flags')
-
-       args = parser.parse_args()
-
-       if not args.flags:
-               args.flags = 0
-
-       if ((not args.input_file) or
-           (not args.output_file) or
-           (not args.tag_version) or
-           (not args.chip_id) or
-           (not args.flash_type)):
-               parser.print_help()
-       else:
-               create_output(args)
+    global args
+
+    parser = argparse.ArgumentParser(description="")
+
+    parser.add_argument(
+        "--input-file",
+        dest="input_file",
+        action="store",
+        type=str,
+        help="Input file",
+    )
+
+    parser.add_argument(
+        "--output-file",
+        dest="output_file",
+        action="store",
+        type=str,
+        help="Output file",
+    )
+
+    parser.add_argument(
+        "--version",
+        dest="tag_version",
+        action="store",
+        type=auto_int,
+        help="WFI Tag Version",
+    )
+
+    parser.add_argument(
+        "--chip-id",
+        dest="chip_id",
+        action="store",
+        type=auto_int,
+        help="WFI Chip ID",
+    )
+
+    parser.add_argument(
+        "--flash-type",
+        dest="flash_type",
+        action="store",
+        type=auto_int,
+        help="WFI Flash Type",
+    )
+
+    parser.add_argument(
+        "--flags", dest="flags", action="store", type=auto_int, help="WFI Flags"
+    )
+
+    args = parser.parse_args()
+
+    if not args.flags:
+        args.flags = 0
+
+    if (
+        (not args.input_file)
+        or (not args.output_file)
+        or (not args.tag_version)
+        or (not args.chip_id)
+        or (not args.flash_type)
+    ):
+        parser.print_help()
+    else:
+        create_output(args)
+
 
 main()