diff --git a/bin/swh-hash-file b/bin/swh-hash-file new file mode 100755 index 0000000000000000000000000000000000000000..7ad22a8d0f7e8b8500977be4de2940ddc1cd5308 --- /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)