-
Notifications
You must be signed in to change notification settings - Fork 0
/
animecheck
executable file
·58 lines (49 loc) · 1.38 KB
/
animecheck
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
# Version 0.2 2009.01.25
# Copyright (c) 2009, Taoufik El Aoumari
# Released under the GPL license http://www.gnu.org/licenses/gpl-3.0.txt
import sys
import re
import zlib
import os
c_null = "\x1b[00;00m"
c_red = "\x1b[31;01m"
c_green = "\x1b[32;01m"
p_reset = "\x08" * 8
def crc32_checksum(filename):
crc = 0
file = open(filename, "rb")
buff_size = 65536
size = os.path.getsize(filename)
done = 0
try:
while True:
data = file.read(buff_size)
done += buff_size
sys.stdout.write("%7d" % (done * 100 / size) + "%" + p_reset)
if not data:
break
crc = zlib.crc32(data, crc)
except KeyboardInterrupt:
sys.stdout.write(p_reset)
file.close()
sys.exit(1)
sys.stdout.write(p_reset)
file.close()
if crc < 0:
crc &= 2**32 - 1
return "%.8X" % (crc)
for file in sys.argv[1:]:
try:
crc = crc32_checksum(file)
dest_sum = re.split("([a-fA-F0-9]{8})", file)[-2]
if crc == dest_sum.upper():
c_in = c_green
else:
c_in = c_red
sfile = file.split(dest_sum)
print("%s%s%s %s%s%s%s%s" % (c_in, crc, c_null, sfile[0], c_in, dest_sum, c_null, sfile[1]))
except(IndexError, ValueError):
print(crc, " ", file)
except (IOError):
continue