• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2
3import sys
4
5try:
6    import hashlib
7    sha1 = hashlib.sha1
8except ImportError, e:
9    import sha
10    sha1 = sha.sha
11
12def compute_sha1(h, path):
13    f = open(path, 'rb')
14    while True:
15        buf = f.read(1024)
16        h.update(buf)
17        if len(buf) < 1024:
18            break
19    f.close()
20
21def compute_sha1_list(path_list):
22    h = sha1()
23    for path in path_list:
24        compute_sha1(h, path)
25    return h.digest()
26
27def main():
28    if len(sys.argv) < 2:
29        print 'USAGE:', sys.argv[0], '[OUTPUT] [INPUTs]'
30        sys.exit(1)
31
32    f = open(sys.argv[1], 'wb')
33    f.write(compute_sha1_list(sys.argv[2:]))
34    f.close()
35
36if __name__ == '__main__':
37    main()
38