mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Decrypt and Encrypt into new files, closes #23
This commit is contained in:
parent
e9063e1336
commit
7dcd78f3ff
1 changed files with 20 additions and 9 deletions
29
jrnl.py
29
jrnl.py
|
@ -401,8 +401,8 @@ if __name__ == "__main__":
|
||||||
exporting.add_argument('--tags', dest='tags', action="store_true", help='Returns a list of all tags and number of occurences')
|
exporting.add_argument('--tags', dest='tags', action="store_true", help='Returns a list of all tags and number of occurences')
|
||||||
exporting.add_argument('--json', dest='json', action="store_true", help='Returns a JSON-encoded version of the Journal')
|
exporting.add_argument('--json', dest='json', action="store_true", help='Returns a JSON-encoded version of the Journal')
|
||||||
exporting.add_argument('--markdown', dest='markdown', action="store_true", help='Returns a Markdown-formated version of the Journal')
|
exporting.add_argument('--markdown', dest='markdown', action="store_true", help='Returns a Markdown-formated version of the Journal')
|
||||||
exporting.add_argument('--encrypt', dest='encrypt', action="store_true", help='Encrypts your existing journal with a new password')
|
exporting.add_argument('--encrypt', dest='encrypt', help='Encrypts your existing journal with a new password', nargs='?', default=False, const=True)
|
||||||
exporting.add_argument('--decrypt', dest='decrypt', action="store_true", help='Decrypts your journal and stores it in plain text')
|
exporting.add_argument('--decrypt', dest='decrypt', help='Decrypts your journal and stores it in plain text', nargs='?', default=False, const=True)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
@ -475,18 +475,29 @@ if __name__ == "__main__":
|
||||||
elif args.markdown: # export to json
|
elif args.markdown: # export to json
|
||||||
print(journal.to_md())
|
print(journal.to_md())
|
||||||
|
|
||||||
|
# Encrypt into new file If args.encrypt is True, that it is present in the command line arguments
|
||||||
|
# but isn't followed by any value - in which case we encrypt the journal file itself. Otherwise
|
||||||
|
# encrypt to a new file.
|
||||||
elif args.encrypt:
|
elif args.encrypt:
|
||||||
|
journal.make_key(prompt="Enter new password:")
|
||||||
journal.config['encrypt'] = True
|
journal.config['encrypt'] = True
|
||||||
journal.config['password'] = ""
|
journal.config['password'] = ""
|
||||||
journal.make_key(prompt="Enter new password:")
|
if args.encrypt is True:
|
||||||
journal.write()
|
journal.write()
|
||||||
journal.save_config()
|
journal.save_config()
|
||||||
print("Journal encrypted to %s." % journal.config['journal'])
|
print("Journal encrypted to %s." % journal.config['journal'])
|
||||||
|
else:
|
||||||
|
journal.write(args.encrypt)
|
||||||
|
print("Journal encrypted to %s." % os.path.realpath(args.encrypt))
|
||||||
|
|
||||||
elif args.decrypt:
|
elif args.decrypt:
|
||||||
journal.config['encrypt'] = False
|
journal.config['encrypt'] = False
|
||||||
journal.config['password'] = ""
|
journal.config['password'] = ""
|
||||||
journal.write()
|
if args.decrypt is True:
|
||||||
journal.save_config()
|
journal.write()
|
||||||
print("Journal decrypted to %s." % journal.config['journal'])
|
journal.save_config()
|
||||||
|
print("Journal decrypted to %s." % journal.config['journal'])
|
||||||
|
else:
|
||||||
|
journal.write(args.decrypt)
|
||||||
|
print("Journal encrypted to %s." % os.path.realpath(args.decrypt))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue