Handle creating new files
This commit is contained in:
parent
26d42b7ac6
commit
e475e1de3c
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue