diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/cek.py	Sat Jul 09 15:33:37 2011 +0700
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+import zlib, os, sys
+
+def get_file_crc32(filename):
+  block_size = 1*2**20
+  return_code = 0
+  file_crc32 = 0
+  file_digest = 0
+  file_handle = open(filename, "rb")
+  if return_code == 0:
+    file_block = file_handle.read(block_size)
+    while file_block:
+      file_digest = zlib.crc32(file_block, file_digest)
+      file_block = file_handle.read(block_size)
+    file_handle.close()
+    file_digest = file_digest & 0xffffffff
+  return "%08X" % file_digest
+
+if __name__ == "__main__":
+  for file in sys.argv[1:]:
+    print "%s %s" % (file, get_file_crc32(file))