compute-file-chksum.py 630 B

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