OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import fnmatch | 5 import fnmatch |
6 import json | 6 import json |
7 import os | 7 import os |
8 import pipes | 8 import pipes |
9 import shlex | 9 import shlex |
10 import shutil | 10 import shutil |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 outfile.write(new_dump) | 74 outfile.write(new_dump) |
75 | 75 |
76 def ReadJson(path): | 76 def ReadJson(path): |
77 with open(path, 'r') as jsonfile: | 77 with open(path, 'r') as jsonfile: |
78 return json.load(jsonfile) | 78 return json.load(jsonfile) |
79 | 79 |
80 | 80 |
81 # This can be used in most cases like subprocess.check_call. The output, | 81 # This can be used in most cases like subprocess.check_call. The output, |
82 # particularly when the command fails, better highlights the command's failure. | 82 # particularly when the command fails, better highlights the command's failure. |
83 # This call will directly exit on a failure in the subprocess so that no python | 83 # This call will directly exit on a failure in the subprocess so that no python |
84 # stacktrace is printed after the output of the failed command. | 84 # stacktrace is printed after the output of the failed command (and will |
| 85 # instead print a python stack trace before the output of the failed command) |
85 def CheckCallDie(args, suppress_output=False, cwd=None): | 86 def CheckCallDie(args, suppress_output=False, cwd=None): |
86 if not cwd: | 87 if not cwd: |
87 cwd = os.getcwd() | 88 cwd = os.getcwd() |
88 | 89 |
89 child = subprocess.Popen(args, | 90 child = subprocess.Popen(args, |
90 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=cwd) | 91 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=cwd) |
91 | 92 |
92 stdout, _ = child.communicate() | 93 stdout, _ = child.communicate() |
93 | 94 |
94 if child.returncode: | 95 if child.returncode: |
(...skipping 26 matching lines...) Expand all Loading... |
121 | 122 |
122 def IsTimeStale(output, inputs): | 123 def IsTimeStale(output, inputs): |
123 if not os.path.exists(output): | 124 if not os.path.exists(output): |
124 return True | 125 return True |
125 | 126 |
126 output_time = GetModifiedTime(output) | 127 output_time = GetModifiedTime(output) |
127 for input in inputs: | 128 for input in inputs: |
128 if GetModifiedTime(input) > output_time: | 129 if GetModifiedTime(input) > output_time: |
129 return True | 130 return True |
130 return False | 131 return False |
| 132 |
| 133 |
| 134 def IsDeviceReady(): |
| 135 device_state = CheckCallDie(['adb', 'get-state'], suppress_output=True) |
| 136 return device_state.strip() == 'device' |
| 137 |
| 138 |
| 139 def PrintWarning(message): |
| 140 print 'WARNING: ' + message |
| 141 |
| 142 |
| 143 def PrintBigWarning(message): |
| 144 print '***** ' * 8 |
| 145 PrintWarning(message) |
| 146 print '***** ' * 8 |
OLD | NEW |