sabayon r944 - in trunk: . lib



Author: federico
Date: Tue Feb 19 02:36:40 2008
New Revision: 944
URL: http://svn.gnome.org/viewvc/sabayon?rev=944&view=rev

Log:
Pull should_ignore_dir/file out of DirectoryMonitor
2008-02-18  Federico Mena Quintero  <federico novell com>

	* lib/util.py (should_ignore_dir): Moved over from dirmonitor.py;
	now this is a general-purpose function instead of being specific
	to the directory monitor.
	(should_ignore_file): Likewise.

	* lib/dirmonitor.py (DirectoryMonitor.__should_ignore_dir):
	Implement in terms of util.should_ignore_dir().
	(DirectoryMonitor.__should_ignore_file): Implement in terms of
	util.should_ignore_file().

Signed-off-by: Federico Mena Quintero <federico gnu org>


Modified:
   trunk/ChangeLog
   trunk/lib/dirmonitor.py
   trunk/lib/util.py

Modified: trunk/lib/dirmonitor.py
==============================================================================
--- trunk/lib/dirmonitor.py	(original)
+++ trunk/lib/dirmonitor.py	Tue Feb 19 02:36:40 2008
@@ -105,28 +105,10 @@
                 dprint ("Not calling callback for '%s' nor recursing in it since it is an ignored dir/file", path)
 
     def __should_ignore_dir (self, dir):
-        dir = os.path.normpath (dir)
-        
-        for ignore_dir in self.dirs_to_ignore:
-            ignore_path = os.path.normpath (os.path.join (self.directory, ignore_dir))
-
-            if fnmatch.fnmatch (dir, ignore_path):
-                return True
-
-        parent = os.path.dirname (dir)
-        if parent != dir:
-            return self.__should_ignore_dir (parent)
-        else:
-            return False
+        return util.should_ignore_dir (self.directory, self.dirs_to_ignore, dir)
     
     def __should_ignore_file (self, file):
-        file = os.path.normpath (file)
-        
-        for ignore_file in self.files_to_ignore:
-            ignore_path = os.path.normpath (os.path.join (self.directory, ignore_file))
-            if fnmatch.fnmatch (file, ignore_path):
-                return True
-        return self.__should_ignore_dir (os.path.dirname (file))
+        return util.should_ignore_file (self.directory, self.dirs_to_ignore, self.files_to_ignore, file)
 
     def __monitor_dir (self, dir):
         dir = os.path.normpath (dir)

Modified: trunk/lib/util.py
==============================================================================
--- trunk/lib/util.py	(original)
+++ trunk/lib/util.py	Tue Feb 19 02:36:40 2008
@@ -85,7 +85,7 @@
             return pw.pw_dir
     except KeyError:
         pass
-    
+
     if os.environ.has_key ("HOME"):
         return os.environ["HOME"]
     else:
@@ -98,7 +98,7 @@
             return pw.pw_name
     except KeyError:
         pass
-    
+
     if os.environ.has_key ("USER"):
         return os.environ["USER"]
     else:
@@ -166,7 +166,7 @@
         if path[dir_split] != '/':
             raise ValueError
         return (path[:dir_split], path[dir_split+1:])
-        
+
     raise ValueError
 
 #
@@ -184,7 +184,7 @@
     except os.error, (err, errstr):
         if err != errno.EINTR:
             raise
-        
+
 def uninterruptible_spawnv (mode, file, args):
     uninterruptible_spawnve (mode, file, args, None)
 
@@ -216,7 +216,7 @@
 
         self.keys_a = self.a.keys()
         self.keys_b = self.b.keys()
-        
+
         self.intersection = []
         self.only_a = []
         self.only_b = []
@@ -235,13 +235,13 @@
         for k in self.keys_b:
             if not self.a.has_key(k):
                 self.only_b.append(k)
-                
+
         for k in self.intersection:
             if self.a[k] == self.b[k]:
                 self.equal.append(k)
             else:
                 self.not_equal.append(k)
-                
+
     def intersection(self):
         'return list of keys shared between a and b'
         return self.intersection
@@ -267,7 +267,7 @@
         (e.g. lhs = rhs), the two dictionary parameters are specified as
         either the string 'a' or the string 'b' corresponding to the parameters
         this class was created with.
-        
+
         Return value is a dictionary with 3 keys (add, del, mod) whose values
         are dictionaries containing containing (key,value) pairs to add,
         delete, or modify respectively in dict_lhs.'''
@@ -339,3 +339,28 @@
             print "    %s=%s" % (k, _mod[k])
 
 
+def should_ignore_dir (base_dir, ignore_dir_list, dir):
+    dir = os.path.normpath (dir)
+
+    for ignore_dir in ignore_dir_list:
+        ignore_path = os.path.normpath (os.path.join (base_dir, ignore_dir))
+
+        if fnmatch.fnmatch (dir, ignore_path):
+            return True
+
+    parent = os.path.dirname (dir)
+    if parent != dir:
+        return should_ignore_dir (parent)
+    else:
+        return False
+
+def should_ignore_file (base_dir, ignore_dir_list, ignore_file_list, file):
+    file = os.path.normpath (file)
+
+    for ignore_file in ignore_file_list:
+        ignore_path = os.path.normpath (os.path.join (base_dir, ignore_file))
+
+        if fnmatch.fnmatch (file, ignore_path):
+            return True
+
+    return should_ignore_dir (base_dir, ignore_dir_list, os.path.dirname (file))



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