File indexing completed on 2025-01-18 10:17:58
0001 import os
0002 import sys
0003
0004
0005
0006
0007
0008
0009 if len(sys.argv) != 3:
0010 sys.exit("Invalid arguments: usage: python libsize.py file.so save.txt")
0011
0012 lib = sys.argv[1]
0013 save = sys.argv[2]
0014
0015 if not os.path.exists(lib):
0016 sys.exit(f"Error: requested file ({lib}) does not exist")
0017
0018 libsize = os.path.getsize(lib)
0019
0020 print("------", os.path.basename(lib), "file size:", libsize, end="")
0021
0022 if os.path.exists(save):
0023 with open(save) as sf:
0024 oldsize = int(sf.readline())
0025
0026 if oldsize > 0:
0027 change = libsize - oldsize
0028 if change == 0:
0029 print(" (no change)")
0030 else:
0031 print(f" (change of {change:+} bytes = {change / oldsize:+.2%})")
0032 else:
0033 print()
0034
0035 with open(save, "w") as sf:
0036 sf.write(str(libsize))