From 6119fb80ea5001b275f02b8d0461efdcf8e897ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Sat, 10 Nov 2018 00:00:01 +0000 Subject: [PATCH] common: print_cmd only prints a single line if the command fits in one line No more ugly ' \\\n;' ending! --- common.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/common.py b/common.py index 4ab9867..aee2d8a 100644 --- a/common.py +++ b/common.py @@ -492,17 +492,21 @@ def cmd_to_string(cmd, cwd=None, extra_env=None, extra_paths=None): for key in extra_env: out.append('{}={}'.format(shlex.quote(key), shlex.quote(extra_env[key]))) cmd_quote = [] - has_newline = False + newline_count = 0 for arg in cmd: if arg == this_module.Newline: cmd_quote.append(arg) - has_newline = True + newline_count += 1 else: 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] 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): '''