Fix set_keychain errors (#964)

* fix keyring problems
* black
* remove else and use stderr
* black
* add tests
* black
* change description of nokeyring
* dumb syntax error
This commit is contained in:
Eshan 2020-05-30 15:43:10 -04:00 committed by GitHub
parent ca482b0a46
commit 0b9137c17d
3 changed files with 52 additions and 4 deletions

View file

@ -59,9 +59,6 @@ def create_password(
if yesno("Do you want to store the password in your keychain?", default=True):
set_keychain(journal_name, pw)
else:
set_keychain(journal_name, None)
return pw
@ -107,7 +104,13 @@ def set_keychain(journal_name, password):
except keyring.errors.PasswordDeleteError:
pass
else:
keyring.set_password("jrnl", journal_name, password)
try:
keyring.set_password("jrnl", journal_name, password)
except keyring.errors.NoKeyringError:
print(
"Keyring backend not found. Please install one of the supported backends by visiting: https://pypi.org/project/keyring/",
file=sys.stderr,
)
def yesno(prompt, default=True):