Changeset View
Changeset View
Standalone View
Standalone View
src/test/data/generate_asmap.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2020 The Bitcoin developers | # Copyright (c) 2020 The Bitcoin developers | ||||
import sys | import sys | ||||
from pathlib import Path | from pathlib import Path | ||||
def main(input_file, output_file): | def main(input_file, output_file): | ||||
with open(input_file, 'rb') as f: | with open(input_file, "rb") as f: | ||||
contents = f.read() | contents = f.read() | ||||
with open(output_file, "w", encoding="utf-8") as f: | with open(output_file, "w", encoding="utf-8") as f: | ||||
f.write( | f.write(f"static unsigned const char {Path(input_file).stem}_raw[] = {{\n") | ||||
f"static unsigned const char {Path(input_file).stem}_raw[] = {{\n") | |||||
f.write(", ".join(f"0x{x:02x}" for x in contents)) | f.write(", ".join(f"0x{x:02x}" for x in contents)) | ||||
f.write("\n};\n") | f.write("\n};\n") | ||||
if __name__ == "__main__": | if __name__ == "__main__": | ||||
if len(sys.argv) != 3: | if len(sys.argv) != 3: | ||||
print("Invalid parameters\nUsage: {} input_file output_file".format( | print( | ||||
Path(sys.argv[0]).name)) | "Invalid parameters\nUsage: {} input_file output_file".format( | ||||
Path(sys.argv[0]).name | |||||
) | |||||
) | |||||
sys.exit(1) | sys.exit(1) | ||||
main(sys.argv[1], sys.argv[2]) | main(sys.argv[1], sys.argv[2]) |