#! /usr/bin/python3 #! /cygwin/c/apps/python3.3/python # Omits time values and footnote string from printout, for legitimate comparison DEBUG = False import os import sys import time import shutil from pprint import pprint, pformat import gzip import pdb import platform import inspect #Globals currOS = platform.platform() if currOS.find('Windows') == 0: WEBROOT = 'C:/website' OLDWEB = 'C:/website_old' ERRFILE = 'C:/website/mpErr.txt' else: WEBROOT = '/tosh/home/sarge/cft' OLDWEB = '/tosh/home/sarge/website_old' ERRFILE = '/tosh/home/sarge/cft/mpErr.txt' def join_with_fslash(s1, s2): return(s1 + '/' + s2) # end join_with_fslash flErr = open(ERRFILE, 'w') # Walk the main directory tree def walk_tree(oDir, nDir): mCount = 0 pCount = 0 nCount = 0 nDir = nDir.replace("\\", '/') oldDir = "" for root, dirs, files in os.walk(nDir): # Only when changing root directories do we collect a list of .pdf # and .midi files root = root.replace("\\", '/') if root == oldDir: continue # Now we have a new "old directory" oldDir = root if root.endswith('/midi'): # Get a list of .mid files in this directory mids = [f for f in files if f.endswith('.mid')] for m in mids: currPath = join_with_fslash(root, m) oldPath = currPath.replace(nDir, oDir) if os.path.exists(oldPath): # print("Copying stat from %s to %s." % (oldPath, currPath)) shutil.copystat(oldPath, currPath) mCount += 1 else: print("Old file %s not found." % oldPath, file=flErr) nCount += 1 if root.endswith('/pdf'): # Get a list of .pdf files in this directory pdfs = [f for f in files if f.endswith('.pdf')] for p in pdfs: currPath = join_with_fslash(root, p) oldPath = currPath.replace(nDir, oDir) if os.path.exists(oldPath): # print("Copying stat from %s to %s." % (oldPath, currPath)) shutil.copystat(oldPath, currPath) pCount += 1 else: print("Old file %s not found." % oldPath, file=flErr) nCount += 1 # end if root != oldDir # After walking the directories. return (mCount, pCount, nCount) # end walk_tree def print_stats(sTime,counts): (mCount, pCount, nCount) = counts endTime = int(time.time()) elapsedTime = endTime - sTime elapsedSeconds = elapsedTime % 3600 elapsedHours = int((elapsedTime - elapsedSeconds) / 3600) elapsedMinutes = elapsedSeconds / 60 elapsedSeconds = elapsedSeconds % 60 elapsedMinutes = int(elapsedMinutes - elapsedSeconds / 60) print("%d files not found; %d .mid files and %d .pdf files processed in %d hours, %d minutes, and %d seconds." % (nCount, mCount,pCount,elapsedHours, elapsedMinutes, elapsedSeconds)) def main(): startTime = int(time.time()) # (mCount, pCount) = walk_tree(OLDWEB, WEBROOT) print_stats(startTime, walk_tree(OLDWEB, WEBROOT)) print("Type a key to exit: ", end='') input() # end main if __name__ == "__main__": main()