1
0

sercomm-partition-tag.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env python3
  2. import argparse
  3. import os
  4. import struct
  5. def create_header(args, size):
  6. header = struct.pack('32s32s32s32s32s',
  7. args.part_name.encode('ascii'),
  8. str(size).encode('ascii'),
  9. args.part_version.encode('ascii'),
  10. "".encode('ascii'),
  11. args.rootfs_version.encode('ascii'))
  12. return header
  13. def create_output(args):
  14. in_st = os.stat(args.input_file)
  15. in_size = in_st.st_size
  16. header = create_header(args, in_size)
  17. print(header)
  18. in_f = open(args.input_file, 'r+b')
  19. in_bytes = in_f.read(in_size)
  20. in_f.close()
  21. out_f = open(args.output_file, 'w+b')
  22. out_f.write(header)
  23. out_f.write(in_bytes)
  24. out_f.close()
  25. def main():
  26. global args
  27. parser = argparse.ArgumentParser(description='')
  28. parser.add_argument('--input-file',
  29. dest='input_file',
  30. action='store',
  31. type=str,
  32. help='Input file')
  33. parser.add_argument('--output-file',
  34. dest='output_file',
  35. action='store',
  36. type=str,
  37. help='Output file')
  38. parser.add_argument('--part-name',
  39. dest='part_name',
  40. action='store',
  41. type=str,
  42. help='Partition Name')
  43. parser.add_argument('--part-version',
  44. dest='part_version',
  45. action='store',
  46. type=str,
  47. help='Partition Version')
  48. parser.add_argument('--rootfs-version',
  49. dest='rootfs_version',
  50. action='store',
  51. type=str,
  52. help='RootFS lib version')
  53. args = parser.parse_args()
  54. if not args.rootfs_version:
  55. args.rootfs_version = ""
  56. if ((not args.input_file) or
  57. (not args.output_file) or
  58. (not args.part_name) or
  59. (not args.part_version)):
  60. parser.print_help()
  61. create_output(args)
  62. main()