git » abk » commit c06b67b

Implement file exclusion with regular expressions.

author Alberto Bertogli
2005-05-01 16:02:57 UTC
committer Alberto Bertogli
2005-05-01 16:02:57 UTC
parent c305709314a574738e2854992117623e38d5d5b7

Implement file exclusion with regular expressions.

abk +20 -2

diff --git a/abk b/abk
index 8aac12b..0b2ded2 100644
--- a/abk
+++ b/abk
@@ -8,6 +8,7 @@ import sys
 import os
 import sha
 import cPickle
+import re
 from stat import *
 
 
@@ -281,8 +282,16 @@ class index_file:
 		"Get the file_info object for the given filename."
 		return self.db[filename]
 
-	def populate(self, root):
+	def populate(self, root, exclude):
 		"Populate the index from a root path."
+
+		def skip_file(relname):
+			"Check if the file matches the exclude list"
+			for r in exclude:
+				if r.search(relname):
+					return 1
+			return 0
+
 		root = os.path.abspath(root)
 		base, reduced = os.path.split(root)
 		self.put_file(reduced, root)
@@ -291,10 +300,14 @@ class index_file:
 			for f in files:
 				full = path + '/' + f
 				name = relative_path(base, full)
+				if skip_file(name):
+					continue
 				self.put_file(name, full)
 			for c in childs:
 				full = path + '/' + c
 				name = relative_path(base, full)
+				if skip_file(name):
+					continue
 				self.put_file(name, full)
 
 
@@ -348,6 +361,11 @@ def make_sync(sources, srcidx_path, dst_path, dstidx_path, exclude):
 	dst_path = os.path.join(os.getcwd(), dst_path)
 	dstidx_path = os.path.join(os.getcwd(), dstidx_path)
 
+	# process regular expressions
+	exclude_re = []
+	for r in exclude:
+		exclude_re.append(re.compile(r))
+
 	# load destination index
 	printv("* loading destination index")
 	dstidx = index_file(dstidx_path)
@@ -358,7 +376,7 @@ def make_sync(sources, srcidx_path, dst_path, dstidx_path, exclude):
 	srcidx = index_file(srcidx_path)
 	for src_path in sources:
 		printv("\t* " + src_path)
-		srcidx.populate(src_path)
+		srcidx.populate(src_path, exclude_re)
 
 	printv("* sync")