mirror of https://github.com/zulip/zulip.git
scripts: Use shell quoting when displaying commands to be run.
This way, commands with arguments containing whitespace or metacharacters are unambiguously readable. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
parent
de5e3d3fbd
commit
510c97d861
|
@ -2,6 +2,7 @@
|
|||
|
||||
import sys
|
||||
import glob
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
import logging
|
||||
|
@ -17,7 +18,7 @@ logger = logging.getLogger(__name__)
|
|||
def run(args, dry_run=False):
|
||||
# type: (List[str], bool) -> str
|
||||
if dry_run:
|
||||
print("Would have run: " + " ".join(args))
|
||||
print("Would have run: " + " ".join(map(shlex.quote, args)))
|
||||
return ""
|
||||
|
||||
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||
|
|
|
@ -7,6 +7,7 @@ import logging
|
|||
import os
|
||||
import pwd
|
||||
import re
|
||||
import shlex
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
@ -153,7 +154,7 @@ def release_deployment_lock():
|
|||
def run(args, **kwargs):
|
||||
# type: (Sequence[str], **Any) -> None
|
||||
# Output what we're doing in the `set -x` style
|
||||
print("+ %s" % (" ".join(args)))
|
||||
print("+ %s" % (" ".join(map(shlex.quote, args)),))
|
||||
|
||||
if kwargs.get('shell'):
|
||||
# With shell=True we can only pass string to Popen
|
||||
|
@ -163,7 +164,8 @@ def run(args, **kwargs):
|
|||
subprocess.check_call(args, **kwargs)
|
||||
except subprocess.CalledProcessError:
|
||||
print()
|
||||
print(WHITEONRED + "Error running a subcommand of %s: %s" % (sys.argv[0], " ".join(args)) +
|
||||
print(WHITEONRED + "Error running a subcommand of %s: %s" %
|
||||
(sys.argv[0], " ".join(map(shlex.quote, args))) +
|
||||
ENDC)
|
||||
print(WHITEONRED + "Actual error output for the subcommand is just above this." +
|
||||
ENDC)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import os
|
||||
import platform
|
||||
import shlex
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
|
@ -26,7 +27,7 @@ def run(check_func):
|
|||
|
||||
def run_command(args):
|
||||
# type: (List[str]) -> None
|
||||
print(' '.join(args))
|
||||
print(' '.join(map(shlex.quote, args)))
|
||||
subprocess.check_call(args)
|
||||
|
||||
@run
|
||||
|
|
Loading…
Reference in New Issue