From 5d9374db4049cc77e0935b7cadf2d7f97a798183 Mon Sep 17 00:00:00 2001 From: Joshua Hesketh Date: Fri, 25 Jul 2014 13:55:57 +1000 Subject: [PATCH] Fix filename in index generation for swift uploads Currently the indexes that are generated include the full path to a file even though you are in a directory. For example, you may have drilled into logs/subdir/ but all of the links in there will appear as "logs/subdir/output.log" etc. This makes the indexes only show the basename of the files or folders while keeping the absolute url's. Change-Id: Ib58a07c19c15179d8b086431a6a9094de5e41e58 --- .../files/slave_scripts/zuul_swift_upload.py | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/modules/openstack_project/files/slave_scripts/zuul_swift_upload.py b/modules/openstack_project/files/slave_scripts/zuul_swift_upload.py index b802c8894f..5c535f67fc 100755 --- a/modules/openstack_project/files/slave_scripts/zuul_swift_upload.py +++ b/modules/openstack_project/files/slave_scripts/zuul_swift_upload.py @@ -34,11 +34,16 @@ def generate_log_index(file_list, logserver_prefix, swift_destination_prefix): output = 'Index of results' output += '' @@ -107,13 +112,13 @@ def swift_form_post_submit(file_list, url, hmac_body, signature): files['file%d' % (i + 1)] = (filename_prefix + f['filename'], open(f['path'], 'rb'), get_file_mime(f['path'])) - requests.post(url, data=payload, files=files) def build_file_list(file_path, logserver_prefix, swift_destination_prefix, create_dir_indexes=True): - """Upload to swift using instructions from zuul""" + """Generate a list of files to upload to zuul. Recurses through directories + and generates index.html files if requested.""" # file_list: a list of dicts with {path=..., filename=...} where filename # is appended to the end of the object (paths can be used) @@ -132,14 +137,13 @@ def build_file_list(file_path, logserver_prefix, swift_destination_prefix, relative_name = os.path.relpath(full_path, parent_dir) push_file = {'filename': relative_name, 'path': full_path} - folder_contents.append(push_file) file_list.append(push_file) + folder_contents.append(relative_name) for f in folders: - full_path = os.path.join(path, f) + '/' + full_path = os.path.join(path, f) relative_name = os.path.relpath(full_path, parent_dir) - folder_contents.append({'filename': relative_name, - 'path': full_path}) + folder_contents.append(relative_name + '/') if create_dir_indexes: index_file = make_index_file(folder_contents, logserver_prefix, @@ -187,12 +191,11 @@ if __name__ == '__main__': quit() for file_path in args.files: + file_path = os.path.normpath(file_path) if os.path.isfile(file_path): - root_list.append({'filename': os.path.basename(file_path), - 'path': file_path}) + root_list.append(os.path.basename(file_path)) else: - root_list.append({'filename': os.path.basename(file_path) + '/', - 'path': file_path}) + root_list.append(os.path.basename(file_path) + '/') file_list += build_file_list( file_path, logserver_prefix, swift_destination_prefix,