We wanted to track everything under /etc with func without having to specify every subdirectory manually. Here's a patch to recursively chew through it all.
-Ralph Bean
Research Computing
Rochester Institute of Technology
From db494fa2dc25a8f51e870009404fc6d1ccb8e2d0 Mon Sep 17 00:00:00 2001 From: Ralph Bean <ralph.bean@xxxxxxxxx> Date: Tue, 24 Aug 2010 14:28:59 -0400 Subject: [PATCH] added recursive parameter to filetracker.track --- func/minion/modules/filetracker.py | 18 +++++++++++++++++- 1 files changed, 17 insertions(+), 1 deletions(-) diff --git a/func/minion/modules/filetracker.py b/func/minion/modules/filetracker.py index 156f051..d58f9d3 100644 --- a/func/minion/modules/filetracker.py +++ b/func/minion/modules/filetracker.py @@ -71,12 +71,13 @@ class FileTracker(func_module.FuncModule): #========================================================== - def track(self, file_name_globs, full_scan=0): + def track(self, file_name_globs, full_scan=0, recursive=0): """ Adds files to keep track of. file_names can be a single filename, a list of filenames, a filename glob or a list of filename globs full_scan implies tracking the full contents of the file, defaults to off + recursive implies tracking the contents of every subdirectory """ filehash = self.__load() @@ -87,11 +88,20 @@ class FileTracker(func_module.FuncModule): if type(file_name_globs) == type([]): filenameglobs = file_name_globs + def _recursive(original_filenames): + for filename in original_filenames: + for (dir, subdirs, subfiles) in os.walk(filename): + for subdir in subdirs: + yield "%s/%s" % (dir, subdir) + for subfile in subfiles: + yield "%s/%s" % (dir, subfile) # expand everything that might be a glob to a list # of names to track for filenameglob in filenameglobs: filenames = glob.glob(filenameglob) + if recursive: + filenames += _recursive(filenames) for filename in filenames: filehash[filename] = full_scan self.__save(filehash) @@ -266,6 +276,12 @@ class FileTracker(func_module.FuncModule): 'optional':True, 'default':0, 'description':"The 0 is for off and 1 is for on" + }, + 'recursive':{ + 'type':'int', + 'optional':True, + 'default':0, + 'description':"The 0 is for off and 1 is for on" } }, 'description':"Adds files to keep track of" -- 1.7.2.1
_______________________________________________ Func-list mailing list Func-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/func-list