#! /usr/bin/python3 # =================================================================== # process a tree of directories and files # Only process files that are new or changed # ------------------------------------------------------------------- # To create a delta tree, use TopDown=True and DirFirst=True # To delete a tree, use TopDown=Flase and DirFirst=False # =================================================================== import os import zz_user_interface as ui import zz_file_dir_operations as df # ------------------------------------------------------------------- # runtime enviroment # # DEBUG if True, print debug messages # DELTADIR root directory of the delta tree to be created # DIRFIRST if true, process directories before files # if false, process files before directories # INCLUDEFILES RegExp list, files names to process # ROOTDIR root direrctory of tree to process # SKIPDIRS RegExp list, directories to skip processing # SKIPFILES RegExp list, files names to skip processing # TESTMODE if True, do every thing except create the delta tree # if False, create the delta tree # (used for testing before making actual changes) # TOPDOWN if True, process the tree from the top down # if False, process the tree from the bottom to top # VERBOSE if True, print verbose messages (warm fuzzy messages) # ------------------------------------------------------------------- DEBUG = False DELTADIR = './delta/' # should end in a '/' character DIRFIRST = True INCLUDEFILES = [ r'\.py$', # include py files '\\.html$', # include html files '\.ino$' ] # include ino files ROOTDIR = './' # should end in a '/' character SKIPDIRS = [ '^x', # skip 'x' direrctories '^__pycache__$'] # skip py cache directories SKIPFILES = [ r'^\.', # skip hidden files (linux/Unix only) '^my_', # skip 'my_' files '^tk_'] # skip 'tk_' files TESTMODE = True TOPDOWN = True VERBOSE = True # ------------------------------------------------------------------- # process each selected directory with this function # (directory is path + name) # ------------------------------------------------------------------- def DirFunction(Directory,TestMode,Verbose,Debug): if Debug or Verbose: print('DirFunction({})'.format(Directory)) return True # ------------------------------------------------------------------- # process each selected file with this function # (file is path + name) # ------------------------------------------------------------------- def FileFunction(File,TestMode,Verbose,Debug): if Debug or Verbose: print('FileFunction({})'.format(File)) return True # =================================================================== # main # =================================================================== if __name__ == '__main__': print() print('start of tree processing') print() #---- running Python3? py3 = ui.RunningPython3() # ---- root directory exists? if not os.path.isdir(ROOTDIR): print("Root directory does not exist ({})".format(ROOTDIR)) quit() # ---- delta directory exists? if os.path.isdir(DELTADIR): print("Delta directory already exists ({})".format(DELTADIR)) quit() # ---- walk (process) the tree of directories and files df.WalkTheTree(ROOTDIR,DELTADIR,INCLUDEFILES,SKIPFILES,SKIPDIRS, DirFunction,FileFunction,TOPDOWN,DIRFIRST, TESTMODE,VERBOSE,DEBUG) print() print('end of tree processing') print()