From 16188b59d117cc298d3bae7f9e27ee1858099c1c Mon Sep 17 00:00:00 2001 From: Jakub Kadlčík Date: Apr 13 2017 16:06:24 +0000 Subject: [cli][python] possibility to submit yaml file to mbs --- diff --git a/cli/copr_cli/main.py b/cli/copr_cli/main.py index 3eae351..c0edc11 100644 --- a/cli/copr_cli/main.py +++ b/cli/copr_cli/main.py @@ -589,7 +589,8 @@ class Commands(object): print("Failed to get a token from response") sys.exit(1) - response = self.client.build_module(args.url, token) + modulemd = open(args.yaml, "rb") if args.yaml else args.url + response = self.client.build_module(modulemd, token) if response.status_code == 500: print(response.text) sys.exit(1) @@ -993,8 +994,9 @@ def setup_parser(): # module building parser_build_module = subparsers.add_parser("build-module", help="Builds a given module in Copr") - parser_build_module.add_argument("--url", - help="SCM with modulemd file in yaml format") + parser_build_module_mmd_source = parser_build_module.add_mutually_exclusive_group() + parser_build_module_mmd_source.add_argument("--url", help="SCM with modulemd file in yaml format") + parser_build_module_mmd_source.add_argument("--yaml", help="Path to modulemd file in yaml format") parser_build_module.add_argument("--token", help="OIDC token for module build service") parser_build_module.set_defaults(func="action_build_module") diff --git a/python/copr/client/client.py b/python/copr/client/client.py index ba171b2..a6e34e0 100644 --- a/python/copr/client/client.py +++ b/python/copr/client/client.py @@ -10,6 +10,7 @@ import json import sys import os import logging +import io import requests import six @@ -1467,9 +1468,15 @@ class CoprClient(UnicodeMixin): def build_module(self, modulemd, token): endpoint = "/module/1/module-builds/" - response = requests.post(urljoin(self.copr_url, endpoint), - json={"scmurl": modulemd, "branch": "master"}, - headers={"Authorization": "Bearer {}".format(token)}) + url = urljoin(self.copr_url, endpoint) + headers = {"Authorization": "Bearer {}".format(token)} + + if isinstance(modulemd, io.BufferedIOBase): + kwargs = {"files": {"yaml": modulemd}} + else: + kwargs = {"json": {"scmurl": modulemd, "branch": "master"}} + + response = requests.post(url, headers=headers, **kwargs) return response def make_module(self, projectname, modulemd, username=None):