Mercurial > ec-dotfiles
annotate bin/cek.py @ 727:49538e2aad65 default tip
Add a useful editrc
author | nanaya <me@nanaya.net> |
---|---|
date | Tue, 24 Sep 2024 16:58:15 +0900 |
parents | 137b18a1898e |
children |
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:]: |
681 | 22 print(f'{file} {get_file_crc32(file)}') |