From df1c6482a8ca4e36d6e9944757233cd7ed3fac74 Mon Sep 17 00:00:00 2001 From: Randall Date: Sat, 27 Aug 2022 12:46:54 -0400 Subject: [PATCH] Optimized cross-device entry deletion code Former-commit-id: 2a1dcda6460c06103846b41fbf2d83bf78c05527 [formerly f1aca39fd10fabd19a40a7d6e9825584f83b7e08] Former-commit-id: 268b5564ff2f4cc157ebe039e9c46826a4bdb878 --- bin/sshyp.py | 22 ++++++++-------------- bin/sshypRemote.py | 13 +++++-------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/bin/sshyp.py b/bin/sshyp.py index 642f876..ea84054 100755 --- a/bin/sshyp.py +++ b/bin/sshyp.py @@ -423,22 +423,16 @@ def sync(): # calls sshync to sync changes to the user's server _deletion_database = None s_exit(1) for _file in _deletion_database: - if _file[:-1].endswith('/'): - try: - if silent_sync != 1: - print(f"\u001b[38;5;208m{_file[:-1]}\u001b[0m has been sheared, removing...") + try: + if silent_sync != 1: + print(f"\u001b[38;5;208m{_file[:-1]}\u001b[0m has been sheared, removing...") + if _file[:-1].endswith('/'): rmtree(f"{directory}{_file[:-1]}") - except FileNotFoundError: - if silent_sync != 1: - print('folder does not exist locally.') - else: - try: - if silent_sync != 1: - print(f"\u001b[38;5;208m{_file[:-1]}\u001b[0m has been sheared, removing...") + else: remove(f"{directory}{_file[:-1]}.gpg") - except (FileNotFoundError, IsADirectoryError): - if silent_sync != 1: - print('file does not exist locally.') + except FileNotFoundError: + if silent_sync != 1: + print('location does not exist locally') # check for new folders system(f"ssh -i '{path.expanduser('~/.ssh/sshyp')}' -p {port} {username_ssh}@{ip} \"cd /bin; python -c " f"'import sshypRemote; sshypRemote.folder_check()'\"") diff --git a/bin/sshypRemote.py b/bin/sshypRemote.py index f8440d3..8d6d024 100755 --- a/bin/sshypRemote.py +++ b/bin/sshypRemote.py @@ -10,16 +10,13 @@ from shutil import rmtree # utility functions def delete(_file_path): # deletes an entry or folder, should be run remotely via ssh - if _file_path.endswith('/'): - try: + try: + if _file_path.endswith('/'): rmtree(f"{expanduser('~/.local/share/sshyp/')}{_file_path}") - except FileNotFoundError: - print('folder does not exist remotely') - else: - try: + else: remove(f"{expanduser('~/.local/share/sshyp/')}{_file_path}.gpg") - except FileNotFoundError: - print('file does not exist remotely') + except FileNotFoundError: + print('location does not exist remotely') for _device_name in listdir(expanduser('~/.config/sshyp/devices')): open(f"{expanduser('~/.config/sshyp/deleted/')}{_file_path.replace('/', '@')}^&*{_device_name}", 'w')