Chromium Code Reviews| Index: testing/scripts/host_info.py |
| diff --git a/testing/scripts/host_info.py b/testing/scripts/host_info.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..9d785b601872be3c79ac3e07f79feb3d0797494c |
| --- /dev/null |
| +++ b/testing/scripts/host_info.py |
| @@ -0,0 +1,137 @@ |
| +#!/usr/bin/env python |
| +# Copyright 2015 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import json |
| +import multiprocessing |
| +import os |
| +import platform |
| +import subprocess |
| +import sys |
| + |
| + |
| +import common |
| + |
| + |
| +def is_linux(): |
| + return sys.platform.startswith('linux') |
| + |
| + |
| +def get_free_disk_space(): |
| + """Returns the amount of free space on the current disk, in GiB. |
| + |
| + Returns: |
| + The amount of free space on the current disk, measured in GiB. |
| + """ |
| + if os.name == 'posix': |
| + # Stat the current path for info on the current disk. |
| + stat_result = os.statvfs('.') |
| + # Multiply block size by number of free blocks, express in GiB. |
| + return stat_result.f_frsize * stat_result.f_bavail / ( |
| + 1024.0 / 1024.0 / 1024.0) |
| + |
| + 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
|
| + return 0 |
| + |
| + |
| +def get_num_cpus(): |
| + """Returns the number of logical CPUs on this machine. |
| + |
| + Returns: |
| + The number of logical CPUs on this machine, or 'unknown' if indeterminate. |
| + """ |
| + try: |
| + return multiprocessing.cpu_count() |
| + except NotImplementedError: |
| + return 'unknown' |
| + |
| + |
| +def get_device_info(args, failures): |
| + """Parses the device info for each attached device, and returns a summary |
| + of the device info and any mismatches. |
| + |
| + Returns: |
| + A dict indicating the result. |
| + """ |
| + if not is_linux(): |
| + return {} |
| + |
| + with common.temporary_file() as tempfile_path: |
| + rc = common.run_command([ |
| + sys.executable, |
| + os.path.join(args.paths['checkout'], |
| + 'build', |
| + 'android', |
| + 'buildbot', |
| + 'bb_device_status_check.py'), |
| + '--json-output', tempfile_path]) |
| + |
| + if rc: |
| + failures.append('bb_device_status_check') |
| + return {} |
| + |
| + with open(tempfile_path, 'r') as src: |
| + device_info = json.load(src) |
| + |
| + results = {} |
| + results['devices'] = sorted(v['serial'] for v in device_info) |
| + |
| + details = [v['build_detail'] for v in device_info] |
| + |
| + parsed_details = { |
| + '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.
|
| + 'build_versions': sorted(list(set([v.split(':')[1] for v in details]))), |
| + 'build_types': sorted(list(set([v.split(':')[2] for v in details]))), |
| + } |
| + |
| + for k, v in parsed_details.iteritems(): |
| + if len(v) == 1: |
| + results[k] = v[0] |
| + else: |
| + results[k] = 'MISMATCH' |
| + results['%s_list' % k] = v |
| + failures.append(k) |
| + |
| + return results |
| + |
| + |
| +def main_run(args): |
| + failures = [] |
| + host_info = {} |
| + host_info['os_system'] = platform.system() |
| + host_info['os_release'] = platform.release() |
| + |
| + host_info['processor'] = platform.processor() |
| + host_info['num_cpus'] = get_num_cpus() |
| + 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.
|
| + failures.append('get_num_cpus') |
| + |
| + host_info['free_disk_space'] = get_free_disk_space() |
| + 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.
|
| + failures.append('get_free_disk_space') |
| + |
| + host_info['python_version'] = platform.python_version() |
| + host_info['python_path'] = sys.executable |
| + |
| + host_info['devices'] = get_device_info(args, failures) |
| + |
| + json.dump({ |
| + 'valid': bool(not failures), |
| + 'failures': failures, |
| + '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.
|
| + }, args.output) |
| + |
| + return len(failures) != 0 |
| + |
| + |
| +def main_compile_targets(args): |
| + json.dump([], args.output) |
| + |
| + |
| +if __name__ == '__main__': |
| + funcs = { |
| + 'run': main_run, |
| + 'compile_targets': main_compile_targets, |
| + } |
| + sys.exit(common.run_script(sys.argv[1:], funcs)) |