Skip to content

Instantly share code, notes, and snippets.

@yasamoka
Created April 13, 2023 22:46
Show Gist options
  • Save yasamoka/a710e4eea5c3b8f7fa9e2e95adcd0465 to your computer and use it in GitHub Desktop.
Save yasamoka/a710e4eea5c3b8f7fa9e2e95adcd0465 to your computer and use it in GitHub Desktop.
Compare outputs of md5sum command on multiple files
from argparse import ArgumentParser
from pathlib import Path
from typing import cast
parser = ArgumentParser(
description="Compares outputs of md5sum command on multiple files"
)
parser.add_argument("-i1", type=Path, required=True, help="First input filepath")
parser.add_argument("-i2", type=Path, required=True, help="Second input filepath")
args = parser.parse_args()
first_input_filepath: Path = args.i1
second_input_filepath: Path = args.i2
def parse_input(input_filepath: Path) -> dict[str, str]:
with open(input_filepath) as input_file:
lines = input_file.readlines()
lines = [line.split(" ") for line in lines]
lines = cast(list[tuple[str, str]], lines)
return {
md5_hex: filename
for md5_hex, filename in lines
}
first_md5_filename_map = parse_input(first_input_filepath)
second_md5_filename_map = parse_input(second_input_filepath)
print(first_md5_filename_map == second_md5_filename_map)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment