Skip to content

Commit d05e558

Browse files
committed
have hash.py tuned per 'black' formatter
a first experiment at black
1 parent 2b919bd commit d05e558

File tree

1 file changed

+44
-18
lines changed

1 file changed

+44
-18
lines changed

hash.py

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33
Created on Tue Jun 23 21:30:06 2015
44
5+
@author: famille
56
"""
67

78
import io
@@ -12,24 +13,49 @@
1213

1314
def give_hash(file_in, with_this):
1415
with io.open(file_in, 'rb') as f:
15-
return with_this(f.read()).hexdigest()
16+
return with_this(f.read()).hexdigest()
1617

1718

1819
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

Comments
 (0)