diff options
author | Guillaume Tucker <guillaume.tucker@collabora.com> | 2019-04-24 16:14:28 +0100 |
---|---|---|
committer | Guillaume Tucker <guillaume.tucker@collabora.com> | 2019-05-03 12:59:46 +0100 |
commit | fe9d0438eb616a099c4b03a0e9bddb59ea263369 (patch) | |
tree | fd220f4ce3e8b1b80d7244b3fd9653a89d290283 | |
parent | 512fdcddca2d7775c277c0cf122c6cd56ffa532f (diff) |
kci_build: add --json-path option to publish_kernel
Add the --json-path to the publish_kernel command to be able to
specify a path where to store the build data in a local JSON file
rather than submitting it to the backend server. Both can be used, if
--api and --token are also provided.
Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
-rwxr-xr-x | kci_build | 19 | ||||
-rw-r--r-- | kernelci/build.py | 46 |
2 files changed, 53 insertions, 12 deletions
@@ -132,6 +132,11 @@ class Args(object): 'help': "Path the output directory", } + json_path = { + 'name': '--json-path', + 'help': "Path to the JSON file", + } + # ----------------------------------------------------------------------------- # Commands @@ -397,10 +402,20 @@ class cmd_push_kernel(Command): class cmd_publish_kernel(Command): help = "Publish the kernel meta-data" - args = [Args.kdir, Args.api, Args.token] + args = [Args.kdir] + opt_args = [Args.api, Args.token, Args.json_path] def __call__(self, configs, args): - return kernelci.build.publish_kernel(args.kdir, args.api, args.token) + if not ((args.api and args.token) or args.json_path): + print("""\ +Invalid arguments, please provide at least one of these sets of options: + --token, --api to publish to the backend server + --json-path to save the data in a local JSON file\ +""") + return False + return kernelci.build.publish_kernel( + args.kdir, api=args.api, token=args.token, + json_path=args.json_path) # ----------------------------------------------------------------------------- # Main diff --git a/kernelci/build.py b/kernelci/build.py index ed85638..c05d895 100644 --- a/kernelci/build.py +++ b/kernelci/build.py @@ -588,7 +588,8 @@ def push_kernel(kdir, api, token, install='_install_'): return True -def publish_kernel(kdir, api, token, install='_install_'): +def publish_kernel(kdir, install='_install_', api=None, token=None, + json_path=None): install_path = os.path.join(kdir, install) with open(os.path.join(install_path, 'build.json')) as f: @@ -596,6 +597,7 @@ def publish_kernel(kdir, api, token, install='_install_'): data = {k: bmeta[v] for k, v in { 'path': 'file_server_resource', + 'file_server_resource': 'file_server_resource', 'job': 'job', 'git_branch': 'git_branch', 'arch': 'arch', @@ -605,14 +607,38 @@ def publish_kernel(kdir, api, token, install='_install_'): 'defconfig_full': 'defconfig_full', }.iteritems()} - headers = { - 'Authorization': token, - 'Content-Type': 'application/json', - } - - url = urlparse.urljoin(api, '/build') - json_data = json.dumps(data) - resp = requests.post(url, headers=headers, data=json_data) - resp.raise_for_status() + if json_path: + json_data = dict(data) + for k in ['kernel_image', 'modules', 'git_commit', 'git_url']: + json_data[k] = bmeta[k] + json_data['status'] = bmeta['build_result'] + dtb_data = [] + if bmeta['dtb_dir']: + dtb_dir = os.path.join(install_path, bmeta['dtb_dir']) + for root, dirs, files in os.walk(dtb_dir): + if root != dtb_dir: + rel = os.path.relpath(root, dtb_dir) + files = list(os.path.join(rel, dtb) for dtb in files) + dtb_data += files + json_data['dtb_dir_data'] = dtb_data + try: + with open(json_path, 'r') as json_file: + full_json = json.load(json_file) + full_json.append(json_data) + except Exception as e: + full_json = [json_data] + with open(json_path, 'w') as json_file: + json.dump(full_json, json_file) + + if api and token: + headers = { + 'Authorization': token, + 'Content-Type': 'application/json', + } + + url = urlparse.urljoin(api, '/build') + json_data = json.dumps(data) + resp = requests.post(url, headers=headers, data=json_data) + resp.raise_for_status() return True |