summaryrefslogtreecommitdiff
path: root/update/adler32
diff options
context:
space:
mode:
authorjak1 <jak1@themanaworld.org>2022-06-18 21:37:28 +0200
committerjak1 <jak1@themanaworld.org>2022-06-18 21:37:28 +0200
commitb3cd9a5dd68c8a973795931149a254563bda2865 (patch)
tree2110f496a061997fbf120f6ac7e82ff28f7b556e /update/adler32
parent6c2ad98dfd4a2d6e39423c5b4f1e7828fd79566a (diff)
downloadtools-b3cd9a5dd68c8a973795931149a254563bda2865.tar.gz
tools-b3cd9a5dd68c8a973795931149a254563bda2865.tar.bz2
tools-b3cd9a5dd68c8a973795931149a254563bda2865.tar.xz
tools-b3cd9a5dd68c8a973795931149a254563bda2865.zip
ported adler32 to py3, updated bash update scripts
Diffstat (limited to 'update/adler32')
-rwxr-xr-xupdate/adler3249
1 files changed, 49 insertions, 0 deletions
diff --git a/update/adler32 b/update/adler32
new file mode 100755
index 0000000..187e34d
--- /dev/null
+++ b/update/adler32
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+
+"""
+ Project: TheManaWorld
+ Author: Bjorn Lindeijer, jak1
+ License: GPLv3
+ Description: Calculates adler32 checksums for all files passed as argument.
+ Credits: adler32.c 2006 Bjorn Lindeijer
+"""
+
+from zlib import adler32
+import sys
+import os
+
+def adler32sum(filepath):
+ BLOCKSIZE = 256*1024*1024
+ asum = 1
+ with open(filepath, 'rb') as f:
+ while (data := f.read(BLOCKSIZE)):
+ asum = adler32(data, asum)
+ return hex(asum)
+
+def cmd_help():
+ print(f"Usage: adler32.py <mode> <file>")
+ print(f" mode: 0 prints file & checksum")
+ print(f" mode: 1 prints only checksum")
+
+if __name__ == "__main__":
+ if len(sys.argv) >= 3:
+ try:
+ mode = int(sys.argv[1])
+ zfiles = sys.argv[2:]
+ for zfile in zfiles:
+ file_exists = os.path.exists(zfile)
+ if file_exists:
+ if mode == 0:
+ print(zfile + " " + adler32sum(zfile)[2:])
+ elif mode == 1:
+ print(adler32sum(zfile)[2:])
+ else:
+ cmd_help()
+ else:
+ print("file not found!")
+ exit(-1)
+ except ValueError:
+ print("mode needs to be an integer value!")
+ exit(-1)
+ else:
+ cmd_help()