common: print_cmd only prints a single line if the command fits in one line

No more ugly ' \\\n;' ending!
This commit is contained in:
Ciro Santilli 六四事件 法轮功
2018-11-10 00:00:01 +00:00
parent 6c355c80d3
commit 6119fb80ea

View File

@@ -492,17 +492,21 @@ def cmd_to_string(cmd, cwd=None, extra_env=None, extra_paths=None):
for key in extra_env: for key in extra_env:
out.append('{}={}'.format(shlex.quote(key), shlex.quote(extra_env[key]))) out.append('{}={}'.format(shlex.quote(key), shlex.quote(extra_env[key])))
cmd_quote = [] cmd_quote = []
has_newline = False newline_count = 0
for arg in cmd: for arg in cmd:
if arg == this_module.Newline: if arg == this_module.Newline:
cmd_quote.append(arg) cmd_quote.append(arg)
has_newline = True newline_count += 1
else: else:
cmd_quote.append(shlex.quote(arg)) cmd_quote.append(shlex.quote(arg))
if has_newline: if newline_count > 0:
cmd_quote = [' '.join(list(y)) for x, y in itertools.groupby(cmd_quote, lambda z: z == this_module.Newline) if not x] cmd_quote = [' '.join(list(y)) for x, y in itertools.groupby(cmd_quote, lambda z: z == this_module.Newline) if not x]
out.extend(cmd_quote) out.extend(cmd_quote)
return newline_separator.join(out) + last_newline + ';' if newline_count == 1 and cmd[-1] == this_module.Newline:
ending = ''
else:
ending = last_newline + ';'
return newline_separator.join(out) + ending
def print_cmd(cmd, cwd=None, cmd_file=None, extra_env=None, extra_paths=None): def print_cmd(cmd, cwd=None, cmd_file=None, extra_env=None, extra_paths=None):
''' '''