| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 logging | 5 import logging |
| 6 | 6 |
| 7 from devil.android import device_errors | 7 from devil.android import device_errors |
| 8 | 8 |
| 9 | 9 |
| 10 class FlagChanger(object): | 10 class FlagChanger(object): |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 """Initializes the FlagChanger and records the original arguments. | 21 """Initializes the FlagChanger and records the original arguments. |
| 22 | 22 |
| 23 Args: | 23 Args: |
| 24 device: A DeviceUtils instance. | 24 device: A DeviceUtils instance. |
| 25 cmdline_file: Path to the command line file on the device. | 25 cmdline_file: Path to the command line file on the device. |
| 26 """ | 26 """ |
| 27 self._device = device | 27 self._device = device |
| 28 self._cmdline_file = cmdline_file | 28 self._cmdline_file = cmdline_file |
| 29 | 29 |
| 30 # Save the original flags. | 30 # Save the original flags. |
| 31 try: | 31 self._orig_line = '' |
| 32 self._orig_line = self._device.ReadFile(self._cmdline_file).strip() | 32 if self._device.PathExists(self._cmdline_file): |
| 33 except device_errors.CommandFailedError: | 33 try: |
| 34 self._orig_line = '' | 34 self._orig_line = self._device.ReadFile(self._cmdline_file).strip() |
| 35 except device_errors.CommandFailedError: |
| 36 pass |
| 35 | 37 |
| 36 # Parse out the flags into a list to facilitate adding and removing flags. | 38 # Parse out the flags into a list to facilitate adding and removing flags. |
| 37 self._current_flags = self._TokenizeFlags(self._orig_line) | 39 self._current_flags = self._TokenizeFlags(self._orig_line) |
| 38 | 40 |
| 39 def Get(self): | 41 def Get(self): |
| 40 """Returns list of current flags.""" | 42 """Returns list of current flags.""" |
| 41 return self._current_flags | 43 return self._current_flags |
| 42 | 44 |
| 43 def Set(self, flags): | 45 def Set(self, flags): |
| 44 """Replaces all flags on the current command line with the flags given. | 46 """Replaces all flags on the current command line with the flags given. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 153 |
| 152 # Tack on the last flag. | 154 # Tack on the last flag. |
| 153 if not current_flag: | 155 if not current_flag: |
| 154 if within_quotations: | 156 if within_quotations: |
| 155 logging.warn('Unterminated quoted argument: ' + line) | 157 logging.warn('Unterminated quoted argument: ' + line) |
| 156 else: | 158 else: |
| 157 tokenized_flags.append(current_flag) | 159 tokenized_flags.append(current_flag) |
| 158 | 160 |
| 159 # Return everything but the program name. | 161 # Return everything but the program name. |
| 160 return tokenized_flags[1:] | 162 return tokenized_flags[1:] |
| OLD | NEW |