summaryrefslogtreecommitdiffstats
path: root/scripts/cfe-wfi-tag.py
diff options
context:
space:
mode:
authorDoug Kerr <dek3rr@gmail.com>2022-04-15 15:54:30 -0400
committerHauke Mehrtens <hauke@hauke-m.de>2022-04-16 14:53:17 +0200
commit6f692c9c497e5e60eb51da741b07ef1c10096355 (patch)
tree985be802ae7f7c6453ff55e9e431c039b6dfcd36 /scripts/cfe-wfi-tag.py
parent0642a2166b9526ec01fe47b6aed1fd57a29e35f9 (diff)
downloadopenwrt-6f692c9c497e5e60eb51da741b07ef1c10096355.tar.gz
openwrt-6f692c9c497e5e60eb51da741b07ef1c10096355.tar.bz2
openwrt-6f692c9c497e5e60eb51da741b07ef1c10096355.zip
scripts: format to black
clean up formatting with black using 80 character line limit Signed-off-by: Doug Kerr <dek3rr@gmail.com>
Diffstat (limited to 'scripts/cfe-wfi-tag.py')
-rwxr-xr-xscripts/cfe-wfi-tag.py155
1 files changed, 88 insertions, 67 deletions
diff --git a/scripts/cfe-wfi-tag.py b/scripts/cfe-wfi-tag.py
index c98301d91a..5fac8ee475 100755
--- a/scripts/cfe-wfi-tag.py
+++ b/scripts/cfe-wfi-tag.py
@@ -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()