mirror of https://github.com/borgbackup/borg.git
Merge pull request #3715 from milkey-mouse/getpass-ux-bp1.1
improve getpass user experience (1.1 backport)
This commit is contained in:
commit
8c40c19508
|
@ -32,6 +32,10 @@ from .low_level import AES, bytes_to_long, bytes_to_int, num_aes_blocks, hmac_sh
|
|||
PREFIX = b'\0' * 8
|
||||
|
||||
|
||||
class NoPassphraseFailure(Error):
|
||||
"""can not acquire a passphrase: {}"""
|
||||
|
||||
|
||||
class PassphraseWrong(Error):
|
||||
"""passphrase supplied in BORG_PASSPHRASE or by BORG_PASSCOMMAND is incorrect."""
|
||||
|
||||
|
@ -451,7 +455,19 @@ class Passphrase(str):
|
|||
|
||||
@classmethod
|
||||
def getpass(cls, prompt):
|
||||
return cls(getpass.getpass(prompt))
|
||||
try:
|
||||
pw = getpass.getpass(prompt)
|
||||
except EOFError:
|
||||
if prompt:
|
||||
print() # avoid err msg appearing right of prompt
|
||||
msg = []
|
||||
for env_var in 'BORG_PASSPHRASE', 'BORG_PASSCOMMAND':
|
||||
env_var_set = os.environ.get(env_var) is not None
|
||||
msg.append('%s is %s.' % (env_var, 'set' if env_var_set else 'not set'))
|
||||
msg.append('Interactive password query failed.')
|
||||
raise NoPassphraseFailure(' '.join(msg)) from None
|
||||
else:
|
||||
return cls(pw)
|
||||
|
||||
@classmethod
|
||||
def verification(cls, passphrase):
|
||||
|
|
Loading…
Reference in New Issue