From 76909625027772102e0a174c17bce5490f8a8fcf Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Thu, 3 Mar 2022 15:29:16 +0100 Subject: Search config files in tree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It allows putting configurations in classical dirs. It fallbacks to the python package for backward compatibility. Change-Id: Ie33b9482fb197926c7d7d66ace815fa4ae01d02d Signed-off-by: Cédric Ollivier --- xtesting/core/campaign.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'xtesting/core') diff --git a/xtesting/core/campaign.py b/xtesting/core/campaign.py index 7c766e53..2c16dfac 100644 --- a/xtesting/core/campaign.py +++ b/xtesting/core/campaign.py @@ -20,13 +20,15 @@ import zipfile import boto3 from boto3.s3.transfer import TransferConfig import botocore -import pkg_resources import requests from six.moves import urllib from xtesting.core import testcase +from xtesting.utils import config +from xtesting.utils import constants from xtesting.utils import env + __author__ = "Cedric Ollivier " @@ -118,7 +120,7 @@ class Campaign(): dst_s3_url = os.environ["S3_DST_URL"] multipart_threshold = 5 * 1024 ** 5 if "google" in os.environ[ "S3_ENDPOINT_URL"] else 8 * 1024 * 1024 - config = TransferConfig(multipart_threshold=multipart_threshold) + tconfig = TransferConfig(multipart_threshold=multipart_threshold) bucket_name = urllib.parse.urlparse(dst_s3_url).netloc s3path = re.search( '^/*(.*)/*$', urllib.parse.urlparse(dst_s3_url).path).group(1) @@ -133,8 +135,8 @@ class Campaign(): # pylint: disable=no-member b3resource.Bucket(bucket_name).download_file( s3_object.key, - re.sub('^{}/*'.format(s3path), '', s3_object.key), - Config=config) + re.sub(f'^{s3path}/*', '', s3_object.key), + Config=tconfig) Campaign.__logger.info( "Downloading %s", re.sub('^{}/*'.format(s3path), '', s3_object.key)) @@ -181,15 +183,15 @@ class Campaign(): dst_s3_url = os.environ["S3_DST_URL"] multipart_threshold = 5 * 1024 ** 5 if "google" in os.environ[ "S3_ENDPOINT_URL"] else 8 * 1024 * 1024 - config = TransferConfig(multipart_threshold=multipart_threshold) + tconfig = TransferConfig(multipart_threshold=multipart_threshold) bucket_name = urllib.parse.urlparse(dst_s3_url).netloc - mime_type = mimetypes.guess_type('{}.zip'.format(build_tag)) + mime_type = mimetypes.guess_type(f'{build_tag}.zip') path = urllib.parse.urlparse(dst_s3_url).path.strip("/") # pylint: disable=no-member b3resource.Bucket(bucket_name).upload_file( - '{}.zip'.format(build_tag), - os.path.join(path, '{}.zip'.format(build_tag)), - Config=config, + f'{build_tag}.zip', + os.path.join(path, f'{build_tag}.zip'), + Config=tconfig, ExtraArgs={'ContentType': mime_type[ 0] or 'application/octet-stream'}) dst_http_url = os.environ["HTTP_DST_URL"] @@ -215,10 +217,10 @@ def main(): if not os.path.exists(testcase.TestCase.dir_results): os.makedirs(testcase.TestCase.dir_results) if env.get('DEBUG').lower() == 'true': - logging.config.fileConfig(pkg_resources.resource_filename( - 'xtesting', 'ci/logging.debug.ini')) + logging.config.fileConfig(config.get_xtesting_config( + 'logging.debug.ini', constants.DEBUG_INI_PATH_DEFAULT)) else: - logging.config.fileConfig(pkg_resources.resource_filename( - 'xtesting', 'ci/logging.ini')) + logging.config.fileConfig(config.get_xtesting_config( + 'logging.ini', constants.INI_PATH_DEFAULT)) logging.captureWarnings(True) Campaign.zip_campaign_files() -- cgit 1.2.3-korg