def make_sha256sums_file(dir_path): shasums_file = SHA256SUMS_FILENAME # Don't include SHA256SUMS because its hash will necessarily be incorrect # after SHA256SUMS is updated. exclude_paths = [shasums_file] contents = utils.directory_sha256sum(dir_path, exclude_paths=exclude_paths) sha256sums_path = dir_path / shasums_file sha256sums_path.write_text(contents)
def main(): logging.basicConfig(level=logging.INFO) try: dir_path = sys.argv[1] except IndexError: raise RuntimeError('path not provided') text = utils.directory_sha256sum(dir_path) print(text)
def test_directory_sha256sum(self): file_infos = [ ('a.txt', 'aaa'), ('b.txt', 'bbb'), ('c.txt', 'ccc'), ('SHA256SUMS', 'xxx'), ] exclude_paths = ['a.txt', 'c.txt'] expected = dedent("""\ cd2eb0837c9b4c962c22d2ff8b5441b7b45805887f051d39bf133b583baf6860 *SHA256SUMS 3e744b9dc39389baf0c5a0660589b8402f3dbb49b89b3e75f2c9355852a3c677 *b.txt """) with TemporaryDirectory() as temp_dir: for rel_path, text in file_infos: path = Path(temp_dir) / rel_path path.write_text(text) actual = utils.directory_sha256sum(temp_dir, exclude_paths=exclude_paths) self.assertEqual(actual, expected)