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

Side by Side Diff: build/android/pylib/device/device_utils.py

Issue 751063002: Allow RunShellCommand to work even with very large commands (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: less mind-bendy version Created 6 years 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 """Provides a variety of device interactions based on adb. 5 """Provides a variety of device interactions based on adb.
6 6
7 Eventually, this will be based on adb_wrapper. 7 Eventually, this will be based on adb_wrapper.
8 """ 8 """
9 # pylint: disable=W0613 9 # pylint: disable=W0613
10 10
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 more lines. 420 more lines.
421 CommandTimeoutError on timeout. 421 CommandTimeoutError on timeout.
422 DeviceUnreachableError on missing device. 422 DeviceUnreachableError on missing device.
423 """ 423 """
424 def env_quote(key, value): 424 def env_quote(key, value):
425 if not DeviceUtils._VALID_SHELL_VARIABLE.match(key): 425 if not DeviceUtils._VALID_SHELL_VARIABLE.match(key):
426 raise KeyError('Invalid shell variable name %r' % key) 426 raise KeyError('Invalid shell variable name %r' % key)
427 # using double quotes here to allow interpolation of shell variables 427 # using double quotes here to allow interpolation of shell variables
428 return '%s=%s' % (key, cmd_helper.DoubleQuote(value)) 428 return '%s=%s' % (key, cmd_helper.DoubleQuote(value))
429 429
430 def do_run(cmd):
431 try:
432 return self.adb.Shell(cmd)
433 except device_errors.AdbCommandFailedError as exc:
434 if check_return:
435 raise
436 else:
437 return exc.output
438
430 if not isinstance(cmd, basestring): 439 if not isinstance(cmd, basestring):
431 cmd = ' '.join(cmd_helper.SingleQuote(s) for s in cmd) 440 cmd = ' '.join(cmd_helper.SingleQuote(s) for s in cmd)
432 if env: 441 if env:
433 env = ' '.join(env_quote(k, v) for k, v in env.iteritems()) 442 env = ' '.join(env_quote(k, v) for k, v in env.iteritems())
434 cmd = '%s %s' % (env, cmd) 443 cmd = '%s %s' % (env, cmd)
435 if cwd: 444 if cwd:
436 cmd = 'cd %s && %s' % (cmd_helper.SingleQuote(cwd), cmd) 445 cmd = 'cd %s && %s' % (cmd_helper.SingleQuote(cwd), cmd)
437 if as_root and self.NeedsSU(): 446 if as_root and self.NeedsSU():
438 # "su -c sh -c" allows using shell features in |cmd| 447 # "su -c sh -c" allows using shell features in |cmd|
439 cmd = 'su -c sh -c %s' % cmd_helper.SingleQuote(cmd) 448 cmd = 'su -c sh -c %s' % cmd_helper.SingleQuote(cmd)
440 if timeout is None: 449 if timeout is None:
441 timeout = self._default_timeout 450 timeout = self._default_timeout
442 451
443 try: 452 if len(cmd) < 512:
jbudorick 2014/11/25 17:05:26 We should de-magic 512. "MAX_ADB_COMMAND_LENGTH" o
444 output = self.adb.Shell(cmd) 453 output = do_run(cmd)
445 except device_errors.AdbCommandFailedError as e: 454 else:
446 if check_return: 455 with device_temp_file.DeviceTempFile(self, suffix='.sh') as script:
447 raise 456 # |as_root| must be False, and |force_push| must be True,
448 else: 457 # otherwise WriteFile may introduce infinite recursion
jbudorick 2014/11/25 17:05:26 This worries me. It's the same kind of cyclical de
449 output = e.output 458 self.WriteFile(script.name, cmd, as_root=False, force_push=True)
perezju 2014/11/25 16:25:33 look, our first non-artificial use of force_push!
459 output = do_run('sh %s' % script.name_quoted)
450 460
451 output = output.splitlines() 461 output = output.splitlines()
452 if single_line: 462 if single_line:
453 if not output: 463 if not output:
454 return '' 464 return ''
455 elif len(output) == 1: 465 elif len(output) == 1:
456 return output[0] 466 return output[0]
457 else: 467 else:
458 msg = 'one line of output was expected, but got: %s' 468 msg = 'one line of output was expected, but got: %s'
459 raise device_errors.CommandFailedError(msg % output, str(self)) 469 raise device_errors.CommandFailedError(msg % output, str(self))
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 Returns: 1166 Returns:
1157 A Parallelizer operating over |devices|. 1167 A Parallelizer operating over |devices|.
1158 """ 1168 """
1159 if not devices or len(devices) == 0: 1169 if not devices or len(devices) == 0:
1160 devices = pylib.android_commands.GetAttachedDevices() 1170 devices = pylib.android_commands.GetAttachedDevices()
1161 parallelizer_type = (parallelizer.Parallelizer if async 1171 parallelizer_type = (parallelizer.Parallelizer if async
1162 else parallelizer.SyncParallelizer) 1172 else parallelizer.SyncParallelizer)
1163 return parallelizer_type([ 1173 return parallelizer_type([
1164 d if isinstance(d, DeviceUtils) else DeviceUtils(d) 1174 d if isinstance(d, DeviceUtils) else DeviceUtils(d)
1165 for d in devices]) 1175 for d in devices])
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/device/device_utils_test.py » ('j') | build/android/pylib/utils/device_temp_file.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698