compute-file-chksum.py 737 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env python
  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:]))
  18. if start == 1:
  19. b = lines[0]
  20. m = ("Checksum in file (%s) doesn't match computed value!" % b,'Checksum in file OK')[a==b]
  21. msg(m)
  22. Msg(a)