compute-file-chksum.py 802 B

1234567891011121314151617181920212223242526272829
  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.common import *
  6. opts_data = {
  7. 'text': {
  8. 'desc': 'Compute checksum for a MMGen data file',
  9. 'usage':'[opts] infile',
  10. 'options': """
  11. -h, --help Print this help message.
  12. -i, --include-first-line Include the first line of the file (you probably don't want this)
  13. """
  14. }
  15. }
  16. cmd_args = opts.init(opts_data)
  17. from mmgen.fileutil import get_lines_from_file
  18. lines = get_lines_from_file(cmd_args[0])
  19. start = (1,0)[bool(opt.include_first_line)]
  20. a = make_chksum_6(' '.join(lines[start:]).encode())
  21. if start == 1:
  22. b = lines[0]
  23. msg(("Checksum in file ({}) doesn't match computed value!".format(b),'Checksum in file OK')[a==b])
  24. Msg(a)