[PATCH] builder: Upload recursively all files in all subdirs
Mike McLean
mikem at redhat.com
Wed Oct 2 23:16:11 UTC 2013
On 10/02/2013 04:00 AM, Mathieu Bridon wrote:
> ---
> 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()?
It should probably be an optional flag rather than a change to default
behavior.
It might be simpler if you used os.walk instead of os.path.walk.
I don't think you need to do anything in the os.path.isdir case, unless
you intend to prune the walk.
> 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'])
>
More information about the buildsys
mailing list