compute-file-chksum.py 863 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python3
  2. import sys,os
  3. repo_root = os.path.split(os.path.abspath(os.path.dirname(sys.argv[0])))[0]
  4. sys.path = [repo_root] + sys.path
  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. lines = get_lines_from_file( cfg, cfg._args[0] )
  20. start = (1,0)[bool(cfg.include_first_line)]
  21. a = make_chksum_6(' '.join(lines[start:]).encode())
  22. if start == 1:
  23. b = lines[0]
  24. msg(
  25. 'Checksum in file OK' if a == b else
  26. f"Checksum in file ({b}) doesn't match computed value!")
  27. Msg(a)