Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

upload.py 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import getpass
  2. from distutils import log
  3. from distutils.command import upload as orig
  4. class upload(orig.upload):
  5. """
  6. Override default upload behavior to obtain password
  7. in a variety of different ways.
  8. """
  9. def run(self):
  10. try:
  11. orig.upload.run(self)
  12. finally:
  13. self.announce(
  14. "WARNING: Uploading via this command is deprecated, use twine "
  15. "to upload instead (https://pypi.org/p/twine/)",
  16. log.WARN
  17. )
  18. def finalize_options(self):
  19. orig.upload.finalize_options(self)
  20. self.username = (
  21. self.username or
  22. getpass.getuser()
  23. )
  24. # Attempt to obtain password. Short circuit evaluation at the first
  25. # sign of success.
  26. self.password = (
  27. self.password or
  28. self._load_password_from_keyring() or
  29. self._prompt_for_password()
  30. )
  31. def _load_password_from_keyring(self):
  32. """
  33. Attempt to load password from keyring. Suppress Exceptions.
  34. """
  35. try:
  36. keyring = __import__('keyring')
  37. return keyring.get_password(self.repository, self.username)
  38. except Exception:
  39. pass
  40. def _prompt_for_password(self):
  41. """
  42. Prompt for a password on the tty. Suppress Exceptions.
  43. """
  44. try:
  45. return getpass.getpass()
  46. except (Exception, KeyboardInterrupt):
  47. pass