File: mergeall-android11-updates-media/MORE--logs-and-code/iospeed.py
#!/usr/bin/python3
"""
================================================================================
Run with 'python iospeed.py path?' in Termux or Pydroid 3. Give the path of the
tree to walk in either the TREE setting below or a sole command-line argument.
This script does what Mergeall compare-only ('-report') runs do, but Mergeall
generally walks two tree copies in parallel; filters out system-metadata files
(e.g., .DS_Store); and compares files by timestamps and sizes in the fetched
stat info. Mergeall likely calls C's readlink() per dir and lstat() per file.
================================================================================
"""
import sys, os, stat, time
trace = lambda *ka, **pa: None # or print
TREE = '/sdcard/MY-STUFF' # EDIT ME: default path of folder to walk
SKIP = '__bkp__' # mergeall backups folder (else moot)
if len(sys.argv) > 1:
TREE = sys.argv[1] # command-line arg? explicit folder path
class Counts:
files = links = dirs = other = 0
def comparetree(dirpath):
trace('...', dirpath, flush=True)
nameshere = os.listdir(dirpath) # <= C libr IO call (dir)
if SKIP in nameshere:
nameshere.remove(SKIP)
for namehere in nameshere:
pathhere = dirpath + os.sep + namehere
stathere = os.lstat(pathhere) # <= C lib IO call (file)
if stat.S_ISLNK(stathere.st_mode):
Counts.links += 1
linkpath = os.readlink(pathhere) # <= C lib IO call (link)
elif stat.S_ISREG(stathere.st_mode):
Counts.files += 1
pass # mergeall compares stat info here
elif stat.S_ISDIR(stathere.st_mode):
Counts.dirs += 1
comparetree(pathhere)
else:
Counts.other += 1
print('Walking', TREE, '...')
start = time.perf_counter()
comparetree(TREE)
stop = time.perf_counter()
elapsed = stop - start
print('Runtime: {:,.3f} seconds'.format(elapsed))
print('Counts:', {key: val for (key, val) in Counts.__dict__.items() if key[0] != '_'})