From a113d67b62dc3ed4d70acb86ea6c70c6df745f33 Mon Sep 17 00:00:00 2001 From: Sayan Chowdhury Date: Fri, 13 Apr 2018 01:23:15 +0530 Subject: [PATCH] fedimg: Fix the trigger_upload script a/c to fedimg==1.1.0 Signed-off-by: Sayan Chowdhury --- roles/fedimg/files/trigger_upload.py | 47 +++++++++++++++++----------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/roles/fedimg/files/trigger_upload.py b/roles/fedimg/files/trigger_upload.py index 7f5d0ba69d..a0184d2563 100644 --- a/roles/fedimg/files/trigger_upload.py +++ b/roles/fedimg/files/trigger_upload.py @@ -2,34 +2,45 @@ # -*- coding: utf8 -*- """ Triggers an upload process with the specified raw.xz URL. """ +import argparse import logging import logging.config import multiprocessing.pool -import sys -import fedmsg import fedmsg.config - -import fedimg -import fedimg.services -from fedimg.services.ec2 import EC2Service, EC2ServiceException import fedimg.uploader -from fedimg.util import virt_types_from_url - -if len(sys.argv) != 3: - print 'Usage: trigger_upload.py ' - sys.exit(1) logging.config.dictConfig(fedmsg.config.load_config()['logging']) log = logging.getLogger('fedmsg') -upload_pool = multiprocessing.pool.ThreadPool(processes=4) -url = sys.argv[1] -compose_id = sys.argv[2] +def trigger_upload(compose_id, url, push_notifications): + upload_pool = multiprocessing.pool.ThreadPool(processes=4) + compose_meta = {'compose_id': compose_id} + fedimg.uploader.upload(upload_pool, [url], compose_meta=compose_meta) -compose_meta = { - 'compose_id': compose_id -} -fedimg.uploader.upload(upload_pool, [url], compose_meta=compose_meta) +def get_args(): + parser = argparse.ArgumentParser( + description="Trigger a manual upload process with the " + "specified raw.xz URL") + parser.add_argument( + "-u", "--url", type=str, help=".raw.xz URL", required=True) + parser.add_argument( + "-c", "--compose-id", type=str, help="compose id of the .raw.xz file", + required=True) + parser.add_argument( + "-p", "--push-notifications", + help="Bool to check if we need to push fedmsg notifications", + action="store_true", required=False) + args = parser.parse_args() + + return args.url, args.compose_id, args.push_notifications + + +def main(): + url, compose_id, push_notifications = get_args() + trigger_upload(url, compose_id, push_notifications) + +if __name__ == '__main__': + main()