diff --git a/software-client/software_client/software_client.py b/software-client/software_client/software_client.py index 403b3cc9..9f87049f 100644 --- a/software-client/software_client/software_client.py +++ b/software-client/software_client/software_client.py @@ -809,18 +809,29 @@ def release_upload_dir_req(args): # Ignore interrupts during this function signal.signal(signal.SIGINT, signal.SIG_IGN) - dirlist = {} - i = 0 - for d in sorted(list(set(release_dirs))): - dirlist["dir%d" % i] = os.path.abspath(d) - i += 1 + to_upload_files = {} + raw_files = [] - url = "http://%s/software/upload_dir" % api_addr + # Find all files that need to be uploaded in given directories + for release_dir in release_dirs: + raw_files = [f for f in os.listdir(release_dir) + if os.path.isfile(os.path.join(release_dir, f))] - headers = {} + # Get absolute path of files + raw_files = [os.path.abspath(os.path.join(release_dir, f)) for f in raw_files] + + for software_file in sorted(set(raw_files)): + _, ext = os.path.splitext(software_file) + if ext in constants.SUPPORTED_UPLOAD_FILE_EXT: + to_upload_files[software_file] = (software_file, open(software_file, 'rb')) + + encoder = MultipartEncoder(fields=to_upload_files) + url = "http://%s/software/upload" % api_addr + headers = {'Content-Type': encoder.content_type} append_auth_token_if_required(headers) - req = requests.post(url, params=dirlist, headers=headers) - + req = requests.post(url, + data=encoder, + headers=headers) if args.debug: print_result_debug(req) else: diff --git a/software/software/api/controllers/root.py b/software/software/api/controllers/root.py index b745591d..cfb6e6de 100644 --- a/software/software/api/controllers/root.py +++ b/software/software/api/controllers/root.py @@ -5,7 +5,6 @@ SPDX-License-Identifier: Apache-2.0 """ import cgi -import glob import os from oslo_log import log from pecan import expose @@ -188,31 +187,6 @@ class SoftwareAPIController(object): sc.software_sync() shutil.rmtree(temp_dir, ignore_errors=True) - @expose('json') - def upload_dir(self, **kwargs): - # todo(abailey): extensions should be configurable or - # registered in setup.cfg - extensions = ['*.patch', '*.tar', '*.iso'] - files = [] - # todo(abailey): investigate an alternative to glob - for path in kwargs.values(): - LOG.info("upload-dir: Uploading software from: %s", path) - for ext in extensions: - for f in glob.glob(path + "/" + ext): - if os.path.isfile(f): - LOG.info("upload-dir: Uploading : %s", f) - files.append(f) - - if len(files) == 0: - return dict(error="No software found matching %s" % extensions) - - try: - result = sc.software_release_upload(sorted(files)) - except SoftwareError as e: - return dict(error=str(e)) - sc.software_sync() - return result - @expose('json') @expose('query.xml', content_type='application/xml') def query(self, **kwargs):