Commit 3070dd76 authored by Jason R. Coombs's avatar Jason R. Coombs

Merge pull request #555 from brookskindle/dev_prompt_password

password prompt on upload command
parents 89509b57 6c9c3c7e
...@@ -3,13 +3,18 @@ from distutils.command import upload as orig ...@@ -3,13 +3,18 @@ from distutils.command import upload as orig
class upload(orig.upload): class upload(orig.upload):
""" """
Override default upload behavior to look up password Override default upload behavior to obtain password
in the keyring if available. in a variety of different ways.
""" """
def finalize_options(self): def finalize_options(self):
orig.upload.finalize_options(self) orig.upload.finalize_options(self)
self.password or self._load_password_from_keyring() # Attempt to obtain password. Short circuit evaluation at the first
# sign of success.
self.password = (
self.password or self._load_password_from_keyring() or
self._prompt_for_password()
)
def _load_password_from_keyring(self): def _load_password_from_keyring(self):
""" """
...@@ -17,7 +22,22 @@ class upload(orig.upload): ...@@ -17,7 +22,22 @@ class upload(orig.upload):
""" """
try: try:
keyring = __import__('keyring') keyring = __import__('keyring')
self.password = keyring.get_password(self.repository, password = keyring.get_password(self.repository, self.username)
self.username)
except Exception: except Exception:
pass password = None
finally:
return password
def _prompt_for_password(self):
"""
Prompt for a password on the tty. Suppress Exceptions.
"""
password = None
try:
import getpass
while not password:
password = getpass.getpass()
except (Exception, KeyboardInterrupt):
password = None
finally:
return password
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment