all repos — dotfiles @ 5542c7ce419ebf1c4a051e595e8273ce1268d8d3

linux dotfiles

update pd: save entry on error
Prithu Goswami prithugoswami524@gmail.com
Sat, 25 Apr 2020 15:56:53 +0530
commit

5542c7ce419ebf1c4a051e595e8273ce1268d8d3

parent

fe04a2700e9267b3117cc096e6ca61fa4f402ce7

1 files changed, 21 insertions(+), 8 deletions(-)

jump to
M bin/scripts/pdbin/scripts/pd

@@ -57,7 +57,7 @@ # the 'key_path' variable accordingly

import os -import datetime +from datetime import datetime as dt import tempfile import subprocess import shlex

@@ -89,6 +89,13 @@ "cache the entry locally you lazy ass")

exit(p.returncode) +def save_entry(entry): + entry_filename = dt.now().strftime('%s') + ".pdentry" + entry_file_path = env_home + "/" + entry_filename + print("Saving the entry to {}".format(entry_file_path)) + with open(entry_file_path, 'w', encoding='utf8') as entry_file: + entry_file.write(entry) + def fetch_and_decrypt(): """

@@ -105,9 +112,10 @@ universal_newlines=True)

out, err = p.communicate() if p.returncode: # if gpg exits with a non-zero return code print("Error while decrypting :\n" + err) - exit() + return(p.returncode) else: print("Something went wrong") + return(1) def encrypt_and_push():

@@ -124,7 +132,7 @@ universal_newlines=True)

out, err = p.communicate() if p.returncode: print("Error while encrypting :\n" + err) - exit() + return(p.returncode) os.remove(tmp_pd_path) print("Pushing changes...")

@@ -132,6 +140,7 @@ if not os.system('rclone sync {}/ {}/'.format(pd_dir, rclone_dir)):

print("Done") else: print("Something went wrong") + return(1)

@@ -172,15 +181,19 @@ if len(entry.strip()) == 0:

print("Nothing was entered...") exit() -fetch_and_decrypt() +if fetch_and_decrypt(): # if there was any error while fetching and decrypting + save_entry(entry) + exit(1) with open(tmp_pd_path, 'a', encoding='utf8') as fp: - dt = datetime.datetime.now() - date_string = dt.strftime('%a, %d %b %Y') - time_string = dt.strftime('%I:%M %p') + now = dt.now() + date_string = now.strftime('%a, %d %b %Y') + time_string = now.strftime('%I:%M %p') date_and_time = '[' + date_string + ' | ' + time_string + ']' fp.write('\n\n\n===============================\n' + date_and_time + '\n') fp.write(entry) -encrypt_and_push() +if encrypt_and_push(): + save_entry(entry) + exit(1)