Mercurial > ec-dotfiles
comparison bin/cek.py @ 79:08d5f6023998
Replace checksum calculator with python version.
author | Edho Prima Arief <me@myconan.net> |
---|---|
date | Sat, 09 Jul 2011 15:33:37 +0700 |
parents | |
children | 137b18a1898e |
comparison
equal
deleted
inserted
replaced
78:06fd72a78cc1 | 79:08d5f6023998 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import zlib, os, sys | |
4 | |
5 def get_file_crc32(filename): | |
6 block_size = 1*2**20 | |
7 return_code = 0 | |
8 file_crc32 = 0 | |
9 file_digest = 0 | |
10 file_handle = open(filename, "rb") | |
11 if return_code == 0: | |
12 file_block = file_handle.read(block_size) | |
13 while file_block: | |
14 file_digest = zlib.crc32(file_block, file_digest) | |
15 file_block = file_handle.read(block_size) | |
16 file_handle.close() | |
17 file_digest = file_digest & 0xffffffff | |
18 return "%08X" % file_digest | |
19 | |
20 if __name__ == "__main__": | |
21 for file in sys.argv[1:]: | |
22 print "%s %s" % (file, get_file_crc32(file)) |