Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: build/android/pylib/flag_changer.py

Issue 358993003: [Android] Switch to DeviceUtils versions of file functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/pylib/device/device_utils_test.py ('k') | build/android/pylib/forwarder.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import pylib.android_commands 7 import pylib.android_commands
8 import pylib.device.device_utils 8 import pylib.device.device_utils
9 9
10 10
(...skipping 14 matching lines...) Expand all
25 device: A DeviceUtils instance. 25 device: A DeviceUtils instance.
26 cmdline_file: Path to the command line file on the device. 26 cmdline_file: Path to the command line file on the device.
27 """ 27 """
28 # TODO(jbudorick) Remove once telemetry switches over. 28 # TODO(jbudorick) Remove once telemetry switches over.
29 if isinstance(device, pylib.android_commands.AndroidCommands): 29 if isinstance(device, pylib.android_commands.AndroidCommands):
30 device = pylib.device.device_utils.DeviceUtils(device) 30 device = pylib.device.device_utils.DeviceUtils(device)
31 self._device = device 31 self._device = device
32 self._cmdline_file = cmdline_file 32 self._cmdline_file = cmdline_file
33 33
34 # Save the original flags. 34 # Save the original flags.
35 self._orig_line = self._device.old_interface.GetFileContents( 35 self._orig_line = self._device.ReadFile(self._cmdline_file)
36 self._cmdline_file)
37 if self._orig_line: 36 if self._orig_line:
38 self._orig_line = self._orig_line[0].strip() 37 self._orig_line = self._orig_line[0].strip()
39 38
40 # Parse out the flags into a list to facilitate adding and removing flags. 39 # Parse out the flags into a list to facilitate adding and removing flags.
41 self._current_flags = self._TokenizeFlags(self._orig_line) 40 self._current_flags = self._TokenizeFlags(self._orig_line)
42 41
43 def Get(self): 42 def Get(self):
44 """Returns list of current flags.""" 43 """Returns list of current flags."""
45 return self._current_flags 44 return self._current_flags
46 45
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 94
96 def _UpdateCommandLineFile(self): 95 def _UpdateCommandLineFile(self):
97 """Writes out the command line to the file, or removes it if empty.""" 96 """Writes out the command line to the file, or removes it if empty."""
98 logging.info('Current flags: %s', self._current_flags) 97 logging.info('Current flags: %s', self._current_flags)
99 # Root is not required to write to /data/local/tmp/. 98 # Root is not required to write to /data/local/tmp/.
100 use_root = '/data/local/tmp/' not in self._cmdline_file 99 use_root = '/data/local/tmp/' not in self._cmdline_file
101 if self._current_flags: 100 if self._current_flags:
102 # The first command line argument doesn't matter as we are not actually 101 # The first command line argument doesn't matter as we are not actually
103 # launching the chrome executable using this command line. 102 # launching the chrome executable using this command line.
104 cmd_line = ' '.join(['_'] + self._current_flags) 103 cmd_line = ' '.join(['_'] + self._current_flags)
105 if use_root: 104 self._device.WriteFile(
106 self._device.old_interface.SetProtectedFileContents( 105 self._cmdline_file, cmd_line, as_root=use_root)
107 self._cmdline_file, cmd_line) 106 file_contents = self._device.ReadFile(
108 file_contents = self._device.old_interface.GetProtectedFileContents( 107 self._cmdline_file, as_root=use_root)
109 self._cmdline_file)
110 else:
111 self._device.old_interface.SetFileContents(self._cmdline_file, cmd_line)
112 file_contents = self._device.old_interface.GetFileContents(
113 self._cmdline_file)
114 assert len(file_contents) == 1 and file_contents[0] == cmd_line, ( 108 assert len(file_contents) == 1 and file_contents[0] == cmd_line, (
115 'Failed to set the command line file at %s' % self._cmdline_file) 109 'Failed to set the command line file at %s' % self._cmdline_file)
116 else: 110 else:
117 self._device.RunShellCommand('rm ' + self._cmdline_file, 111 self._device.RunShellCommand('rm ' + self._cmdline_file,
118 as_root=use_root) 112 as_root=use_root)
119 assert ( 113 assert not self._device.FileExists(self._cmdline_file), (
120 not self._device.old_interface.FileExistsOnDevice(
121 self._cmdline_file)), (
122 'Failed to remove the command line file at %s' % self._cmdline_file) 114 'Failed to remove the command line file at %s' % self._cmdline_file)
123 115
124 @staticmethod 116 @staticmethod
125 def _TokenizeFlags(line): 117 def _TokenizeFlags(line):
126 """Changes the string containing the command line into a list of flags. 118 """Changes the string containing the command line into a list of flags.
127 119
128 Follows similar logic to CommandLine.java::tokenizeQuotedArguments: 120 Follows similar logic to CommandLine.java::tokenizeQuotedArguments:
129 * Flags are split using whitespace, unless the whitespace is within a 121 * Flags are split using whitespace, unless the whitespace is within a
130 pair of quotation marks. 122 pair of quotation marks.
131 * Unlike the Java version, we keep the quotation marks around switch 123 * Unlike the Java version, we keep the quotation marks around switch
(...skipping 30 matching lines...) Expand all
162 154
163 # Tack on the last flag. 155 # Tack on the last flag.
164 if not current_flag: 156 if not current_flag:
165 if within_quotations: 157 if within_quotations:
166 logging.warn('Unterminated quoted argument: ' + line) 158 logging.warn('Unterminated quoted argument: ' + line)
167 else: 159 else:
168 tokenized_flags.append(current_flag) 160 tokenized_flags.append(current_flag)
169 161
170 # Return everything but the program name. 162 # Return everything but the program name.
171 return tokenized_flags[1:] 163 return tokenized_flags[1:]
OLDNEW
« no previous file with comments | « build/android/pylib/device/device_utils_test.py ('k') | build/android/pylib/forwarder.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698