OLD | NEW |
(Empty) | |
| 1 import getpass |
| 2 from distutils.command import upload as orig |
| 3 |
| 4 |
| 5 class upload(orig.upload): |
| 6 """ |
| 7 Override default upload behavior to obtain password |
| 8 in a variety of different ways. |
| 9 """ |
| 10 |
| 11 def finalize_options(self): |
| 12 orig.upload.finalize_options(self) |
| 13 # Attempt to obtain password. Short circuit evaluation at the first |
| 14 # sign of success. |
| 15 self.password = ( |
| 16 self.password or |
| 17 self._load_password_from_keyring() or |
| 18 self._prompt_for_password() |
| 19 ) |
| 20 |
| 21 def _load_password_from_keyring(self): |
| 22 """ |
| 23 Attempt to load password from keyring. Suppress Exceptions. |
| 24 """ |
| 25 try: |
| 26 keyring = __import__('keyring') |
| 27 return keyring.get_password(self.repository, self.username) |
| 28 except Exception: |
| 29 pass |
| 30 |
| 31 def _prompt_for_password(self): |
| 32 """ |
| 33 Prompt for a password on the tty. Suppress Exceptions. |
| 34 """ |
| 35 try: |
| 36 return getpass.getpass() |
| 37 except (Exception, KeyboardInterrupt): |
| 38 pass |
OLD | NEW |