4cade/bin/addfile.py

28 lines
816 B
Python
Executable File

#!/usr/bin/env python3
# parameters
# 1 - input file
# 2 - output filename for data file
# stdout - source code of index record
import argparse
import os.path
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Append file to TOTAL.DATA and calculate its index record")
parser.add_argument("input_file")
parser.add_argument("output_file")
args = parser.parse_args()
offset = os.path.getsize(args.output_file)
size = os.path.getsize(args.input_file)
with open(args.input_file, 'rb') as input_handle, open(args.output_file, 'ab') as output_handle:
output_handle.write(input_handle.read())
print(f""";
; Index record for {args.input_file}
;
; This file is automatically generated
;
!byte 0
!be24 {offset:>9}
!le16 {size:>8}""")