Anthony Young | d99f5fd | 2011-11-14 11:05:04 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
Masayuki Igawa | 46c688c | 2014-02-24 18:42:37 +0900 | [diff] [blame] | 2 | |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
Anthony Young | d99f5fd | 2011-11-14 11:05:04 -0800 | [diff] [blame] | 15 | import json |
| 16 | import sys |
Masayuki Igawa | 46c688c | 2014-02-24 18:42:37 +0900 | [diff] [blame] | 17 | import urllib |
Anthony Young | d99f5fd | 2011-11-14 11:05:04 -0800 | [diff] [blame] | 18 | |
| 19 | |
| 20 | def print_usage(): |
zhang-jinnan | 8829aca | 2014-03-03 10:55:33 +0800 | [diff] [blame] | 21 | print("Usage: %s [jenkins_url (eg. http://50.56.12.202:8080/)]" |
| 22 | % sys.argv[0]) |
Anthony Young | d99f5fd | 2011-11-14 11:05:04 -0800 | [diff] [blame] | 23 | sys.exit() |
| 24 | |
| 25 | |
| 26 | def fetch_blob(url): |
| 27 | return json.loads(urllib.urlopen(url + '/api/json').read()) |
| 28 | |
| 29 | |
| 30 | if len(sys.argv) < 2: |
| 31 | print_usage() |
| 32 | |
| 33 | BASE_URL = sys.argv[1] |
| 34 | |
| 35 | root = fetch_blob(BASE_URL) |
| 36 | results = {} |
| 37 | for job_url in root['jobs']: |
| 38 | job = fetch_blob(job_url['url']) |
| 39 | if job.get('activeConfigurations'): |
| 40 | (tag, name) = job['name'].split('-') |
| 41 | if not results.get(tag): |
| 42 | results[tag] = {} |
| 43 | if not results[tag].get(name): |
| 44 | results[tag][name] = [] |
| 45 | |
| 46 | for config_url in job['activeConfigurations']: |
| 47 | config = fetch_blob(config_url['url']) |
| 48 | |
| 49 | log_url = '' |
| 50 | if config.get('lastBuild'): |
| 51 | log_url = config['lastBuild']['url'] + 'console' |
| 52 | |
| 53 | results[tag][name].append({'test': config['displayName'], |
| 54 | 'status': config['color'], |
| 55 | 'logUrl': log_url, |
| 56 | 'healthReport': config['healthReport']}) |
| 57 | |
Masayuki Igawa | 46c688c | 2014-02-24 18:42:37 +0900 | [diff] [blame] | 58 | print(json.dumps(results)) |