# updatelocal.py # During a BIRCH update, this script checks to make sure # that all files found in the new copy of $BIRCH/local-generic # are also present in the existing $BIRCH/local directory. # Files not found in $BIRCH/local are copied from $BIRCH/local-generic # # Set variables for local-generic, local, and current # directories import os, os.path, sys, shutil def update_local(): UPDIR = os.path.abspath(os.path.join(os.getcwd(), os.pardir)) LOCAL = os.path.join(UPDIR, "local") LOCALGENERIC = os.path.join(UPDIR, "local-generic") print ("LOCAL " + LOCAL) print ("LOCALGENERIC " + LOCALGENERIC) newlocalfiles = open("NewLocalFiles.list") #--------------------------------------------------------------------------- # When a directory is not found, copy whole directory # in a single step. Otherwise, copy one file at a time. for name in newlocalfiles: gen_name = os.path.join(LOCALGENERIC, name) local_name = os.path.join(LOCAL, name) if os.path.exists(gen_name) and not os.path.exists(local_name): # symbolic link if os.path.islink(gen_name): print ('Copying link ' + local_name) os.symlink(local_name, os.readlink(gen_name)) # directory elif os.path.isdir(gen_name): print ('Copying directory ' + local_name) shutil.copytree(gen_name, local_name) #file else: print ('Copying file ' + local_name) shutil.copy(gen_name, local_name) newlocalfiles.close() if __name__=="__main__": update_local()