Last active
February 21, 2020 16:07
-
-
Save fovea1959/5b87bf0285013eb2d535ffd9e33337ff to your computer and use it in GitHub Desktop.
Utility to compare two md5sum files and give a view of changed/missing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 | |
| import argparse, logging, sys, os, difflib, traceback | |
| class argparse_logging(argparse.ArgumentParser): | |
| def error(self, message): | |
| logging.error(message) | |
| argparse.ArgumentParser.error(self, message) | |
| def log_uncaught_exceptions(ex_cls, ex, tb): | |
| logging.critical(''.join(traceback.format_tb(tb))) | |
| logging.critical('{0}: {1}'.format(ex_cls, ex)) | |
| def readfile(fn): | |
| with open(fn, 'r') as f: | |
| lines = f.readlines() | |
| rv = [(x, x.split(" ",1)[1]) for x in lines] | |
| rv.sort(key=lambda x: x[1]) | |
| rv = [x[0] for x in rv] | |
| return rv | |
| def main(): | |
| logging.basicConfig (level=logging.INFO, format='%(asctime)s %(levelname)s %(name)s %(message)s') | |
| sys.excepthook = log_uncaught_exceptions | |
| parser = argparse_logging(description='Compare two md5sum files') | |
| parser.add_argument('--verbose', action='count', help='crank up logging') | |
| parser.add_argument('A', help='md5sum file A') | |
| parser.add_argument('B', help='md5sum file A') | |
| args = parser.parse_args() | |
| if args.verbose > 0: | |
| logging.getLogger().setLevel(logging.DEBUG) | |
| a = readfile(args.A) | |
| b = readfile(args.B) | |
| for line in difflib.context_diff(a, b, fromfile=args.A, tofile=args.B): | |
| sys.stdout.write(line) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment