[PATCH] builder: Upload recursively all files in all subdirs

Mathieu Bridon bochecha at fedoraproject.org
Wed Oct 2 08:00:09 UTC 2013


---
This will become necessary if we want to upload the results of a mash
task, as I am currently working on.

Should I have created a new uploadDirRecursively() method, instead of
changing uploadDir()?

 builder/kojid | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/builder/kojid b/builder/kojid
index ca73cad..fbd4e73 100755
--- a/builder/kojid
+++ b/builder/kojid
@@ -371,15 +371,34 @@ class BuildRoot(object):
         append '.' + suffix to the filenames, so that successive uploads
         of the same directory won't overwrite each other, if the files have
         the same name but different contents."""
+        def walker(arg, dirname, filenames):
+            # `arg` is completely ignored here
+            if dirname == dirpath:
+                uploadpath = rootuploadpath
+
+            else:
+                dirrelpath = os.path.relpath(dirname, start=dirpath)
+                uploadpath = os.path.join(rootuploadpath, dirrelpath)
+
+            for filename in filenames:
+                filepath = os.path.join(dirname, filename)
+
+                if os.path.isdir(filepath):
+                    # TODO: Should we do something about this?
+                    continue
+
+                if os.stat(filepath).st_size > 0:
+                    if suffix:
+                        filename = '%s.%s' % (filename, suffix)
+
+                    self.session.uploadWrapper(filepath, uploadpath, filename)
+
         if not os.path.isdir(dirpath):
             return
-        uploadpath = self.getUploadPath()
-        for filename in os.listdir(dirpath):
-            filepath = os.path.join(dirpath, filename)
-            if os.stat(filepath).st_size > 0:
-                if suffix:
-                    filename = '%s.%s' % (filename, suffix)
-                self.session.uploadWrapper(filepath, uploadpath, filename)
+
+        rootuploadpath = self.getUploadPath()
+
+        os.path.walk(dirpath, walker, None)
 
     def init(self):
         rv = self.mock(['--init'])
-- 
1.8.1.4



More information about the buildsys mailing list