From 73d5ffb2f37f14f0977d809f09765fa3acbefc35 Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli <zack@upsilon.cc> Date: Sun, 14 Jan 2018 14:40:18 +0100 Subject: [PATCH] bin/swh-hash-file: new binary to compute SWH-style content identifiers reincarnation of the old shw.model bin/ script, which is now gone --- bin/swh-hash-file | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 bin/swh-hash-file diff --git a/bin/swh-hash-file b/bin/swh-hash-file new file mode 100755 index 00000000..7ad22a8d --- /dev/null +++ b/bin/swh-hash-file @@ -0,0 +1,32 @@ +#!/usr/bin/python3 + +# Copyright (C) 2018 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + +import sys + +from swh.model.from_disk import Content +from swh.model.hashutil import hash_to_hex + + +HASH_ALGO = 'sha1_git' + + +def hash_file(fname): + return hash_to_hex(Content.from_file(path=fname).hash) + + +def main(fnames): + for f in fnames: + print(f, hash_file(f), sep='\t') + + +if __name__ == '__main__': + fnames = sys.argv[1:] + if not fnames: + print('Usage: swh-hash-file FILE...') + sys.exit(2) + + main(fnames) -- GitLab