compute-file-chksum.py 840 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python3
  2. import sys,os
  3. import script_init
  4. from mmgen.main import launch
  5. from mmgen.cfg import Config
  6. from mmgen.util import msg,Msg,make_chksum_6
  7. from mmgen.fileutil import get_lines_from_file
  8. opts_data = {
  9. 'text': {
  10. 'desc': 'Compute checksum for a MMGen data file',
  11. 'usage':'[opts] infile',
  12. 'options': """
  13. -h, --help Print this help message.
  14. -i, --include-first-line Include the first line of the file (you probably don't want this)
  15. """
  16. }
  17. }
  18. cfg = Config(opts_data=opts_data)
  19. def main():
  20. lines = get_lines_from_file(cfg, cfg._args[0])
  21. start = (1,0)[bool(cfg.include_first_line)]
  22. a = make_chksum_6(' '.join(lines[start:]).encode())
  23. if start == 1:
  24. b = lines[0]
  25. msg(
  26. 'Checksum in file OK' if a == b else
  27. f"Checksum in file ({b}) doesn't match computed value!")
  28. Msg(a)
  29. launch(func=main)