[patch] Added 'files_only' argument to filetracker.track

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello again-
  I've reattached my first patch with a second now that adds a 'files_only' parameter to filetracker.track to ignore directories and links when specified.

  We're using these in combination with func-inventory, a cron entry, and git log to produce HTML emails of colorized diffs of every change that happens in /etc on all of our servers.

  Func is pretty sweet.  Thanks for a great tool!

-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 1/2] 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

From de4334bde7a235cf01950ec16a3e1b4741370d0d Mon Sep 17 00:00:00 2001
From: Ralph Bean <ralph.bean@xxxxxxxxx>
Date: Tue, 24 Aug 2010 14:55:22 -0400
Subject: [PATCH 2/2] Added files_only parameter to filetracker.track

---
 func/minion/modules/filetracker.py |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/func/minion/modules/filetracker.py b/func/minion/modules/filetracker.py
index d58f9d3..bfa6208 100644
--- a/func/minion/modules/filetracker.py
+++ b/func/minion/modules/filetracker.py
@@ -71,13 +71,14 @@ class FileTracker(func_module.FuncModule):
 
     #==========================================================
                
-    def track(self, file_name_globs, full_scan=0, recursive=0):
+    def track(self, file_name_globs, full_scan=0, recursive=0, files_only=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
+        files_only implies tracking files that are files (not directories)
         """
 
         filehash = self.__load()
@@ -102,6 +103,8 @@ class FileTracker(func_module.FuncModule):
             filenames = glob.glob(filenameglob)
             if recursive:
                 filenames += _recursive(filenames)
+            if files_only:
+                filenames = [f for f in filenames if os.path.isfile(f)]
             for filename in filenames:
                 filehash[filename] = full_scan
         self.__save(filehash)
@@ -282,6 +285,12 @@ class FileTracker(func_module.FuncModule):
                             'optional':True,
                             'default':0,
                             'description':"The 0 is for off and 1 is for on"
+                            },
+                        'files_only':{
+                            'type':'int',
+                            'optional':True,
+                            'default':0,
+                            'description':"Track only files (not dirs or links)"
                             }
                         },
                     '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

[Index of Archives]     [Fedora Users]     [Linux Networking]     [Fedora Legacy List]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux