build:waf dist: factor out function to add list of files to the tarball
[samba.git] / buildtools / wafsamba / samba_dist.py
index 1f56f2e3ec2b2d96bc8709d5ba7533174ca72c7d..871c11101967ef15a9f9903e411bb86d053b425d 100644 (file)
@@ -99,6 +99,34 @@ def vcs_dir_contents(path):
 
 
 def dist(appname='',version=''):
+
+    def add_files_to_tarball(tar, srcdir, srcsubdir, dstdir, dstsubdir, blacklist, files):
+        if blacklist == None:
+            blacklist = []
+        for f in files:
+            abspath = os.path.join(srcdir, f)
+
+            if srcsubdir != '.':
+                f = f[len(srcsubdir)+1:]
+
+            # Remove files in the blacklist
+            if f in blacklist:
+                continue
+            blacklisted = False
+            # Remove directories in the blacklist
+            for d in blacklist:
+                if f.startswith(d):
+                    blacklisted = True
+            if blacklisted:
+                continue
+            if os.path.isdir(abspath):
+                continue
+            if dstsubdir != '.':
+                f = dstsubdir + '/' + f
+            fname = dstdir + '/' + f
+            add_tarfile(tar, fname, abspath, srcsubdir)
+
+
     if not isinstance(appname, str) or not appname:
         # this copes with a mismatch in the calling arguments for dist()
         appname = Utils.g_module.APPNAME
@@ -135,28 +163,7 @@ def dist(appname='',version=''):
         except Exception, e:
             Logs.error('unable to get contents of %s: %s' % (absdir, e))
             sys.exit(1)
-        for f in files:
-            abspath = os.path.join(srcdir, f)
-
-            if dir != '.':
-                f = f[len(dir)+1:]
-
-            # Remove files in the blacklist
-            if f in blacklist:
-                continue
-            blacklisted = False
-            # Remove directories in the blacklist
-            for d in blacklist:
-                if f.startswith(d):
-                    blacklisted = True
-            if blacklisted:
-                continue
-            if os.path.isdir(abspath):
-                continue
-            if destdir != '.':
-                f = destdir + '/' + f
-            fname = dist_base + '/' + f
-            add_tarfile(tar, fname, abspath, dir)
+        add_files_to_tarball(tar, srcdir, dir, dist_base, destdir, blacklist, files)
 
     if dist_files:
         for file in dist_files.split():