compute-file-chksum.py 755 B

12345678910111213141516171819202122232425262728
  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. lines = get_lines_from_file(cmd_args[0])
  18. start = (1,0)[bool(opt.include_first_line)]
  19. a = make_chksum_6(' '.join(lines[start:]).encode())
  20. if start == 1:
  21. b = lines[0]
  22. msg(("Checksum in file ({}) doesn't match computed value!".format(b),'Checksum in file OK')[a==b])
  23. Msg(a)