Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
bin2values.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: UTF-8 -*-
3 
4 # Copyright (C)2015,2016,2018 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
5 
6 from sys import argv, stderr, stdout, exit
7 from textwrap import wrap
8 
9 if __name__ == "__main__":
10  if len(argv) != 3:
11  stderr.write("Bad usage.\n")
12  exit(1)
13  try:
14  with open(argv[1], "rb") as bb:
15  bb = bytearray(bb.read())
16  except IOError as a:
17  stderr.write("File open/read error: " + str(a) + "\n")
18  exit(1)
19  bb = "\n".join(wrap(", ".join(map("0x{:02X}".format, bb)))) + "\n"
20  try:
21  if argv[2] == "-":
22  stdout.write(bb)
23  else:
24  with open(argv[2], "w") as f:
25  f.write(bb)
26  except IOError as a:
27  stderr.write("File create/write error: " + str(a) + "\n")
28  exit(1)
29  exit(0)