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

Unified Diff: build/android/devil/utils/cmd_helper.py

Issue 1397663002: DeviceUtils.StartInstrumentation: Shrink command-line (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add blank line Created 5 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
« no previous file with comments | « build/android/devil/android/device_utils_test.py ('k') | build/android/devil/utils/cmd_helper_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/devil/utils/cmd_helper.py
diff --git a/build/android/devil/utils/cmd_helper.py b/build/android/devil/utils/cmd_helper.py
index 8f3708bead2aad96d1c21295c63c26f098605860..57e8987558d4a3209c1be35d6f905ed3485cecc4 100644
--- a/build/android/devil/utils/cmd_helper.py
+++ b/build/android/devil/utils/cmd_helper.py
@@ -67,6 +67,27 @@ def DoubleQuote(s):
return '"' + s.replace('"', '\\"') + '"'
+def ShrinkToSnippet(cmd_parts, var_name, var_value):
+ """Constructs a shell snippet for a command using a variable to shrink it.
+
+ Takes into account all quoting that needs to happen.
+
+ Args:
+ cmd_parts: A list of command arguments.
+ var_name: The variable that holds var_value.
+ var_value: The string to replace in cmd_parts with $var_name
+
+ Returns:
+ A shell snippet that does not include setting the variable.
+ """
+ def shrink(value):
+ parts = (x and SingleQuote(x) for x in value.split(var_value))
+ with_substitutions = ('"$%s"' % var_name).join(parts)
+ return with_substitutions or "''"
+
+ return ' '.join(shrink(part) for part in cmd_parts)
+
+
def Popen(args, stdout=None, stderr=None, shell=None, cwd=None, env=None):
return subprocess.Popen(
args=args, cwd=cwd, stdout=stdout, stderr=stderr,
« no previous file with comments | « build/android/devil/android/device_utils_test.py ('k') | build/android/devil/utils/cmd_helper_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698