|
2 | 2 | """ |
3 | 3 | Created on Tue Jun 23 21:30:06 2015 |
4 | 4 |
|
| 5 | +@author: famille |
5 | 6 | """ |
6 | 7 |
|
7 | 8 | import io |
|
12 | 13 |
|
13 | 14 | def give_hash(file_in, with_this): |
14 | 15 | with io.open(file_in, 'rb') as f: |
15 | | - return with_this(f.read()).hexdigest() |
| 16 | + return with_this(f.read()).hexdigest() |
16 | 17 |
|
17 | 18 |
|
18 | 19 | if __name__ == '__main__': |
19 | | - if (len(sys.argv) < 2): |
20 | | - print ("Usage: " + sys.argv[0] + " filename_to_hash") |
21 | | - exit(1) |
22 | | - file = sys.argv[1] |
23 | | - |
24 | | - header = (" MD5"+" "*(32-4)+" | SHA-1"+" "*(40-5)+" | SHA-256"+ |
25 | | - " "*(64-7)+" | Binary"+" "*(31-5)+"| Size"+" "*(20-6)) |
26 | | - line = "|".join(["-"*len(i) for i in header.split("|")]) |
27 | | - |
28 | | - print(header) |
29 | | - print(line) |
30 | | - print ("%s | %s | %s | %s | %s" % (give_hash(file, hashlib.md5), |
31 | | - give_hash(file, hashlib.sha1), |
32 | | - give_hash(file, hashlib.sha256), |
33 | | - '{0:31s}'.format(os.path.basename(file)), |
34 | | - ('{0:12,}'.format(os.path.getsize(file)).replace(","," ")+ ' Bytes') |
35 | | - )) |
| 20 | + if len(sys.argv) < 2: |
| 21 | + print( |
| 22 | + "Usage: " |
| 23 | + + sys.argv[0] |
| 24 | + + " github-user [github-project]" |
| 25 | + ) |
| 26 | + exit(1) |
| 27 | + file = sys.argv[1] |
| 28 | + |
| 29 | + header = ( |
| 30 | + " MD5" |
| 31 | + + " " * (32 - 4) |
| 32 | + + " | SHA-1" |
| 33 | + + " " * (40 - 5) |
| 34 | + + " | SHA-256" |
| 35 | + + " " * (64 - 7) |
| 36 | + + " | Binary" |
| 37 | + + " " * (31 - 5) |
| 38 | + + "| Size" |
| 39 | + + " " * (20 - 6) |
| 40 | + ) |
| 41 | + line = "|".join( |
| 42 | + ["-" * len(i) for i in header.split("|")] |
| 43 | + ) |
| 44 | + |
| 45 | + print(header) |
| 46 | + print(line) |
| 47 | + print( |
| 48 | + "%s | %s | %s | %s | %s" |
| 49 | + % ( |
| 50 | + give_hash(file, hashlib.md5), |
| 51 | + give_hash(file, hashlib.sha1), |
| 52 | + give_hash(file, hashlib.sha256), |
| 53 | + '{0:31s}'.format(os.path.basename(file)), |
| 54 | + ( |
| 55 | + '{0:12,}'.format( |
| 56 | + os.path.getsize(file) |
| 57 | + ).replace(",", " ") |
| 58 | + + ' Bytes' |
| 59 | + ), |
| 60 | + ) |
| 61 | + ) |
0 commit comments