Chromium Code Reviews| 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..43dfb8989cb16219448f4455747c8cd4dad2d827 100644 |
| --- a/build/android/devil/utils/cmd_helper.py |
| +++ b/build/android/devil/utils/cmd_helper.py |
| @@ -67,6 +67,26 @@ 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) |
|
jbudorick
2015/10/14 17:59:09
nit: newline before this line
agrieve
2015/10/14 18:02:05
Done.
|
| + |
| + |
| def Popen(args, stdout=None, stderr=None, shell=None, cwd=None, env=None): |
| return subprocess.Popen( |
| args=args, cwd=cwd, stdout=stdout, stderr=stderr, |