#!/usr/bin/env python import sys import json import uuid import os from datetime import datetime, timedelta from linaro_dashboard_bundle.io import DocumentIO build_status=os.getenv('BUILD_STATUS') gcc_cross_compiler_version = os.getenv('GCC_CROSS_COMPILER', 'unknown') gcc_version = os.getenv('GCC_VERSION', 'unknown') commit_time=os.getenv("COMMIT_TIME") commit_time=commit_time.rsplit(' ', 1)[0] commit_time=((datetime.strptime(commit_time, "%a, %d %b %Y %H:%M:%S")).strftime("%Y-%m-%dT%H:%M:%SZ")) bundle = { "format": "Dashboard Bundle Format 1.2", "test_runs": [ { "test_id": "kernel-ci", "test_results": [ { "test_case_id": "build-status", "result": build_status },], "attributes": { "kernel.name": os.getenv("KERNEL_NAME", "unknown"), "target.device_type": os.getenv("BOARD_TYPE", "unknown"), "kernel.git_log_info": os.getenv("GIT_LOG", "unknown"), "kernel.config": os.getenv('KERNEL_CONFIG', 'unknown'), "kernel.git_branch_name": os.getenv('KERNEL_BRANCH', 'unknown'), "kernel.git_describe_info": os.getenv('KERNEL_VERSION','unknown'), "build.id": os.getenv('BUILD_ID', 'unknown'), "kernel.gitweb_url": os.getenv('GIT_WEB_URL', 'unknown'), "kernel.build_url": os.getenv('KERNEL_BUILD_URL', 'unknown') }, "software_context": { "image": { "name": os.getenv('OS_INFO', 'unknown') }, "sources": [{ "project_name": "Linux Linaro", "branch_vcs": "git", "branch_url": os.getenv('KERNEL_GIT', 'git://git.linaro.org/kernel/unknown'), "branch_revision": os.getenv('KERNEL_COMMIT', 'unknown'), "commit_timestamp": commit_time } ] }, "attachments": [{ "pathname": "consoleText", "mime_type": "text/plain", "public_url": os.getenv('LOG', 'unknown') },], "time_check_performed": True, } ] } def GetInHMS(seconds): d = timedelta(seconds=seconds) return "%02dd %02ds %02dus" % (d.days, d.seconds, d.microseconds) if build_status != 'fail': build_time=int(os.getenv('EXECUTION_TIME_IN_SEC')) timestamp=os.getenv('HWPACK_BUILD_DATE') timestamp=((datetime.strptime(timestamp, "%Y%m%d-%H%M")).strftime("%Y-%m-%dT%H:%M:%SZ")) bundle['test_runs'][0]['test_results'][0]['timestamp']=timestamp bundle['test_runs'][0]['test_results'][0]['duration']=GetInHMS(build_time) bundle['test_runs'][0]['software_context']['packages']=[{'version': gcc_version, 'name': 'gcc'}, {'version': gcc_cross_compiler_version, 'name': 'gcc-arm-linux-gnueabi'}] bundle['test_runs'][0]['analyzer_assigned_uuid']=str(uuid.uuid1()) bundle['test_runs'][0]['analyzer_assigned_date']=datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") print DocumentIO.dumps(bundle, human_readable=True, sort_keys=True)