compute-file-chksum.py 612 B

1234567891011121314151617181920212223
  1. #!/usr/bin/env python
  2. from mmgen.common import *
  3. opts_data = {
  4. 'desc': 'Compute checksum for a MMGen data file',
  5. 'usage':'[opts] infile',
  6. 'options': """
  7. -h, --help Print this help message.
  8. -i, --include-first-line Include the first line of the file (you probably don't want this)
  9. """.strip()
  10. }
  11. cmd_args = opts.init(opts_data)
  12. lines = get_lines_from_file(cmd_args[0])
  13. start = (1,0)[bool(opt.include_first_line)]
  14. a = make_chksum_6(' '.join(lines[start:]))
  15. if start == 1:
  16. b = lines[0]
  17. m = ("Checksum in file (%s) doesn't match computed value!" % b,'Checksum in file OK')[a==b]
  18. msg(m)
  19. Msg(a)