From e475e1de3c04ddd97be3b79b34e120e325644717 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Sun, 2 Dec 2018 10:10:20 +0100 Subject: [PATCH] Handle creating new files --- bin/var_editor.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bin/var_editor.py b/bin/var_editor.py index c8cae73..0e47eb0 100755 --- a/bin/var_editor.py +++ b/bin/var_editor.py @@ -29,12 +29,13 @@ def main(): f = Fernet(key) # This temp file will hold the decrypted content while we edit it tmp = tempfile.NamedTemporaryFile() - # We open the file, which contains the encrypted content - crypt = open(args[0], 'rb').read() - # And we decrypt it, and write it in the temp file - clear = f.decrypt(crypt) - tmp.write(clear) - tmp.flush() + # We open the file which contains the encrypted content, if it exists + if os.path.exists(args[0]): + crypt = open(args[0], 'rb').read() + # And we decrypt it, and write it in the temp file + clear = f.decrypt(crypt) + tmp.write(clear) + tmp.flush() # Now, lets open our favorite editor to edit the file os.system(os.getenv('EDITOR', 'vim') + ' ' + tmp.name) # We closed the editor, we just have to open the cleartext file, encrypt its content