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(failures): | |
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 failures.append('get_free_disk_space: OS %s not supported.' % os.name) | |
35 return 0 | |
36 | |
37 | |
38 def get_num_cpus(failures): | |
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 failures.append('get_num_cpus') | |
48 return 'unknown' | |
49 | |
50 | |
51 def get_device_info(args, failures): | |
52 """Parses the device info for each attached device, and returns a summary | |
53 of the device info and any mismatches. | |
54 | |
55 Returns: | |
56 A dict indicating the result. | |
57 """ | |
58 if not is_linux(): | |
59 return {} | |
60 | |
61 with common.temporary_file() as tempfile_path: | |
62 rc = common.run_command([ | |
63 sys.executable, | |
64 os.path.join(args.paths['checkout'], | |
65 'build', | |
66 'android', | |
67 'buildbot', | |
68 'bb_device_status_check.py'), | |
69 '--json-output', tempfile_path]) | |
70 | |
71 if rc: | |
72 failures.append('bb_device_status_check') | |
73 return {} | |
74 | |
75 with open(tempfile_path, 'r') as src: | |
76 device_info = json.load(src) | |
77 | |
78 results = {} | |
79 results['devices'] = sorted(v['serial'] for v in device_info) | |
80 | |
81 details = [v['build_detail'] for v in device_info] | |
82 | |
83 def unique_build_details(index): | |
84 return sorted(list(set([v.split(':')[index] for v in details]))) | |
85 | |
86 parsed_details = { | |
87 'device_names': unique_build_details(0), | |
88 'build_versions': unique_build_details(1), | |
89 'build_types': unique_build_details(2), | |
90 } | |
91 | |
92 for k, v in parsed_details.iteritems(): | |
93 if len(v) == 1: | |
94 results[k] = v[0] | |
95 else: | |
96 results[k] = 'MISMATCH' | |
97 results['%s_list' % k] = v | |
98 failures.append(k) | |
99 | |
100 return results | |
101 | |
102 | |
103 def main_run(args): | |
104 failures = [] | |
105 host_info = {} | |
106 host_info['os_system'] = platform.system() | |
107 host_info['os_release'] = platform.release() | |
108 | |
109 host_info['processor'] = platform.processor() | |
110 host_info['num_cpus'] = get_num_cpus(failures) | |
111 host_info['free_disk_space'] = get_free_disk_space(failures) | |
112 | |
113 host_info['python_version'] = platform.python_version() | |
114 host_info['python_path'] = sys.executable | |
115 | |
116 host_info['devices'] = get_device_info(args, failures) | |
117 | |
118 json.dump({ | |
119 'valid': bool(not failures), | |
Paweł Hajdan Jr.
2015/02/17 16:07:01
This is _valid_ , not e.g. "successful". Looks lik
shatch
2015/02/17 16:49:22
Done.
| |
120 'failures': failures, | |
121 '_host_info': host_info, | |
122 }, args.output) | |
123 | |
124 return len(failures) != 0 | |
125 | |
126 | |
127 def main_compile_targets(args): | |
128 json.dump([], args.output) | |
129 | |
130 | |
131 if __name__ == '__main__': | |
132 funcs = { | |
133 'run': main_run, | |
134 'compile_targets': main_compile_targets, | |
135 } | |
136 sys.exit(common.run_script(sys.argv[1:], funcs)) | |
OLD | NEW |