compute-file-chksum.py 752 B

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