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

Unified Diff: build/android/pylib/cmd_helper.py

Issue 659533002: New run shell implementation for DeviceUtils (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed RunShellCommand call in instrumentation runner Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: build/android/pylib/cmd_helper.py
diff --git a/build/android/pylib/cmd_helper.py b/build/android/pylib/cmd_helper.py
index aba00be735368e9e931e321b14bef1d46ad1fbf3..b99db589d516b1baf1f980eb7a6f0798631c5d82 100644
--- a/build/android/pylib/cmd_helper.py
+++ b/build/android/pylib/cmd_helper.py
@@ -9,6 +9,7 @@ import os
import pipes
import select
import signal
+import string
import StringIO
import subprocess
import time
@@ -19,6 +20,27 @@ try:
except ImportError:
fcntl = None
+_SafeShellChars = frozenset(string.ascii_letters + string.digits + '@%_-+=:,./')
+
+quote = pipes.quote
jbudorick 2014/10/17 09:04:52 I don't think I like this. Let callers use pipes.q
+
+def dquote(s):
jbudorick 2014/10/17 09:04:53 While I understand that you're mimicking pipes.quo
perezju 2014/10/17 11:17:09 Done.
+ """Return an escaped version of the string using double quotes.
+
+ A sibling to pipes.quote that uses double rather than single quotes.
+ Meant to be used to quote strings which may contain unsafe characters (e.g.
+ spaces), while retaining some shell features such as variable interpolation.
+
+ The set of characters that retain their special meaning may depend on the
+ shell implementation. It usually includes: '$', '`', '\', '!', '*', and '@'.
+ """
+ if not s:
jbudorick 2014/10/17 09:04:52 Also, this function should have some unit tests.
perezju 2014/10/17 11:17:09 Done.
+ return '""'
+ if all(c in _SafeShellChars for c in s):
+ return s
+ else:
+ return '"' + s.replace('"', '\\"') + '"'
+
def Popen(args, stdout=None, stderr=None, shell=None, cwd=None, env=None):
return subprocess.Popen(
@@ -88,7 +110,7 @@ def GetCmdStatusAndOutput(args, cwd=None, shell=False):
elif shell:
raise Exception('array args must be run with shell=False')
else:
- args_repr = ' '.join(map(pipes.quote, args))
+ args_repr = ' '.join(map(quote, args))
s = '[host]'
if cwd:
« no previous file with comments | « no previous file | build/android/pylib/device/adb_wrapper.py » ('j') | build/android/pylib/device/device_errors.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698