Mercurial > ec-dotfiles
annotate bin/cek.py @ 549:fe33aeb572f6
Update name (part 2).
author | nanaya <me@myconan.net> |
---|---|
date | Tue, 14 Apr 2015 04:46:28 +0900 |
parents | 08d5f6023998 |
children | 137b18a1898e |
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)) |