Handle creating new files

master
Daniel Berteaud 6 years ago
parent 26d42b7ac6
commit e475e1de3c
  1. 13
      bin/var_editor.py

@ -29,12 +29,13 @@ def main():
f = Fernet(key) f = Fernet(key)
# This temp file will hold the decrypted content while we edit it # This temp file will hold the decrypted content while we edit it
tmp = tempfile.NamedTemporaryFile() tmp = tempfile.NamedTemporaryFile()
# We open the file, which contains the encrypted content # We open the file which contains the encrypted content, if it exists
crypt = open(args[0], 'rb').read() if os.path.exists(args[0]):
# And we decrypt it, and write it in the temp file crypt = open(args[0], 'rb').read()
clear = f.decrypt(crypt) # And we decrypt it, and write it in the temp file
tmp.write(clear) clear = f.decrypt(crypt)
tmp.flush() tmp.write(clear)
tmp.flush()
# Now, lets open our favorite editor to edit the file # Now, lets open our favorite editor to edit the file
os.system(os.getenv('EDITOR', 'vim') + ' ' + tmp.name) os.system(os.getenv('EDITOR', 'vim') + ' ' + tmp.name)
# We closed the editor, we just have to open the cleartext file, encrypt its content # We closed the editor, we just have to open the cleartext file, encrypt its content

Loading…
Cancel
Save