From 4fedbb13d80833cf02bc7bb83c133ed7f24b225a Mon Sep 17 00:00:00 2001 From: Gergely Imreh Date: Thu, 19 Mar 2020 15:25:42 +0000 Subject: [PATCH 01/10] Add helper output for connecting after running add-to-ssh-agent The function definition header has help how to connect to the server whose key we've added to the ssh-agent, on the other hand the tabular output is both different order and would still require knowledge of the ssh parameters. This change fills in the command with the server variables and adds some extra flags that help to be less noisy later: not adding the server's key to the known hosts file, and not checking the server's key. ``` Hostname Port Username 123.123.123.123 12345 faculty Connect to the server by: ssh faculty@123.123.123.123 -p 12345 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ``` It should work both on Linux/Mac and Windows as the relevant null device is substituted in the command example. Signed-off-by: Gergely Imreh --- faculty_cli/cli.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/faculty_cli/cli.py b/faculty_cli/cli.py index 6d6c055..a37d308 100644 --- a/faculty_cli/cli.py +++ b/faculty_cli/cli.py @@ -735,6 +735,15 @@ def ssh(project, server): tablefmt="plain", ) ) + click.echo( + "\n".join( + [ + "", + "Connect to the server by:", + f"ssh {details.username}@{details.hostname} -p {details.port} -o UserKnownHostsFile={os.devnull} -o StrictHostKeyChecking=no", + ] + ) + ) @cli.command(context_settings={"ignore_unknown_options": True}) From b6513276eeadc239138676e46698344fc12cb738 Mon Sep 17 00:00:00 2001 From: Gergely Imreh Date: Thu, 19 Mar 2020 15:43:06 +0000 Subject: [PATCH 02/10] Formatting changes, not connected to the main code, required by black Signed-off-by: Gergely Imreh --- faculty_cli/cli.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/faculty_cli/cli.py b/faculty_cli/cli.py index a37d308..f92ec58 100644 --- a/faculty_cli/cli.py +++ b/faculty_cli/cli.py @@ -1167,7 +1167,7 @@ def put(project, local, remote, server): "-P", str(details.port), os.path.expanduser(local), - u"{}@{}:{}".format( + "{}@{}:{}".format( details.username, details.hostname, escaped_remote ), ] @@ -1199,7 +1199,7 @@ def get(project, remote, local, server): filename, "-P", str(details.port), - u"{}@{}:{}".format( + "{}@{}:{}".format( details.username, details.hostname, escaped_remote ), os.path.expanduser(local), @@ -1219,11 +1219,11 @@ def _rsync(project, local, remote, server, rsync_opts, up): escaped_remote = faculty_cli.shell.quote(remote) if up: path_from = local - path_to = u"{}@{}:{}".format( + path_to = "{}@{}:{}".format( details.username, details.hostname, escaped_remote ) else: - path_from = u"{}@{}:{}".format( + path_from = "{}@{}:{}".format( details.username, details.hostname, escaped_remote ) path_to = local From d5da1d85d659c9f448bb40930061512cd409dce8 Mon Sep 17 00:00:00 2001 From: Gergely Imreh Date: Thu, 19 Mar 2020 15:51:12 +0000 Subject: [PATCH 03/10] Redo string output with format Since older Pythons don't do f-strings, duh. Signed-off-by: Gergely Imreh --- faculty_cli/cli.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/faculty_cli/cli.py b/faculty_cli/cli.py index f92ec58..415f452 100644 --- a/faculty_cli/cli.py +++ b/faculty_cli/cli.py @@ -740,7 +740,12 @@ def ssh(project, server): [ "", "Connect to the server by:", - f"ssh {details.username}@{details.hostname} -p {details.port} -o UserKnownHostsFile={os.devnull} -o StrictHostKeyChecking=no", + "ssh {username}@{password} -p {port} -o UserKnownHostsFile={devnull} -o StrictHostKeyChecking=no".format( + username=details.username, + password=details.hostname, + port=details.port, + devnull=os.devnull, + ), ] ) ) From fe1bfcba20fb50d0034f77cc175738cbd43b7d3b Mon Sep 17 00:00:00 2001 From: Gergely Imreh Date: Thu, 19 Mar 2020 15:55:37 +0000 Subject: [PATCH 04/10] Update flake8 check to follow black's formatting Otherwise can run into issues that black formats lines one way, but flake8 doesn't accept the formatting choices. Signed-off-by: Gergely Imreh --- tox.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 154be0e..ce0a6ae 100644 --- a/tox.ini +++ b/tox.ini @@ -13,8 +13,9 @@ commands = pytest {posargs} skip_install = True deps = flake8 + flake8-black commands = - flake8 + flake8 --select BLK [testenv:black] skip_install = True From 53d53d240c27c09b66865b7e0b96dbcee140ce0c Mon Sep 17 00:00:00 2001 From: Gergely Imreh Date: Thu, 19 Mar 2020 15:58:24 +0000 Subject: [PATCH 05/10] Revert "Update flake8 check to follow black's formatting" due to Python 2 This reverts commit fe1bfcba20fb50d0034f77cc175738cbd43b7d3b. --- tox.ini | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index ce0a6ae..154be0e 100644 --- a/tox.ini +++ b/tox.ini @@ -13,9 +13,8 @@ commands = pytest {posargs} skip_install = True deps = flake8 - flake8-black commands = - flake8 --select BLK + flake8 [testenv:black] skip_install = True From a0209d7036649b82cf84ec9a9ada925dc72b05ff Mon Sep 17 00:00:00 2001 From: Gergely Imreh Date: Thu, 19 Mar 2020 16:11:20 +0000 Subject: [PATCH 06/10] Simplify output formatting and linter setup. Signed-off-by: Gergely Imreh --- faculty_cli/cli.py | 15 ++++----------- tox.ini | 7 +++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/faculty_cli/cli.py b/faculty_cli/cli.py index 415f452..fd8630f 100644 --- a/faculty_cli/cli.py +++ b/faculty_cli/cli.py @@ -736,17 +736,10 @@ def ssh(project, server): ) ) click.echo( - "\n".join( - [ - "", - "Connect to the server by:", - "ssh {username}@{password} -p {port} -o UserKnownHostsFile={devnull} -o StrictHostKeyChecking=no".format( - username=details.username, - password=details.hostname, - port=details.port, - devnull=os.devnull, - ), - ] + "\n" + + "Connect to the server by:\n" + + "ssh {}@{} -p {} -o UserKnownHostsFile={} -o StrictHostKeyChecking=no".format( + details.username, details.hostname, details.port, os.devnull, ) ) diff --git a/tox.ini b/tox.ini index 154be0e..8d07967 100644 --- a/tox.ini +++ b/tox.ini @@ -22,3 +22,10 @@ deps = black==18.9b0 commands = black {posargs:--check setup.py faculty_cli test} + +# This section is in use Python 2 is supported +# With Python 3 flake8-black would unify the requirements +# of the formatter and linter. +[flake8] +# Longer line length is due to black's default line wrap +max-line-length = 88 From 2e8eec9d4b27adb20b4d49050d192e57087efcce Mon Sep 17 00:00:00 2001 From: Gergely Imreh Date: Thu, 19 Mar 2020 16:18:26 +0000 Subject: [PATCH 07/10] More formatting, as newer black does things differently. Signed-off-by: Gergely Imreh --- faculty_cli/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/faculty_cli/cli.py b/faculty_cli/cli.py index fd8630f..8213c1c 100644 --- a/faculty_cli/cli.py +++ b/faculty_cli/cli.py @@ -739,7 +739,7 @@ def ssh(project, server): "\n" + "Connect to the server by:\n" + "ssh {}@{} -p {} -o UserKnownHostsFile={} -o StrictHostKeyChecking=no".format( - details.username, details.hostname, details.port, os.devnull, + details.username, details.hostname, details.port, os.devnull ) ) From 90b46ff8b155543c30601ca64319d04fbcbdce48 Mon Sep 17 00:00:00 2001 From: Gergely Imreh Date: Sat, 21 Mar 2020 15:24:19 +0000 Subject: [PATCH 08/10] Remove ineffective flake8 setting, update grammar, reformat string The awkward string formatting is necessary as `black` doesn't break long strings but `flake8` despises them. Signed-off-by: Gergely Imreh --- faculty_cli/cli.py | 9 ++++++--- tox.ini | 7 ------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/faculty_cli/cli.py b/faculty_cli/cli.py index 8213c1c..7c9bbed 100644 --- a/faculty_cli/cli.py +++ b/faculty_cli/cli.py @@ -737,9 +737,12 @@ def ssh(project, server): ) click.echo( "\n" - + "Connect to the server by:\n" - + "ssh {}@{} -p {} -o UserKnownHostsFile={} -o StrictHostKeyChecking=no".format( - details.username, details.hostname, details.port, os.devnull + + "Login to the server with:\n" + + "ssh {}@{} -p {}".format( + details.username, details.hostname, details.port + ) + + " -o UserKnownHostsFile={} -o StrictHostKeyChecking=no".format( + os.devnull ) ) diff --git a/tox.ini b/tox.ini index 8d07967..154be0e 100644 --- a/tox.ini +++ b/tox.ini @@ -22,10 +22,3 @@ deps = black==18.9b0 commands = black {posargs:--check setup.py faculty_cli test} - -# This section is in use Python 2 is supported -# With Python 3 flake8-black would unify the requirements -# of the formatter and linter. -[flake8] -# Longer line length is due to black's default line wrap -max-line-length = 88 From 1d6d9a970939b5a93d86687fc61c2a10515eca3e Mon Sep 17 00:00:00 2001 From: Gergely Imreh Date: Sat, 21 Mar 2020 15:42:49 +0000 Subject: [PATCH 09/10] Instruct flake8 to ignore long line errors, and string formatting Signed-off-by: Gergely Imreh --- faculty_cli/cli.py | 7 ++----- tox.ini | 4 ++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/faculty_cli/cli.py b/faculty_cli/cli.py index 7c9bbed..df91e85 100644 --- a/faculty_cli/cli.py +++ b/faculty_cli/cli.py @@ -738,11 +738,8 @@ def ssh(project, server): click.echo( "\n" + "Login to the server with:\n" - + "ssh {}@{} -p {}".format( - details.username, details.hostname, details.port - ) - + " -o UserKnownHostsFile={} -o StrictHostKeyChecking=no".format( - os.devnull + + "ssh {}@{} -p {} -o UserKnownHostsFile={} -o StrictHostKeyChecking=no".format( + details.username, details.hostname, details.port, os.devnull ) ) diff --git a/tox.ini b/tox.ini index 154be0e..bc9d1d5 100644 --- a/tox.ini +++ b/tox.ini @@ -22,3 +22,7 @@ deps = black==18.9b0 commands = black {posargs:--check setup.py faculty_cli test} + +[flake8] +# Ignore long line errors, and rely on the formatting done properly by black +ignore = E501 From ef3e309d72ae04f10f3d7027e9c6f3739fbd0e4f Mon Sep 17 00:00:00 2001 From: Gergely Imreh Date: Sat, 21 Mar 2020 15:51:44 +0000 Subject: [PATCH 10/10] Add another ignore to flake8, for usability and relying on black Signed-off-by: Gergely Imreh --- tox.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index bc9d1d5..294bfc2 100644 --- a/tox.ini +++ b/tox.ini @@ -25,4 +25,5 @@ commands = [flake8] # Ignore long line errors, and rely on the formatting done properly by black -ignore = E501 +# Also ignore "Line break occurred before a binary operator" also coming from black +ignore = E501,W503