From 8576f634795c8c6f2c1731227eb43161a5b91b2f Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Tue, 21 Jun 2022 03:13:55 -0400 Subject: [PATCH] Optimized copy_name_check() function Former-commit-id: 07e02ab7b0bbf030b0ee1baedd8dbb7ec5ef2e4e [formerly 47e8383146bb61d3328b06b9b2e9fa678525ce8c] Former-commit-id: 570a930a9c63aaa5315285ccf1a84316f4e6199a --- bin/sshyp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bin/sshyp b/bin/sshyp index 9546d88..fd12658 100755 --- a/bin/sshyp +++ b/bin/sshyp @@ -174,17 +174,16 @@ def edit_note(_shm_folder, _shm_entry): def copy_name_check(_port, _username_ssh, _ip, _client_device_name): _command = f"ssh -o ConnectTimeout=3 -i '{path.expanduser('~/.ssh/sshyp')}' -p {_port} {_username_ssh}@{_ip} " \ f"\"touch '/home/{_username_ssh}/.config/sshyp/devices/{_client_device_name}'\"" - _output = Popen(_command, shell=True, stdout=PIPE, stderr=STDOUT, close_fds=True) - _block = _output.communicate()[0].strip() - if _output.returncode != 0: + try: + run(_command, shell=True, stderr=PIPE, check=True, close_fds=True) + except CalledProcessError: print('\n\u001b[38;5;9mwarning: ssh connection could not be made - ensure the public key (~/.ssh/sshyp.pub) is ' 'registered on the remote server and that the entered ip, port, and username are correct\n\nsyncing ' 'functionality will be disabled until this is addressed\u001b[0m\n') open(path.expanduser('~/.config/sshyp/ssh-error'), 'w').write('1') return 1 - else: - open(path.expanduser('~/.config/sshyp/ssh-error'), 'w').write('0') - return 0 + open(path.expanduser('~/.config/sshyp/ssh-error'), 'w').write('0') + return 0 # argument-specific functions