Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 import json | |
| 7 import multiprocessing | |
| 8 import os | |
| 9 import platform | |
| 10 import subprocess | |
| 11 import sys | |
| 12 | |
| 13 | |
| 14 import common | |
| 15 | |
| 16 | |
| 17 def is_linux(): | |
| 18 return sys.platform.startswith('linux') | |
| 19 | |
| 20 | |
| 21 def get_free_disk_space(): | |
| 22 """Returns the amount of free space on the current disk, in GiB. | |
| 23 | |
| 24 Returns: | |
| 25 The amount of free space on the current disk, measured in GiB. | |
| 26 """ | |
| 27 if os.name == 'posix': | |
| 28 # Stat the current path for info on the current disk. | |
| 29 stat_result = os.statvfs('.') | |
| 30 # Multiply block size by number of free blocks, express in GiB. | |
| 31 return stat_result.f_frsize * stat_result.f_bavail / ( | |
| 32 1024.0 / 1024.0 / 1024.0) | |
| 33 | |
| 34 assert False, 'OS %s not supported.' % os.name | |
|
Paweł Hajdan Jr.
2015/02/10 08:34:12
I'd rather throw an exception than assert.
shatch
2015/02/10 16:42:57
Removed assert and just added to the failures list
| |
| 35 return 0 | |
| 36 | |
| 37 | |
| 38 def get_num_cpus(): | |
| 39 """Returns the number of logical CPUs on this machine. | |
| 40 | |
| 41 Returns: | |
| 42 The number of logical CPUs on this machine, or 'unknown' if indeterminate. | |
| 43 """ | |
| 44 try: | |
| 45 return multiprocessing.cpu_count() | |
| 46 except NotImplementedError: | |
| 47 return 'unknown' | |
| 48 | |
| 49 | |
| 50 def get_device_info(args, failures): | |
| 51 """Parses the device info for each attached device, and returns a summary | |
| 52 of the device info and any mismatches. | |
| 53 | |
| 54 Returns: | |
| 55 A dict indicating the result. | |
| 56 """ | |
| 57 if not is_linux(): | |
| 58 return {} | |
| 59 | |
| 60 with common.temporary_file() as tempfile_path: | |
| 61 rc = common.run_command([ | |
| 62 sys.executable, | |
| 63 os.path.join(args.paths['checkout'], | |
| 64 'build', | |
| 65 'android', | |
| 66 'buildbot', | |
| 67 'bb_device_status_check.py'), | |
| 68 '--json-output', tempfile_path]) | |
| 69 | |
| 70 if rc: | |
| 71 failures.append('bb_device_status_check') | |
| 72 return {} | |
| 73 | |
| 74 with open(tempfile_path, 'r') as src: | |
| 75 device_info = json.load(src) | |
| 76 | |
| 77 results = {} | |
| 78 results['devices'] = sorted(v['serial'] for v in device_info) | |
| 79 | |
| 80 details = [v['build_detail'] for v in device_info] | |
| 81 | |
| 82 parsed_details = { | |
| 83 'device_names': sorted(list(set([v.split(':')[0] for v in details]))), | |
|
Paweł Hajdan Jr.
2015/02/10 08:34:12
Consider extracting the common logic to a helper (
shatch
2015/02/10 16:42:57
Done.
| |
| 84 'build_versions': sorted(list(set([v.split(':')[1] for v in details]))), | |
| 85 'build_types': sorted(list(set([v.split(':')[2] for v in details]))), | |
| 86 } | |
| 87 | |
| 88 for k, v in parsed_details.iteritems(): | |
| 89 if len(v) == 1: | |
| 90 results[k] = v[0] | |
| 91 else: | |
| 92 results[k] = 'MISMATCH' | |
| 93 results['%s_list' % k] = v | |
| 94 failures.append(k) | |
| 95 | |
| 96 return results | |
| 97 | |
| 98 | |
| 99 def main_run(args): | |
| 100 failures = [] | |
| 101 host_info = {} | |
| 102 host_info['os_system'] = platform.system() | |
| 103 host_info['os_release'] = platform.release() | |
| 104 | |
| 105 host_info['processor'] = platform.processor() | |
| 106 host_info['num_cpus'] = get_num_cpus() | |
| 107 if host_info['num_cpus'] == 'unknown': | |
|
Paweł Hajdan Jr.
2015/02/10 08:34:12
Why not put this into get_num_cpus?
shatch
2015/02/10 16:42:57
Done.
| |
| 108 failures.append('get_num_cpus') | |
| 109 | |
| 110 host_info['free_disk_space'] = get_free_disk_space() | |
| 111 if host_info['free_disk_space'] == 0: | |
|
Paweł Hajdan Jr.
2015/02/10 08:34:12
Why not put this into get_free_disk_space?
shatch
2015/02/10 16:42:57
Done.
| |
| 112 failures.append('get_free_disk_space') | |
| 113 | |
| 114 host_info['python_version'] = platform.python_version() | |
| 115 host_info['python_path'] = sys.executable | |
| 116 | |
| 117 host_info['devices'] = get_device_info(args, failures) | |
| 118 | |
| 119 json.dump({ | |
| 120 'valid': bool(not failures), | |
| 121 'failures': failures, | |
| 122 'host_info': host_info, | |
|
shatch
2015/02/04 15:46:18
I'm not really clear what's allowed in the json ou
Paweł Hajdan Jr.
2015/02/10 08:34:12
Maybe prefix it with '_' to indicate it's a custom
shatch
2015/02/10 16:42:57
Done.
| |
| 123 }, args.output) | |
| 124 | |
| 125 return len(failures) != 0 | |
| 126 | |
| 127 | |
| 128 def main_compile_targets(args): | |
| 129 json.dump([], args.output) | |
| 130 | |
| 131 | |
| 132 if __name__ == '__main__': | |
| 133 funcs = { | |
| 134 'run': main_run, | |
| 135 'compile_targets': main_compile_targets, | |
| 136 } | |
| 137 sys.exit(common.run_script(sys.argv[1:], funcs)) | |
| OLD | NEW |