From 8c520d972e6840cf44f277ac3671cc6a9b731dca Mon Sep 17 00:00:00 2001 From: rwinkhart Date: Sat, 9 Jul 2022 18:17:24 -0400 Subject: [PATCH] Updated sshyp-refresh to use new entry directory --- extra/sshyp-refresh.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/extra/sshyp-refresh.py b/extra/sshyp-refresh.py index 61fdc70..9df936a 100755 --- a/extra/sshyp-refresh.py +++ b/extra/sshyp-refresh.py @@ -6,19 +6,19 @@ from shutil import move, rmtree if __name__ == "__main__": gpg_id = input('\nWhat is the ID of the GPG key you would like to use for re-encryption?\n\nID: ') - pasture = path.expanduser('~/.password-pasture') - if Path(f"{pasture}.new").exists(): - rmtree(f"{pasture}.new") - if Path(f"{pasture}.old").exists(): - rmtree(f"{pasture}.old") - if path.isdir(pasture): - for dirPath, dirNames, filenames in walk(pasture): + directory = path.expanduser('~/.local/share/sshyp') + if Path(f"{directory}.new").exists(): + rmtree(f"{directory}.new") + if Path(f"{directory}.old").exists(): + rmtree(f"{directory}.old") + if path.isdir(directory): + for dirPath, dirNames, filenames in walk(directory): for filename in sorted(filenames): - Path(dirPath.replace(pasture, pasture + '.new')).mkdir(0o700, parents=True, exist_ok=True) + Path(dirPath.replace(directory, directory + '.new')).mkdir(0o700, parents=True, exist_ok=True) system(f"gpg -d '{dirPath}/{filename}' " - f"> '{dirPath.replace(pasture, pasture + '.new')}/{filename[:-4]}'") + f"> '{dirPath.replace(directory, directory + '.new')}/{filename[:-4]}'") _old_contents, _new_contents = \ - open(f"{dirPath.replace(pasture, pasture + '.new')}/{filename[:-4]}", 'r').readlines(), '' + open(f"{dirPath.replace(directory, directory + '.new')}/{filename[:-4]}", 'r').readlines(), '' for _num in range(len(_old_contents)): if _num == 3: if _old_contents[_num] == ' ' or _old_contents[_num] == '\n': @@ -32,10 +32,10 @@ if __name__ == "__main__": _new_contents = _new_contents[:-1] else: break - open(f"{dirPath.replace(pasture, pasture + '.new')}/{filename[:-4]}", 'w').writelines(_new_contents) - system(f"gpg -qr {str(gpg_id)} -e '{dirPath.replace(pasture, pasture + '.new')}/{filename[:-4]}'") - remove(f"{dirPath.replace(pasture, pasture + '.new')}/{filename[:-4]}") + open(f"{dirPath.replace(directory, directory + '.new')}/{filename[:-4]}", 'w').writelines(_new_contents) + system(f"gpg -qr {str(gpg_id)} -e '{dirPath.replace(directory, directory + '.new')}/{filename[:-4]}'") + remove(f"{dirPath.replace(directory, directory + '.new')}/{filename[:-4]}") else: - print(f"\nError: no entry folder ({pasture}) found\n") - move(pasture, f"{pasture}.old") - move(f"{pasture}.new", pasture) + print(f"\nError: no entry folder ({directory}) found\n") + move(directory, f"{directory}.old") + move(f"{directory}.new", directory)