annotate bin/cek.py @ 245:f74212d79fcb

Ensures we're running tcsh.
author Edho Arief <edho@myconan.net>
date Mon, 07 Nov 2011 12:30:06 +0700
parents 08d5f6023998
children 137b18a1898e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
79
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
1 #!/usr/bin/env python
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
2
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
3 import zlib, os, sys
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
4
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
5 def get_file_crc32(filename):
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
6 block_size = 1*2**20
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
7 return_code = 0
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
8 file_crc32 = 0
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
9 file_digest = 0
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
10 file_handle = open(filename, "rb")
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
11 if return_code == 0:
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
12 file_block = file_handle.read(block_size)
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
13 while file_block:
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
14 file_digest = zlib.crc32(file_block, file_digest)
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
15 file_block = file_handle.read(block_size)
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
16 file_handle.close()
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
17 file_digest = file_digest & 0xffffffff
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
18 return "%08X" % file_digest
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
19
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
20 if __name__ == "__main__":
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
21 for file in sys.argv[1:]:
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
22 print "%s %s" % (file, get_file_crc32(file))