Home | History | Annotate | Download | only in tools
      1 #!/usr/bin/env python
      2 
      3 import sys
      4 
      5 try:
      6     import hashlib
      7     sha1 = hashlib.sha1
      8 except ImportError, e:
      9     import sha
     10     sha1 = sha.sha
     11 
     12 def 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 
     21 def compute_sha1_list(path_list):
     22     h = sha1()
     23     for path in path_list:
     24         compute_sha1(h, path)
     25     return h.digest()
     26 
     27 def 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 
     36 if __name__ == '__main__':
     37     main()
     38