OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 datetime | 5 import datetime |
6 import os | 6 import os |
7 import logging | 7 import logging |
8 import platform | 8 import platform |
9 import random | 9 import random |
10 import subprocess | 10 import subprocess |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 def GetShellReturnCode(self): | 194 def GetShellReturnCode(self): |
195 """Gets the return code of the BattOr agent shell.""" | 195 """Gets the return code of the BattOr agent shell.""" |
196 rc = self._battor_shell.poll() | 196 rc = self._battor_shell.poll() |
197 return rc | 197 return rc |
198 | 198 |
199 def StartShell(self): | 199 def StartShell(self): |
200 """Start BattOr binary shell.""" | 200 """Start BattOr binary shell.""" |
201 assert not self._battor_shell, 'Attempting to start running BattOr shell.' | 201 assert not self._battor_shell, 'Attempting to start running BattOr shell.' |
202 | 202 |
203 battor_cmd = [self._battor_agent_binary] | 203 battor_cmd = [self._battor_agent_binary] |
204 if self._serial_log_bucket: | 204 # if self._serial_log_bucket: |
205 # Create and immediately close a temp file in order to get a filename | 205 # Create and immediately close a temp file in order to get a filename |
206 # for the serial log. | 206 # for the serial log. |
207 self._serial_log_file = tempfile.NamedTemporaryFile(delete=False) | 207 self._serial_log_file = tempfile.NamedTemporaryFile(delete=False) |
208 self._serial_log_file.close() | 208 self._serial_log_file.close() |
209 battor_cmd.append('--battor-serial-log=%s' % self._serial_log_file.name) | 209 print "Serial log at %s" % (self._serial_log_file.name) |
| 210 battor_cmd.append('--battor-serial-log=%s' % self._serial_log_file.name) |
210 if self._battor_path: | 211 if self._battor_path: |
211 battor_cmd.append('--battor-path=%s' % self._battor_path) | 212 battor_cmd.append('--battor-path=%s' % self._battor_path) |
212 self._battor_shell = self._StartShellImpl(battor_cmd) | 213 self._battor_shell = self._StartShellImpl(battor_cmd) |
213 assert self.GetShellReturnCode() is None, 'Shell failed to start.' | 214 assert self.GetShellReturnCode() is None, 'Shell failed to start.' |
214 | 215 |
215 def StopShell(self, timeout=None): | 216 def StopShell(self, timeout=None): |
216 """Stop BattOr binary shell.""" | 217 """Stop BattOr binary shell.""" |
217 assert self._battor_shell, 'Attempting to stop a non-running BattOr shell.' | 218 assert self._battor_shell, 'Attempting to stop a non-running BattOr shell.' |
218 assert not self._tracing, 'Attempting to stop a BattOr shell while tracing.' | 219 assert not self._tracing, 'Attempting to stop a BattOr shell while tracing.' |
219 timeout = timeout if timeout else DEFAULT_SHELL_CLOSE_TIMEOUT_S | 220 timeout = timeout if timeout else DEFAULT_SHELL_CLOSE_TIMEOUT_S |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 'Outputted: %s' % (cmd, status)) | 354 'Outputted: %s' % (cmd, status)) |
354 return status | 355 return status |
355 | 356 |
356 def _StartShellImpl(self, battor_cmd): | 357 def _StartShellImpl(self, battor_cmd): |
357 return subprocess.Popen( | 358 return subprocess.Popen( |
358 battor_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, | 359 battor_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, |
359 stderr=subprocess.STDOUT, shell=False) | 360 stderr=subprocess.STDOUT, shell=False) |
360 | 361 |
361 def _UploadSerialLogToCloudStorage(self): | 362 def _UploadSerialLogToCloudStorage(self): |
362 """Uploads the BattOr serial log to cloud storage.""" | 363 """Uploads the BattOr serial log to cloud storage.""" |
363 if not self._serial_log_file or not cloud_storage.IsNetworkIOEnabled(): | 364 return False |
364 return | 365 # if not self._serial_log_file |
| 366 # return |
365 | 367 |
366 remote_path = ('battor-serial-log-%s-%d.txt' % ( | 368 # remote_path = ('battor-serial-log-%s-%d.txt' % ( |
367 datetime.datetime.now().strftime('%Y-%m-%d_%H-%M.txt'), | 369 # datetime.datetime.now().strftime('%Y-%m-%d_%H-%M.txt'), |
368 random.randint(1, 100000))) | 370 # random.randint(1, 100000))) |
369 | 371 |
370 try: | 372 # try: |
371 cloud_url = cloud_storage.Insert( | 373 # cloud_url = cloud_storage.Insert( |
372 self._serial_log_bucket, remote_path, self._serial_log_file.name) | 374 # self._serial_log_bucket, remote_path, self._serial_log_file.name) |
373 sys.stderr.write('View BattOr serial log at %s\n' % cloud_url) | 375 # sys.stderr.write('View BattOr serial log at %s\n' % cloud_url) |
374 except cloud_storage.PermissionError as e: | 376 # except cloud_storage.PermissionError as e: |
375 logging.error('Cannot upload BattOr serial log file to cloud storage due ' | 377 # logging.error('Cannot upload BattOr serial log file to cloud storage due
' |
376 'to permission error: %s' % e.message) | 378 # 'to permission error: %s' % e.message) |
377 | 379 |
378 def GetFirmwareGitHash(self): | 380 def GetFirmwareGitHash(self): |
379 """Gets the git hash for the BattOr firmware. | 381 """Gets the git hash for the BattOr firmware. |
380 | 382 |
381 Returns: Git hash for firmware currently on the BattOr. | 383 Returns: Git hash for firmware currently on the BattOr. |
382 Also sets self._git_hash to this value. | 384 Also sets self._git_hash to this value. |
383 | 385 |
384 Raises: ValueException if the git hash is not in hex. | 386 Raises: ValueException if the git hash is not in hex. |
385 """ | 387 """ |
386 assert self._battor_shell, ('Must start shell before getting firmware git ' | 388 assert self._battor_shell, ('Must start shell before getting firmware git ' |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 except subprocess.CalledProcessError as e: | 423 except subprocess.CalledProcessError as e: |
422 raise BattOrFlashError('BattOr flash failed with return code %s.' | 424 raise BattOrFlashError('BattOr flash failed with return code %s.' |
423 % e.returncode) | 425 % e.returncode) |
424 | 426 |
425 self._git_hash = None | 427 self._git_hash = None |
426 return True | 428 return True |
427 | 429 |
428 | 430 |
429 class BattOrFlashError(Exception): | 431 class BattOrFlashError(Exception): |
430 pass | 432 pass |
OLD | NEW |