#!python3 ''' Created on Sep 21, 20-16 author: tpweis file name: watcherfeeder.py This function feeds files into a directory that is watched. (input argument 1) This is a simple tool used for testing the watching ''' import os, time import subprocess import sys import shutil def main(): "function main" arglist = sys.argv[1:] if(len(arglist)< 1): print("Missing Watch Directory argument. Try again") sys.exit(3) else: WATCHdir = arglist[0] if(len(arglist) < 2): print("Missing seed file argument. Try again") sys.exit(4) else: SEEDfile =arglist[1] if(len(arglist) < 3): print("Missing replication count argument. Defaulting to 3") rep_count = 3 else: rep_count =int(arglist[2]) if rep_count > 10: print("Maximum replication count is 10") rep_count = 10 elif rep_count < 1: print("Minimum replication count is 1") rep_count = 1 # Now ensure that both the directory and file exist. if not os.path.isdir(WATCHdir): print("First arg (watcher directory) " + WATCHdir + " is not a valid directory") sys.exit(5) if not os.path.isfile(SEEDfile): print("Second arg (processed directory) " + SEEDfile + " is not a valid file name") sys.exit(6) print("Place " + str(rep_count) + " copy of " + SEEDfile + " into directory " + WATCHdir) # beging the copying filename,sep,ext = SEEDfile.rpartition('.') for copy_count in range (rep_count): # fiddle with the file name so that we can produce numbered copies newfile = WATCHdir + "/" + filename + str(copy_count) + sep + ext print(newfile) shutil.copy(SEEDfile,newfile) sys.exit(0) if __name__ == '__main__': # execute only if run as a script main()