Optimized copy_name_check() function

Former-commit-id: 07e02ab7b0bbf030b0ee1baedd8dbb7ec5ef2e4e [formerly 47e8383146]
Former-commit-id: 570a930a9c63aaa5315285ccf1a84316f4e6199a
This commit is contained in:
2022-06-21 03:13:55 -04:00
parent 393f241538
commit 8576f63479
+5 -6
View File
@@ -174,17 +174,16 @@ def edit_note(_shm_folder, _shm_entry):
def copy_name_check(_port, _username_ssh, _ip, _client_device_name): 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} " \ _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}'\"" f"\"touch '/home/{_username_ssh}/.config/sshyp/devices/{_client_device_name}'\""
_output = Popen(_command, shell=True, stdout=PIPE, stderr=STDOUT, close_fds=True) try:
_block = _output.communicate()[0].strip() run(_command, shell=True, stderr=PIPE, check=True, close_fds=True)
if _output.returncode != 0: except CalledProcessError:
print('\n\u001b[38;5;9mwarning: ssh connection could not be made - ensure the public key (~/.ssh/sshyp.pub) is ' 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 ' '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') 'functionality will be disabled until this is addressed\u001b[0m\n')
open(path.expanduser('~/.config/sshyp/ssh-error'), 'w').write('1') open(path.expanduser('~/.config/sshyp/ssh-error'), 'w').write('1')
return 1 return 1
else: open(path.expanduser('~/.config/sshyp/ssh-error'), 'w').write('0')
open(path.expanduser('~/.config/sshyp/ssh-error'), 'w').write('0') return 0
return 0
# argument-specific functions # argument-specific functions