Created
April 13, 2023 22:46
-
-
Save yasamoka/a710e4eea5c3b8f7fa9e2e95adcd0465 to your computer and use it in GitHub Desktop.
Compare outputs of md5sum command on multiple files
This file contains 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
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